From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Handle requests

Handle requests

In this lesson, we'll learn how to handle requests and modify the same. In the previous lesson, we created our event listener that is onEveryRequest, get the request object. Now we can read in the properties of our request like the URL it's being sent to, the post data attached with the same, along with all the other attributes of our request. Now what we cannot do here is we cannot modify or change the request in any way. So if we want to change the request when it's being sent, instead of an event listener, we have to use a route handler. So we'll go ahead and remove our event listener. And then when we register the event listener, we'll register a route handler instead. And to do that, we'll use the route method. The route method instead of an event takes the URL which will be used to handle that is let's say we'd like to handle the route for our homepage. So let's go ahead and give it to our route handler. And then the second argument will be the function which will get our route,…

Contents