snk_qa
(Soumya Khedagi)
October 30, 2020, 1:43am
1
I have written pre-request script and storing the response in a variable.
pm.sendRequest(“http://localhost:8086/query?db=edgeOpsApp&q=SHOW MEASUREMENTS”, function (err, response) {
resp_tst= ;*
_.each(response.json().results[0].series[0].values, (item) => {resp_tst.push(item[0])})*
});
resp_tst is the variable.
Now, in the Test tab, I want to print this variable.
console.log(resp_tst)
This was working for me all the time, but from past few hours I getting ‘undefined’ in the response.
Not sure what is the problem. I have not changed any settings/configurations.
Basically, variable from pre-request is not working in Tests tab
Please help!
bpricilla
(Pricilla B)
October 30, 2020, 2:21am
2
@snk_qa : Welcome to the community
Can you please share the response if possible? May be the schema got changed in your response. The script is unable to pick the variable then.
snk_qa
(Soumya Khedagi)
October 30, 2020, 2:30am
3
when I print the response in Pre-request Tab, the value is correctly displayed in console. But same is not getting accessed in Tests tab.
If you want your variable to persist from the pre-request script to the test script, you need to save it as a postman variable.
pm.variables.set('resp_tst', JSON.stringify(resp_tst));
In your test script you would just pull it out of postman:
const resp_tst = JSON.parse(pm.variables.get('resp_tst'));
snk_qa
(Soumya Khedagi)
October 30, 2020, 2:05pm
5
Thanks Allen. This works.
But I wonder how did it work before. I’m running this tests from 2 months now without setting the variables. From yesterday it is suddenly failing.
Thanks for your help.
1 Like