Intercept Browser API Calls | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Interacting with APIs
Instructor: Artem Bondar
Lesson Summary
In this lesson, we learned how to intercept browser API responses , save the response into a variable, and extract the response body for later use in tests. This technique is particularly useful for retrieving specific test data from the response body. Lesson Overview We automated a scenario where we: Created a new article titled "Playwright is awesome" . Published the article. Validated that the article appeared in the global feed. Deleted the article using the API to clean up test data. Key Steps Create the Article: Fill out the article title and content. Publish the article using the await page.getByRole method. Validate Article Creation: Check that the article appears in the global feed. Intercept API Response: Use await page.waitForResponse to capture the response after publishing. Extract the slug ID from the response body. Delete the Article: Make a DELETE request using the slug ID. Assert that the article was successfully deleted. Conclusion By intercepting the API calls and using the response data, we can effectively manage test data and ensure our tests are repeatable without conflicts. This lesson demonstrated the complete flow from article creation to deletion using API calls.