Postman OR / to.be.oneOf Issue

Hi All,

Can anyone help me with an issue i am having please?

After i have hit an endpoint, the response body will render some HTML.

Inside the Test tab i am running

pm.test("Confirm Expected Item Details are on Page : X", function(){

pm.expect(pm.response.text()).to.include("itemA");

});

However, i wanted to do an OR like statement, and item can change at different points so could be itemA, itemB or itemC.

So i did some googling, and have still come up short. I’ve tried:

pm.test("Confirm Expected Item Details are on Page : X", function(){

pm.expect(pm.response.text()).to.include.oneOf(['itemA','itemB']);

});

pm.test("Confirm Expected Item Details are on Page : X", function(){

pm.expect(pm.response.text()).to.include("itemA") || pm.response.text()).to.include("itemb");

});

None of these work. What am i doing wrong?

Since these tests are just running javascript, you could change it up a bit to the following:

const responseText = pm.response.text();
const hasItemDetails = (responseText.includes('itemA') || responseText.includes('itemB'));

pm.expect(hasItemDetails).to.be.true;
4 Likes

Thanks Allen! Works a charm

1 Like

Thanks Allen, it’s working! :+1:

1 Like