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 02:53, 6 June 2024
, 6 June→Mocking API
m (→Mocking API) |
|||
Line 1,143: | Line 1,143: | ||
=== Mocking API === | === Mocking API === | ||
* Goto https://conduit.bondaracademy.com/ | |||
* check network tab in dev tools | |||
* mocking the tags api call | |||
file <code>tests\workingWithAPI.spec.ts</code> | |||
<nowiki> | |||
import { test, expect } from "@playwright/test" | |||
import ressponseBody from "../test-data/tags.json" | |||
test.beforeEach(async ({ page }) => { | |||
await page.route( | |||
"*/**/api/tags", | |||
async (route) => { | |||
await route.fulfill({ | |||
body: JSON.stringify(ressponseBody), | |||
}) | |||
} | |||
) | |||
await page.goto("https://conduit.bondaracademy.com/") | |||
}) | |||
test("has title", async ({ page }) => { | |||
await expect(page.locator(".navbar-brand")).toHaveText("conduit") | |||
await expect( | |||
page.locator(".tag-default.tag-pill", { hasText: "Playwright" }) | |||
).toBeVisible() | |||
})</nowiki> | |||
file <code>test-data\tags.json</code> | |||
<nowiki> | |||
{ | |||
"tags": ["Automation", "Playwright"] | |||
}</nowiki> | |||
=== Mocking API Response === | === Mocking API Response === | ||
=== Perform API Request === | === Perform API Request === |