forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expect-puppeteer-tests.ts
64 lines (53 loc) · 3.64 KB
/
expect-puppeteer-tests.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
52
53
54
55
56
57
58
59
60
61
62
63
64
import { ElementHandle, Page } from "puppeteer";
import { getDefaultOptions, setDefaultOptions } from 'expect-puppeteer';
import { expect } from 'expect';
const testGlobal = async (instance: ElementHandle | Page) => {
await expect(instance).toClick({ type: 'css', value: 'selector' });
await expect(instance).toClick({ type: 'xpath', value: 'selector' });
await expect(instance).toClick("selector");
await expect(instance).toClick("selector", { text: "text" });
await expect(instance).toClick("selector", { button: "left" });
await expect(instance).toClick("selector", { button: "right" });
await expect(instance).toClick("selector", { button: "middle" });
await expect(instance).toClick("selector", { clickCount: 3 });
await expect(instance).toClick("selector", { delay: 100 });
const dialog = await expect(instance).toDisplayDialog(async () => {});
console.log(dialog.message());
await expect(instance).toFill({ type: 'css', value: 'selector' }, 'value');
await expect(instance).toFill({ type: 'xpath', value: 'selector' }, 'value');
await expect(instance).toFill("selector", "value");
await expect(instance).toFill("selector", "value", { delay: 777 });
await expect(instance).toFillForm({ type: 'css', value: 'selector' }, { foo: 'bar', baz: 123 });
await expect(instance).toFillForm({ type: 'xpath', value: 'selector' }, { foo: 'bar', baz: 123 });
await expect(instance).toFillForm("selector", { foo: 'bar', baz: 123 });
await expect(instance).toFillForm("selector", { foo: 'bar', baz: 123 }, { delay: 777 });
await expect(instance).toMatch("some_string");
await expect(instance).toMatch("some_string", { timeout: 777 });
await expect(instance).toMatch("some_string", { polling: "raf", timeout: 777 });
await expect(instance).toMatch("some_string", { polling: "mutation", timeout: 777 });
await expect(instance).toMatch(/some_regexp/);
await expect(instance).toMatch(/some_regexp/, { timeout: 777 });
await expect(instance).toMatch(/some_regexp/, { polling: "raf", timeout: 777 });
await expect(instance).toMatch(/some_regexp/, { polling: "mutation", timeout: 777 });
await expect(instance).toMatchElement({ type: 'css', value: 'selector' });
await expect(instance).toMatchElement({ type: 'xpath', value: 'selector' });
await expect(instance).toMatchElement("selector");
await expect(instance).toMatchElement("selector", { polling: "raf", timeout: 777 });
await expect(instance).toMatchElement("selector", { polling: "mutation", text: "text" });
await expect(instance).toMatchElement("selector", { polling: "raf", visible: true });
await expect(instance).toSelect({ type: 'css', value: 'selector' }, 'valueOrText');
await expect(instance).toSelect({ type: 'xpath', value: 'selector' }, 'valueOrText');
await expect(instance).toSelect("selector", "valueOrText");
await expect(instance).toUploadFile({ type: 'css', value: 'selector' }, 'filePath');
await expect(instance).toUploadFile({ type: 'xpath', value: 'selector' }, 'filePath');
await expect(instance).toUploadFile("selector", "filePath");
await expect(instance).toUploadFile("selector", "filePath", { timeout: 777 });
setDefaultOptions({ polling: "mutation", timeout: 5000 });
const { polling, timeout } = getDefaultOptions();
};
const testImported = async (instance: ElementHandle | Page) => {
const expectPuppeteer = await import("expect-puppeteer");
await expectPuppeteer(instance).toClick("selector");
await expect(instance).toClick("selector", { polling: "mutation", text: "text" });
await expect(instance).toClick("selector", { polling: "raf", timeout: 777 });
};