I am trying to use a dynamic field from parsed response. The parsed response must be for the last request made using a specific environment. Is this possible?
Here's the scenario:
1. Make Request 1 using Environment A
Receive Response A1
2. Make Request 1 using Environment B
Receive Response B1
3. Make Request 2 using environment A, with field from parsed response A1
Receive Response A2
4. Make Request 2 using environment B, with field from parsed response B1
Receive Response B2
How do I orchestrate steps 3 and 4?
We are planning to implement it properly by using tabs on MacOS Sierra. With each tab operation as dedicated session and you will pin environment selection to a tab.
This is not properly implemented in Paw yet, but you can write a custom Dynamic value for this or use a hacky workaround:
Set a X-paw-env
header in Request 1 the partitioning environment variable. This way you get the current value of the partitioning variable depending on the environment
In Request 2 in the field where you are using the Response Parsed Body
insert a Custom
dynamic value instead. Inside there get the latest exchange for Request 1 where the request header matches the value of your partitioning variable for the current environment. Then extract the value you need from the response body using RegExp Match
function evaluate(context){
var variableValue = context.getEnvironmentVariableByName("myPartitioningVariable").getCurrentValue()
var exchanges = context.getRequestByName("Request1").getAllExchanges();
for (var i = 0; i < exchanges.length; i++) {
console.log(i, exchanges[i].requestHeaders["X-paw-env"]);
if (variableValue === exchanges[i].requestHeaders["X-paw-env"]) {
var dv = new DynamicValue("com.luckymarmot.RegExMatch", { re: '"user":\\s*"([^"]*)', input: exchanges[i].responseBody });
console.log(exchanges[i].responseBody)
console.log(i, "returning")
return dv.getEvaluatedString();
}
}
};