From the course: Playwright Essential Training: Abstractions, Fixtures, and Complex Scenarios

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Mocking HTTP responses with Playwright

Mocking HTTP responses with Playwright

- [Instructor] Another approach to working with network requests in Playwright is to override certain things in the response or to fully mock the network request. We'll walk through both of these examples in this video. So let's go back to our home spec and we're just going to go ahead and create a new test at the bottom down here. The test will be to validate the first one. Validate product data is visible from modified API, add our test information here. All right, so I think we should have a valid test framework here and we're just going to go ahead and copy this test step up here. We'll paste this here. So we're going to intercept, I'm actually going to say we're going to overwrite the products in point. It's very similar context, but there's some slight differences. So hopefully you get to see those here. So we've got our paid route, we've got the endpoint we want to route to, we have our awaitroute.fetch. The next thing we want to do is create a JSON variable. I'm going to set…

Contents