mercredi 1 avril 2020

Postman Testing Scripts: How to change env variable after one test case?

So my issue is that I want to have 2 tests for a single api call - one pass and one fail with missing params.

Here is what I have:

pm.test("Successful Login", function () {
pm.response.to.have.status(200);

});

pm.test("Missing Parameters", function () {
    const currentUsername = pm.environment.get("username");
    pm.environment.set("username", null);
    pm.response.to.have.status(400);
    //pm.environment.set("username", currentUsername);
});

So as you can see, I set username to null for the second test, only to set it back to is original value after the test. What I found was that instead of running the script sequentially, postman set my username to null before the first test could have been run, so I fail the first test. What should I do ?

Aucun commentaire:

Enregistrer un commentaire