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 ?

4

1 回答 1

0

好了朋友们。显然,您不能在测试脚本中设置变量,因为测试脚本是在 api 调用之后运行的。这需要在预请求脚本中设置。至于如何根据要求设置所有各种测试,我认为这是无法做到的。因此,我只是为每个测试用例提出一个新请求。

于 2020-04-02T22:17:43.877 回答