Udemy Playwright: Web Automation Testing From Zero to Hero: Difference between revisions
Jump to navigation
Jump to search
Udemy Playwright: Web Automation Testing From Zero to Hero (view source)
Revision as of 03:25, 6 June 2024
, 6 June→Mocking API Response
m (→Mocking API) |
|||
Line 1,177: | Line 1,177: | ||
}</nowiki> | }</nowiki> | ||
=== | === Modifying an API Response === | ||
Add the following code the the previous <code>test.beforeEach(...)</code> call | |||
<nowiki> | |||
await page.route("*/**/api/articles*", async (route) => { | |||
const response = await route.fetch() | |||
const responseBody = await response.json() | |||
responseBody.articles[0].title = "This is a test title" | |||
responseBody.articles[0].description = "This is a description" | |||
await route.fulfill({ body: JSON.stringify(responseBody) }) | |||
})</nowiki> | |||
=== Perform API Request === | === Perform API Request === | ||
=== Intercept Browser API Response === | === Intercept Browser API Response === | ||
=== Sharing Authentication State === | === Sharing Authentication State === | ||
=== API Authentication === | === API Authentication === |