Hi I need to solve this problem:
My question:
I need to check response from pm.sendRequest test, how I can do this?
// check modals to show array
pm.test("Modals to show blank", function () {
pm.expect(pm.response.text()).to.include("modals_to_show:[]");});
Details (like screenshots):
var jsonData = pm.response.json();
// tests
if (pm.response.code != 201) {
console.log(jsonData.detail);
pm.test("Status code is 201", function () {
pm.response.to.have.status(201);
});
pm.test("Errors:", function () {
pm.expect(pm.response.text()).not.include("message");});
}
else {
pm.test("Status code is 201", function () {
pm.response.to.have.status(201);
});
pm.test("Token present", function () {
pm.expect(pm.response.text()).to.include("token");});
// save token to var
pm.environment.set("test.token", pm.variables.replaceIn(jsonData.token));
var token = pm.environment.get("test.token");
// get info request
pm.sendRequest({
url: 'my_url',
method: 'GET',
auth: {
type: "bearer",
bearer: [
{
key: "token",
value: token,
type: "string"
}
]
},
header: {
'content-type': 'application/json',
},
}, function (err, res) {
});
}