So you just need to use the proper attribute for err. First, I would try console logging the whole error, that way, you can then see what attributes it has.
Thanks, i noticed when i changed that url into a text, and added it to the variable, when i print it to the console i am seeing undefined , and when i am using that same variable for my pm.sendrequest i am seeing that its not getting the url instead its just writing the variable as a url.
So in order to use a postman variable, you need to first obtain a reference to the variable. You can do that by using the following syntax in your script:
var TracerswithAMPurl = pm.environment.get("TracerswithAMPurl");
Then you can use the variable as you normally would with javascript.
pm.sendRequest(TracerswithAMPrul, function (err, response) {
if (err) {
console.log(err);
}
console.log("Response is " + pm.response.text());
pm.expect.pass("Pass test")
});
but am seeing the same unexpected token issue ā¦
Json error ā¦
the url is a text so is that why its sending this error ā¦? do you we need to convert that text into json ?
From the looks of it, you error is coming from response.json. This is because your response actually isnt json, its just text. The snippet above was taken from something else that has a json response.
Instead, use pm.response.text() and you shouldnt have an error anymore. Iāve also updated the example above.
Thank you very much for thatā¦ instead of using the console.log , how can i show these results through the test results? i tried pm.expect.pass or pm.expect.fail but pass is not a function
is it fine if i ask more questions on this forum ā¦?
pm.test("Tracers with AMP Url hits the server successfully", function () {
pm.sendRequest(TracerswithAMPurl, function (err, response) {
pm.expect(err).to.not.be.ok;
pm.expect(response).to.have.property('code', 200);
pm.expect(response).to.have.property('status', 'OK');
});
});
Youāre welcome! Glad we can help and that you can figure it out.
Youāre script looks pretty good.
As for asking more questions, I would say if you have new unrelated questions to the original issue for this post, I would make a new post around it, for organizational purposes.
Iām going to reformat your test script for better readability.
pm.test(āif 200 - Pass else Fail - 404 errorā, function(){
pm.response.to.have.status(200);
});
pm.test(āResponse Time is less than 600msā, function(){
pm.expect(pm.response.responseTime).to.be.below(600);
});
const apiOne = JSON.parse(pm.collectionVariables.get(āAlertBanner_Messageā));
const apiTwo = pm.response.json();
for(let i = 0; i < apiOne.length; i++) {
const alertbanner = apiOne[i];
const apiTwo = apiTwo.find(portalannouncement => portalannouncement.announcementId === alertbanner.announcementId && portalannouncement.header === alertbanner.header &&
portalannouncement.body === alertbanner.body);
pm.test(Has matching header for ${alertbanner.header}, function (){
pm.expect(apiTwo).to.not.be.undefined;
});
}
Since you arenāt seeing any matching header tests, that means that you donāt have any objects in your apiOne array and your for loop has nothing to iterate over.