Skip to content

Commit 1c50324

Browse files
authored
Playwright Root: use expect instead of assert (#1467)
This commit makes sure to rely more on `await` for the asynchronous page driving actions like `page.goTo` and `page.click`. Similarly, use Playwright's `await expect(…)` wait-and-retry based assertions to reduce timing based flakiness in the test execution.
1 parent 972dc96 commit 1c50324

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/tests/functional/root_tests.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
import { test } from "@playwright/test"
2-
import { assert } from "chai"
3-
import { nextBody, pathname, visitAction } from "../helpers/page"
1+
import { expect, test } from "@playwright/test"
2+
import { visitAction, withPathname } from "../helpers/page"
43

54
test("visiting a location inside the root", async ({ page }) => {
6-
page.goto("/src/tests/fixtures/root/index.html")
7-
page.click("#link-page-inside")
8-
await nextBody(page)
9-
assert.equal(pathname(page.url()), "/src/tests/fixtures/root/page.html")
10-
assert.notEqual(await visitAction(page), "load")
5+
await page.goto("/src/tests/fixtures/root/index.html")
6+
await page.click("#link-page-inside")
7+
8+
await expect(page).toHaveURL(withPathname("/src/tests/fixtures/root/page.html"))
9+
expect(await visitAction(page)).not.toEqual("load")
1110
})
1211

1312
test("visiting the root itself", async ({ page }) => {
14-
page.goto("/src/tests/fixtures/root/page.html")
15-
page.click("#link-root")
16-
await nextBody(page)
17-
assert.equal(pathname(page.url()), "/src/tests/fixtures/root/")
18-
assert.notEqual(await visitAction(page), "load")
13+
await page.goto("/src/tests/fixtures/root/page.html")
14+
await page.click("#link-root")
15+
16+
await expect(page).toHaveURL(withPathname("/src/tests/fixtures/root/"))
17+
expect(await visitAction(page)).not.toEqual("load")
1918
})
2019

2120
test("visiting a location outside the root", async ({ page }) => {
22-
page.goto("/src/tests/fixtures/root/index.html")
23-
page.click("#link-page-outside")
24-
await nextBody(page)
25-
assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html")
26-
assert.equal(await visitAction(page), "load")
21+
await page.goto("/src/tests/fixtures/root/index.html")
22+
await page.click("#link-page-outside")
23+
24+
await expect(page).toHaveURL(withPathname("/src/tests/fixtures/one.html"))
25+
expect(await visitAction(page)).toEqual("load")
2726
})
2827

2928
test("visiting a location outside the root having the root as a prefix", async ({ page }) => {
30-
page.goto("/src/tests/fixtures/root/index.html")
31-
page.click("#link-page-outside-prefix")
32-
await nextBody(page)
33-
assert.equal(pathname(page.url()), "/src/tests/fixtures/rootlet.html")
34-
assert.equal(await visitAction(page), "load")
29+
await page.goto("/src/tests/fixtures/root/index.html")
30+
await page.click("#link-page-outside-prefix")
31+
32+
await expect(page).toHaveURL(withPathname("/src/tests/fixtures/rootlet.html"))
33+
expect(await visitAction(page)).toEqual("load")
3534
})

0 commit comments

Comments
 (0)