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.

Network events

Network events

In this section, we'll learn about the network events and how to handle the same. So when we navigate to a website, we send a request to its URL, that is the website. Now when the website gets the request, it sends us a response back, which is the HTML code or other resource file like CSS or any image. So when we navigate to a website, we send a request to the same, that is its URL address, and the website sends us a response back. To handle these events, we can set up event listeners, which we already learned in the previous sections. So to set an event listener for the request event, we can use the page objects on method And the event which is a request, set up a function, which will be called whenever the request happens. So I can go ahead and define this function. On request, we will get the request object. And for now we can pass on the block. we can go ahead and define an event listener for the response event, and set Similarly, up a on response function, which would be defined…

Contents