How can I adopt this code to include, that when the string value is "5.10", run the test collection as normal? Currently it works but it will just fail the test and this looks bad on my reporting.
I've tried various solutions but none of them work & comparing floats in chai/postman is a nightmare. Or well any of my solutions I've created have an issue. I have to use strings to match the values as in my code versioning, 5.10 is higher than 5.20... Hence the string matching.
Im also saving the 5.6 = into tofixed(2); Hence 5.60
*CODE *:
pm.test("Validate the following strings", function() {
let expectedStrings = ["4.60", "4.80", "4.70", "4.90", "4.10", "4.11",
"4.12", "4.13", "5.20", "5.30", "5.40", "5.50", "5.60", "5.70", "5.80",
"5.90"];
const hasAnyExpectedString = expectedStrings.some((s) =>
version2.includes(s));
pm.expect(hasAnyExpectedString).to.be.true;
postman.setNextRequest("stoptest1")
});
I don’t want this test to fail when the expected string is not included in that array of strings for example ‘5.10’
If you can help, that would be great.
Cheers.
CodePudding user response:
actually i was just making this harder for myself and just wrote a bunch of if statements.. :/
if (version == 'etc')
{
postman.setNextRequest("stoptest1")
}
CodePudding user response:
Based on your comment
I only want it to go to stoptest1 if its those versions. if its '5.10' then the test should fail and not go to stoptest1
I make a sample code to satify your requirement.
const version = ... //get from somewhere
pm.test("Validate the following strings", function() {
let expectedStrings = ["4.60", "4.80", "4.70", "4.90", "4.10", "4.11",
"4.12", "4.13", "5.20", "5.30", "5.40", "5.50", "5.60", "5.70", "5.80", "5.90"];
const hasAnyExpectedString = expectedStrings.includes(version);
if(hasAnyExpectedString){
postman.setNextRequest("stoptest1")
} else {
pm.expect(hasAnyExpectedString).to.be.true;
}
});