jeudi 17 mai 2018

Unable to branch my tests using a variable in Postman

I have a collection with two folders, one for POSTs and one for GETs

Collection

At the collection level, I have set variables

Collection variables

And the following collection-level scripts to be run after every request:

requestLast = pm.variables.get("requestLast");
requestCurrent = pm.variables.get("requestCurrent");
statusGet = pm.variables.get("statusGet");

requestLast = requestCurrent;
requestCurrent = pm.request.name;

I want to always be keeping track of the previously run request, so I can return to it when necessary.

In the 'positivePosts' folder I have the following test script:

if(statusGet === 0) {
    postman.setNextRequest("resultsPositive");
}
else {
    statusGet = 0;
}

pm.variables.set("requestLast", requestLast);
pm.variables.set("requestCurrent", requestCurrent);
pm.variables.set("statusGet", statusGet);

The individual POST requests have no test scripts.

The results folder does not have any tests, but the resultsPositive GET has this test script:

var jsonData = JSON.parse(responseBody);
schema = pm.variables.get("schemaPositive");
tests["Valid Schema"] = tv4.validate(jsonData, schema);
tests["Status code is 200"] = responseCode.code === 200;

statusGet = 1;
postman.setNextRequest(requestLast);

pm.variables.set("requestLast", requestLast);
pm.variables.set("requestCurrent", requestCurrent);
pm.variables.set("statusGet", statusGet);

There are no pre-request scripts anywhere in the collection.

When running the collection, I would expect this order:

  1. postRich
  2. resultsPositive
  3. postAllProperties
  4. resultsPositive
  5. postMinimum
  6. resultsPositive

However, what I actually see is:

  1. postRich
  2. postAllProperties
  3. postPositive

Looking at the console, the 'requestCurrent' variable never changes and stays 'null' for the entire run. I also don't understand why postPositive is not run after postRich.

Aucun commentaire:

Enregistrer un commentaire