-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path3-assertions.spec.ts
44 lines (38 loc) · 1.59 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
import {test, expect} from '@playwright/test';
test.beforeEach(async ({page}) => {
await page.goto('https://todomvc.com/examples/javascript-es6/dist/');
});
/**
* 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('TodoMVC: JavaScript Es6 Webpack');
await expect(page).toHaveURL('https://todomvc.com/examples/javascript-es6/dist/');
});
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');
});
});