Hi,
I am trying to use the sendRequest in the tests.
Here I am getting the some data from API,
and trying to delete it using another API.
For delete request, I need a token for which I need another API.
Below code is working fine and sometimes it is not working due to the reason there is already a request trying to process.
I have added timeout as well but that is not helping much
pm.test("Status code is 202", function authenticate() {
const postRequest = createGetTimersRequest();
pm.sendRequest(postRequest, (error, response) => {
var jsonData = response.json();
pm.variables.get("service_token");
if (jsonData.departureTimerSetting.timers.length > 0) {
jsonData.departureTimerSetting.timers.forEach(function(timer) {
const tokenRequest = createRequest("XX", "XXXX");
setTimeout(function() {
pm.sendRequest(tokenRequest, (error, tokenResponse) => {
var tokenData = tokenResponse.json();
const timerDelete = createDeleteTimersRequest(timer.timerIndex, tokenData.token);
setTimeout(function() {
pm.sendRequest(timerDelete, function(err, res) {
pm.test("Status code is 200", () => {
setTimeout(function() {}, 1000);
pm.response.to.have.status(200);
});
})
}, 2000);
})
}, 4000);
})
}
});
});