How to verify if response contains specific text

@skyroamofghostviper

You will need to include an IF statement and can use the old way of writing to the tests tab (before Postman included the pm.expect library).

const response = pm.response.json();

let allowedDomains = ["somedomain.com","somedomain2.com"]

response.forEach(record => {
    const emailDomain = record.email.split('@')[1];
    console.log(emailDomain);
    if (!allowedDomains.includes(emailDomain)) {
        tests[`${emailDomain} is not in allowed list`] = false;
    }
});

image

1 Like