-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path2-actions.spec.ts
51 lines (42 loc) · 1.99 KB
/
2-actions.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/javascript-es6/dist/');
});
/**
* Locators are used to represent a selector on a page and re-use them. They have
* strictMode enabled by default. This option will throw an error if the selector
* will resolve to multiple elements.
* In this example we create a todo item, assert that it exists and then filter
* by the completed items to ensure that the item is not visible anymore.
* @see https://playwright.dev/docs/api/class-locator
*/
test('basic interaction', async ({page}) => {
const inputBox = page.locator('input.new-todo');
const todoList = page.locator('.todo-list');
await inputBox.fill('Learn Playwright');
await inputBox.press('Enter');
await expect(todoList).toHaveText('Learn Playwright');
await page.locator('.filters >> text=Completed').click();
await expect(todoList).not.toHaveText('Learn Playwright');
});
/**
* Playwright supports different selector engines which you can combine with '>>'.
* @see https://playwright.dev/docs/selectors
*/
test('element selectors', async ({page}) => {
// When no selector engine is specified, Playwright will use the css selector engine.
await page.fill('.header input', 'Learn Playwright');
// So the selector above is the same as the following:
await page.press('css=.header input', 'Enter');
// select by text with the text selector engine:
await page.click('text=All');
// Combine css and text selectors (https://playwright.dev/docs/selectors/#text-selector)
await page.click('.todo-list > li:has-text("Playwright")');
await page.click('.todoapp .footer >> text=Completed');
// Selecting based on layout, with css selector
expect(await page.innerText('a:right-of(:text("Active"))')).toBe('Completed');
// Only visible elements, with css selector
await page.click('text=Completed >> visible=true');
// XPath selector
await page.click('xpath=//html/body/section/main/div/label');
});