My question:
In a test script I want to validate a response is within a given range, but the problem is the number format is Brazilian, (1,1 instead of 1.1) and is so surrounded by “” and treated like text.
My Code Attempt:
pm.test(“Test_07 AI % is in range 3,5 to 4,5”, function () {
var annualMode = pm.response.json();
pm.expect(annualMode.recScheme.incPctAnMode).is.lessThan(“5,0”);
Obviously this fails. AssertionError: expected ‘3,7’ to be a number or a date
First you will need to change the string from 1,1 to 1.1. You can do this with simple javascript string replace text.replace(",", “.”).
Then you will need to convert the text to an integer again with simple javascript. parseInt(text).
So your test should look like this…
pm.test(“Test_07 AI % is in range 3,5 to 4,5”, function () {
var annualMode = pm.response.json();
var value = annualMode.recScheme.incPctAnMode.replace(’,’,’.’) // Setting new value and replacing the character.
pm.expect(parseInt(value)).is.lessThan(5.0);