Request Handler Constructor | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Building a Framework
Instructor: Artem Bondar
Lesson Summary
In this lesson, we modify our request handler to enable API requests by passing a request fixture into the handler. Here’s a breakdown of the key steps: Modifications to the Request Handler We need to create a constructor in the request handler that defines required parameters for creating a new instance. Two parameters are required: request : of type API request context API base URL : of type string Remove the hard-coded URL from the class and pass it as an argument during instantiation. Updating the Fixture In the fixtures.ts , we need to pass the request fixture as an argument to the async function. Create a constant for base URL and pass it as the second argument to the request handler. Remove the hard-coded default base URL from the class and assign it through the fixture. Summary of Changes We successfully created a constructor in the request handler that accepts two parameters: the request fixture and the API base URL . These parameters are assigned to class fields for later use. The fixture was updated to accommodate these changes, allowing us to pass the necessary arguments when creating a new instance of the request handler. In the next lesson, we will begin making actual API requests using our custom request handler.