0

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 ?

Naman Jain
  • 321
  • 5
  • 21

1 Answers1

0

Ok guys. Apparently you cannot set variables in the testing scripts because the testing script is run after the api call has been made. This needed to be set in the pre-request script. As for how to set all various tests in just on request I dont think this can be done. Therefore, I am just making a new request per test case.

Naman Jain
  • 321
  • 5
  • 21