How we automate API testing in ZIWO
It’s not a secret that when the tests are automated, it eliminates human errors, saves time and money. Automated tests bring full confidence in our API testing behavior and consistency.
ZIWO is an API-Centric Web Application, so API test automation is the most important one for us.
- We use Postman to write tests. Postman is a tool used by software developers and testers worldwide for API testing that provides a wide range of features and is really easy to use.
- Testing something like HTTP status codes, for example, can be done using a simple script like this (and Postman even has snippets for it):
This is an example of a request with several tests in Postman:
- The tests tab on the request itself when a test is for one request only.
- The tests tab on the folder level is very useful to apply tests to each request.
- Since we have a lot of endpoints and different scenarios to check, our test base is pretty complex. To make it easier to maintain it’s organised into test collections, then top-level folders and sub-folders.
As you can see on the picture above, the test suit will be executed in 4 phases and we have top-level folders for that:
- Pre-request folder where we log in the agents.
- Tests for a regular agent + pre-request actions (changing settings, generating and saving data for tests).
- The same for a desk agent.
- Post-request: reverting all the changes, removing some fake data.
To check the workflow locally during test development we use Postman collection runner. It’s an easy way to run all the requests quickly and visualise results.
This is the Runner:
Postman allows dynamically control the workflow, like this:
When the test suit is ready to be used, we switch to another tool – Newman CLI, because it allows us to use Postman tests as a part of our CI/CD process.
CI/CD and Postman tests
We use GitHub actions for this purpose. Every time our developers want to merge the changes to the master branch, we add a label to a PR and it triggers a Newman CLI test.
All the test results are stored in influxDB and we also generate some reports with Grafana: