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.

Modify response

Modify response

In the previous lesson, we learned about the page route handler which can be used to handle the request and modify the same. In this lesson, we'll learn how to modify and handle our responses. Now what we did before is we continued the route or about it the same based on our need. Let's say what we want to do is return this route a response ourselves. To do that, we can use the fulfill method. That is, we can fulfill the request even without contacting the web server with a custom defined response. So let's go ahead and say when we visit the website that is the homepage, we'll go ahead and fulfill this request with a custom response. So we'll go ahead and provide the status code 200 which means everything is fine. We'll give you a response and we can specify the response body which will be the actual HTML. So let's go ahead and quickly define an HTML with a custom body. So here you can see I have a simple HTML with body with a h1 that is heading of custom response. So what will happen…

Contents