Performing API Request | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Interacting with APIs
Instructor: Artem Bondar
Lesson Summary
In this lesson, you will learn how to perform API requests using Playwright , a powerful technique for setting up test data and validating functionality in web applications. Key Concepts API Usage: Set up test data on the server before running UI tests and delete test data after tests. Scenario Overview: Automate a sign-in process, create a new article, and validate the delete functionality. Steps to Automate Sign in to the application using an account (e.g., pwtest.com with password welcome1 ). Create a new article with a title, description, and body. To test the delete functionality: Create the article via an API call instead of UI for efficiency. Delete the article using the UI. API Call Process To create an article via API: await request.post(url, { data: { title: "This is a test article", description: "This is a test description", body: "This is a test body" }, headers: { Authorization: `Token ${accessToken}` } }); Validation Steps Ensure the article is created successfully by checking the response status code (should be 201 ). Delete the article and validate its absence on the global feed. In summary, use the request method in Playwright to perform API calls, handle the data object for the request body, and manage authorization tokens for secure API interactions. That's it for this lesson! See you in the next one.