need to get the parameters and values ​​passed in the url (Query Params) to validate these values.
The parameter and value are passed like this in the url:
/Data?value=4
I want to validate the value passed in this parameter in the test script. I was able to validate when it happened in the body, but I need to validate when it happened in Params. Please, help!
1 Like
Hi @mirellae2e! I’m having a bit of trouble understanding what you’re asking. Can you elaborate a bit on what you mean when you say you want to “validate the value passed in the parameter in the test script?” What is the current code in your Tests tab?
Hello, in my test script I did validating the request body, now I need to validate the request’s Params.
//Validate Field
pm.test(“Field is between 1 and 100.”, function () {
var req = JSON.parse(pm.request.queryParams); // this does not work
pm.environment.get("value", req.value);
pm.expect(req.value).to.above(0.99);
pm.expect(req.value).to.below(101);
});
console.log(pm.request.toJSON().url.query)
2 Likes
Can you tell me how to make sure that a field is not between 1 and 10? I managed to do it to show when it is between 1 and 10, now I need to show when it is not to be, to be an invalid test.
Here the example that must be between 1 and 10, now I need one that should not be between 1 and 10.
pm.test(“Field 0 and 30.”, function () {
var req = JSON.parse(pm.request.body.raw);
pm.environment.set("field", req.field);
pm.expect(req.field).to.above(-1);
pm.expect(req.field).to.below(31);
});
pm.expect(2).to.be.within(1, 3);
Postman is based on chai assertions so you can use within
Expect / Should - Chai
1 Like
Hello, did you manage to find the solution?
I need to validate the data type of my parameters