Request Handler Improvement | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Building a Framework
Instructor: Artem Bondar
Lesson Summary
In this lesson, we address an issue in our request handler that causes parameters from one request to leak into another. This occurs when executing two tasks: getArticles and getTestTags . Problem Overview When running the getArticleTest , we noticed that parameters from the first request (to get articles) were unintentionally carried over to the second request (to get tags). This happens because the values for the request handler's fields are not reset between requests. Solution Steps Create a private method called cleanUpFields to reset the request handler's fields after each request. Set the following fields to their default values: API body : empty object API headers : empty object base URL : undefined API path : empty string query params : empty object Adjust the type for base URL to accept both string and undefined . Invoke cleanUpFields after every request method: GET , POST , PUT , and DELETE . Testing the Fix After implementing these changes, we reran the tests. The first request executed correctly with parameters, and the second request to the tags endpoint no longer included any leaking parameters. This confirms that our fix was successful. In summary, we effectively resolved the issue of parameter leakage in our request handler, ensuring cleaner and more reliable requests in future tests.