forked from MarcusFelling/demo.playwright
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-assertions.spec.ts
51 lines (44 loc) · 1.9 KB
/
3-assertions.spec.ts
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
import {test, expect} from '@playwright/test';
test.beforeEach(async ({page}) => {
await page.goto('https://todomvc.com/examples/vanilla-es6/');
});
/**
* 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('Vanilla ES6 • TodoMVC');
await expect(page).toHaveURL('https://todomvc.com/examples/vanilla-es6/');
});
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/toHaveCSS', async () => {
await expect(page.locator('[placeholder="What needs to be done?"]')).toHaveClass('new-todo');
await page.click('text=Clear completed');
await expect(page.locator('.main')).toHaveCSS('display', 'none');
});
});