Requirement : Trying to pass Request1 output(particular field only) as input to Request2
Based upon the test data i am getting different response for request1. where i need help how to pass based on the condition
Basically for Positive flow and Negative flow response code is coming as 200 only.
I need to manipulate based on the response body.
So if i get the Sample1Header i need to pass the “requireddata” filed to next request
Currently i am storing this “requireddata” as env variables. Positive flow is working If i give condition
Code I have tried
var requireddata = “”;
var jsonData = JSON.parse(responseBody);
pm.globals.set(“jsonData”,jsonData);
if(requireddata = jsonData.Sample1Header[0].requireddata){
console.log(requireddata);
pm.globals.set(“requireddata”,jsonData.Sample1Header[0].requireddata);}
else{
(pm.expect(pm.response.text()).to.include(“No Record”))
{
requireddata = null;
pm.global.set(“requireddata”,requireddata);
console.log(“No value from first response”);
}}
Tip #1, don’t call your global variable the same as a local variable.
Give them different names. It will use the local scope first. (Plus it can get confusing).
Use const to declare the response, as the response should be constant (and not change).
Tip #2
Write your steps\logic out. It will you you, and others to troubleshoot.
I’m still trying to work out what you are trying to achieve.
You are physically setting the local variable requireddata to null, so as far as I can tell, your IF statement will always trigger the ELSE (unless the requireddata field in the actual response is actually null).
If you trying to craft positive and negative tests, then these should be separate tests. (Best practice and all that).
If you post code, can you please use the preformatted code, as its hard to read when everything is aligned to the left.
Sure we can help you on this, but just need to you refine your question and maybe split your code into steps so we can understand your logic better.