Site icon rtCamp

API test automation with Playwright

Automation with Playwright-featured-image

Organizations have increasingly been embracing microservices architecture for their enterprise projects. It necessitates APIs as a core infrastructure requirement for communication among different modules of the web stack. It is thus imperative to implement a proper API testing strategy for such web applications.

After evaluating different API testing frameworks, we found Playwright to be a suitable foundation to develop a comprehensive, and seamless solution for the WordPress platform. And our QA team built a custom tool, API Playwright Utils.

Created by Microsoft, Playwright is a Node.js library for test automation, with new features and functionalities being added continuously. It is highly modular with a plethora of integration options and cross-browser support. This blog post is a run-down of the solution we built, the benefits we packed in, and its implementation.

Capabilities of API Playwright Utils

Playwright has a bunch of interesting features built on the request-response model:

Pros of API test automation

Cons of API test automation

Installation and configuration

Implementing the API Playwright Utils framework is quite a streamlined process.  

First, clone our GitHub repository for initiating the installation. To install the dependencies, run the “npm install” command.

Inside the project directory, find the sample.env file, enter the tokens, and baseURL into this file and rename it as “.env”.

Within the same project directory, navigate to the utils folder and find the response.js file. Insert all the response statuses for different requests as per the project requirements. 

Note that every project requires a different response status. 

Find the payload.js file in the directory to insert all the JSON payloads wrapped in custom functions, as shown in the following screenshot.

After configuring the response, the test cases can be added to the tests folder with the procedure described in the general Playwright test method.

Import all the functions to be executed from the utils folder. To understand the pattern for writing test cases, you can explore a few demo test cases from the sample.spec.js file. Implementing the utils will help make your test cases short and uncomplicated.

Find some demo test cases inside the sample.spec.js file

Executing test cases

Running “npx playwright test” command executes all the test cases.

For executing a specific test case, run the “npx playwright test [filename]” command.

Refer to Playwright’s official documentation to further inform yourself about the different options for running tests.

Preparing HTML Reports

Playwright can generate custom reports out of the box with several options. Here is the official documentation detailing built-in reporters. 

Use cases

At rtCamp, this framework is used in projects where the scope warrants an application. Here are some of its common use cases:

Conclusion

While there are other solutions out there, we believe that the test automation features of our implementation of API Playwright Utils will dovetail well with applications crafted around WordPress.

Explore our Quality Assurance Services and drop us a line if you’d like to build or improve your QA pipeline!

Links: API Playwright Utils | Quality Assurance Services | We’re Hiring

Exit mobile version