-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-assertions.spec.ts
More file actions
54 lines (47 loc) · 1.82 KB
/
Copy path3-assertions.spec.ts
File metadata and controls
54 lines (47 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { expect } from "@playwright/test";
import { test } from "./base.ts";
test.beforeEach(async ({ page }) => {
await page.goto("https://demo.playwright.dev/todomvc");
});
/**
* All available test assertions are listed here:
* @see https://playwright.dev/docs/test-assertions/
*/
test("should be able to use assertions", async ({ page }) => {
await test.step("toHaveTitle/toHaveURL", async () => {
await expect(page).toHaveTitle("React • TodoMVC");
await expect(page).toHaveURL(/^https:\/\/demo.playwright.dev\/todomvc/);
});
await test.step("toBeEmpty/toHaveValue", async () => {
const input = page.locator("input.new-todo");
await expect(input).toBeEmpty();
await input.fill("Buy milk");
await expect(input).toHaveValue("Buy milk");
await input.press("Enter");
});
await test.step("toHaveCount/toHaveText/toContainText", async () => {
const items = page.locator(".todo-list li");
await expect(items).toHaveCount(1);
await expect(items.first()).toHaveText("Buy milk");
await expect(items).toHaveText(["Buy milk"]);
await expect(items.first()).toContainText("milk");
});
await test.step("toBeChecked", async () => {
const firstItemCheckbox = page.locator(
'input[type=checkbox]:left-of(:text("Buy milk"))'
);
await expect(firstItemCheckbox).not.toBeChecked();
await page.check('div input[type="checkbox"]');
await expect(firstItemCheckbox).toBeChecked();
});
await test.step("toBeVisible/toBeHidden", async () => {
await expect(page.locator("text=Buy milk")).toBeVisible();
await page.click("text=Active");
await expect(page.locator("text=Buy milk")).toBeHidden();
});
await test.step("toHaveClass", async () => {
await expect(
page.locator('[placeholder="What needs to be done?"]')
).toHaveClass("new-todo");
});
});