Tests are executed after a response is received from the server. You can add multiple tests to a request. You can add tests to both requests saved and not saved in a collection.
pw
which can handle post-request scripts as well as tests. Here we’ll use pw
to run tests on the response received from APIs.
test
method from the pw
API to group related statements.
There are two ways to test the status code:
Condition | Code |
---|---|
Check if response code is 200 | pw.expect(pw.response.status).toBe(200) |
In-built matcher function | pw.expect(pw.response.status).toBeLevel2xx() |
.toBe()
to assert specific values and .toBeType()
to assert specific data types as shown in the code snippet below: