This blog is on Playwright API Testing using Typescript. I will cover the following topics,
1. Introduction to Playwright API Testing
2. What is APIRequestContext?
3. How to use various Request methods and verify its response?
Playwright can be used to get access to the REST API of your application.
Sometimes you may want to send requests to the server directly from Node.js without loading a page and running js code in it. A few examples where it may come in handy:
· Test your server API.
· Prepare server side state before visiting the web application in a test.
· Validate server side post-conditions after running some actions in the browser.
All of that could be achieved via APIRequestContext methods.
What is APIRequestContext ?
This API is used for the Web API testing and can be used to trigger API endpoints, configure micro-services, prepare environment or the service to your e2e test.
Each Playwright browser context has associated with APIRequestContext instance which shares cookie storage with the browser context and can be accessed via browserContext.request or page.request. It is also possible to create a new…