Udemy Playwright: Web Automation Testing From Zero to Hero: Difference between revisions

Jump to navigation Jump to search
m
Line 1,177: Line 1,177:
}</nowiki>
}</nowiki>


=== Mocking API Response ===
=== 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 ===

Navigation menu