Have I ever mentioned how I dislike dynamic tests
Ideally, you should be in control of your test data, and your request sent to this end point should return exactly the same data every time its run.
If you want to test for US and USD, then this should be a request specifically testing for that outcome.
If you want to test other countries and currencies, then you should have multiple requests with associated tests for those outcomes. (Or you could potentially use the collection runner with a data file or the Collection Runner with a setNextRequest loop) if you want to test multiple combinations.
I’m not really understanding your IF statement. You are already targetting and defining a variable for customerCountry, so the IF statement should just be
if (customerCountry === "US" && customerCurrency === "USD") {
console.log("customerCountry and customerCurrency match");
}
Here is some code and options to consider.
// step 1 - parse XML\Soap response
const xmlResponse = pm.response.text();
// step 2 - parse the XML response to JSON - so its easier to work with
let parseString = require('xml2js').parseString;
const stripPrefix = require('xml2js').processors.stripPrefix;
parseString(xmlResponse, {
tagNameProcessors: [stripPrefix],
ignoreAttrs: true,
explicitArray: false,
}, function (err, jsonData) {
// handle any errors in the XML
if (err) {
console.log(err);
} else {
// do something with the result - define the fields you want to test against
let customerCountry = jsonData.recordOfInterest.customerCountry;
let customerCurrency = jsonData.recordOfInterest.customerCurrency
let productId = jsonData.recordOfInterest.productId
// Option 1 using IF statements.
if (customerCountry === "US" && customerCurrency === "USD") {
pm.test("Option 1: Is product ID valid for the country (US/USD)", function () {
pm.expect(productId).to.be.oneOf(["25680", "25681", "25682", "25683", "25684"]);
});
} else {
pm.test("Option 1: Is product ID valid for the country (Non US/USD)", function () {
pm.expect(productId).to.be.oneOf(["26680", "26681", "26682", "26683", "26684"]);
});
}
// Option 2 using switch
let countryCurrency = customerCountry + " " + customerCurrency
switch (countryCurrency) {
case "US USD":
pm.test("Option 2: Is product ID valid for the country (US/USD)", function () {
pm.expect(productId).to.be.oneOf(["25680", "25681", "25682", "25683", "25684"]);
});
break;
default:
pm.test("Option 2: Is product ID valid for the country (Non US/USD)", function () {
pm.expect(productId).to.be.oneOf(["26680", "26681", "26682", "26683", "26684"]);
});
}
}
});