How can we test required body element is missing in request body for each required element in single request itself

For e.g. there are 3 required elements in request body as A,B,C, If C is missed, I need to check whether correct error message is getting displayed. If A,B is missed I need to verify error messages for A and B are correct. Would like to know is it possible in single request?

@rohit2330 It is not possible to run such scenario in a single request.
If you wanted to verify tags with different inputs, then it is possible in a single request with the help of iterative csv data.

1 Like

Hey @rohit2330,

Can you clarify the question a little bit more, please?

What does the body of the request look like? What’s the structure?

Where are the error messages coming from? Is that part of the response body?

You can write tests to assert that certain pieces of information are part of the request body using something like:

pm.test('Check for keys A, B and C', () => {
    pm.expect(JSON.parse(pm.request.body.raw)).to.be.an('object').that.has.all.keys('A', 'B', 'C')
}) 

This is assuming your request body looks like this:

{
	"A": "test1",
	"B": "test2",
	"C": "test3"
}

Without a clear picture of what you’re trying to achieve, it will be difficult to give a better solution.

Hi @dannydainton,

Error message coming from API as response body. Sample request body is as below.
{
“A”: “asass”,
“B”: “A22222”,
“C”: “asas”,
“D”: [
{
“E”: “def ghi”,
“F”: “aaa bbb”,

}

]

}

Thanks for your help :smiley:

Is error message different for every scenario you have mentioned ?
If not, and you are ok to send an empty string for A, B, C, you can use a csv file as below and In collection runner, select the data file, Iterations: 2

a,b,c
as,bs,
,,cs

Response body should be
{
“A”: “{{a}}”,
“B”: “{{b}}”,
“C”: “{{c}}”
}

1 Like

Hi @jeevananthank,

Error message is different for each scenario.

Hi @rohit2330 I think then it is hard to achieve all this scenario in one single request.
Can you describe your case that is demanding to do everything in one single request ?