Get Request | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: API Testing Basics
Instructor: Artem Bondar
Lesson Summary
In this lesson, we learned how to write API tests using Playwright . We focused on creating GET requests for our API. Here’s a summary of the key concepts covered: Test Structure The test function is used to define a test, taking a title and a callback function as arguments. For API testing, we use the request fixture instead of the page fixture , which is used for UI testing. Making a GET Request To perform a GET request: const response = await request.get('API_URL'); We must use the await keyword because the get method is a promise that waits for a response. Response Handling To extract the JSON body from the response, use: const jsonResponse = await response.json(); Assertions can be made using the built-in expect library in Playwright. Assertions Examples Check the response status: expect(response.status()).toEqual(200); Validate properties in the JSON response: expect(jsonResponse.tags[0]).toEqual('test'); Check the length of an array: expect(jsonResponse.tags.length).toBeLessThanOrEqual(10); In summary, we created two tests for our API, ensuring we understood how to make requests, handle responses, and validate results effectively. This approach allows for quick and reliable API testing.