Assert more than one value

Hi All

Can any one help me in below scenario.

Need to assert all values which is there in array.

Could you guys help me in this.

pm.test(“Testing multiple values” , function(){

var arr = [‘Value1’,‘Value2’,‘Value3’,‘Value4’];
var x;
for(x of arr){
console.log(x);
pm.expect(pm.response.text()).to.include(x);
}
});

I tried above code but not working getting ‘There was an error in evaluating the test script: SyntaxError: Unexpected token }’ Error.

Hi @himanshudwivedi1989, can you try this:

pm.test("Testing multiple values", function () {
  let arr = ['Value1', 'Value2', 'Value3', 'Value4'],
    responseText = pm.response.text();

  arr.forEach((x) => {
    pm.expect(responseText).to.include(x);
  });
});
1 Like

Hi Siv,

not working for me.
Still same error.

Could you share the screenshot of your complete test script?
The error seems to be somewhere else.

Hi Siv,

It is working fine now both the codes.
yours as well as mine.
Thanks for the help.

1 Like

Hi Siv,

Do you have any idea about how to read values from json file and store into json object as expected output so that i can assert this output with actual object.

Since i can’t put more than 1000 values in my test script , i have to put those values into a file and then read as json and assert against my response.

image

like here my json values are less so i mentioned in there itself what if they are more than 1000 (which is in my case) how to deal with this scenario.

Regards
Himanshu

Did you try something like:

pm.expect(1).to.be.oneOf([1, 2, 3]); 

No i din’t try this one , but this will give you assert against single value i guess not all the values.

tried with normal for loop.