-
Notifications
You must be signed in to change notification settings - Fork 672
/
test.js
106 lines (82 loc) · 3.16 KB
/
test.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import Page from './page-model';
fixture `A set of examples that illustrate how to use TestCafe API`
.page `https://devexpress.github.io/testcafe/example/`;
// Page model
const page = new Page();
// Tests
test('Text typing basics', async t => {
await t
.typeText(page.nameInput, 'Peter') // Type name
.typeText(page.nameInput, 'Paker', { replace: true }) // Replace with last name
.typeText(page.nameInput, 'r', { caretPos: 2 }) // Correct last name
.expect(page.nameInput.value).eql('Parker'); // Check result
});
test('Click an array of labels and then check their states', async t => {
for (const feature of page.featureList) {
await t
.click(feature.label)
.expect(feature.checkbox.checked).ok();
}
});
test('Dealing with text using keyboard', async t => {
await t
.typeText(page.nameInput, 'Peter Parker') // Type name
.click(page.nameInput, { caretPos: 5 }) // Move caret position
.pressKey('backspace') // Erase a character
.expect(page.nameInput.value).eql('Pete Parker') // Check result
.pressKey('home right . delete delete delete') // Pick even shorter form for name
.expect(page.nameInput.value).eql('P. Parker'); // Check result
});
test('Moving the slider', async t => {
const initialOffset = await page.slider.handle.offsetLeft;
await t
.click(page.triedTestCafeCheckbox)
.dragToElement(page.slider.handle, page.slider.tick.withText('9'))
.expect(page.slider.handle.offsetLeft).gt(initialOffset);
});
test('Dealing with text using selection', async t => {
await t
.typeText(page.nameInput, 'Test Cafe')
.selectText(page.nameInput, 7, 1)
.pressKey('delete')
.expect(page.nameInput.value).eql('Tfe'); // Check result
});
test('Handle native confirmation dialog', async t => {
await t
.setNativeDialogHandler(() => true)
.click(page.populateButton);
const dialogHistory = await t.getNativeDialogHistory();
await t.expect(dialogHistory[0].text).eql('Reset information before proceeding?');
await t
.click(page.submitButton)
.expect(page.results.innerText).contains('Peter Parker');
});
test('Pick option from select', async t => {
await t
.click(page.interfaceSelect)
.click(page.interfaceSelectOption.withText('Both'))
.expect(page.interfaceSelect.value).eql('Both');
});
test('Filling a form', async t => {
// Fill some basic fields
await t
.typeText(page.nameInput, 'Bruce Wayne')
.click(page.macOSRadioButton)
.click(page.triedTestCafeCheckbox);
// Let's leave a comment...
await t
.typeText(page.commentsTextArea, "It's...")
.wait(500)
.typeText(page.commentsTextArea, '\ngood');
// I guess, I've changed my mind
await t
.wait(500)
.selectTextAreaContent(page.commentsTextArea, 1, 0)
.pressKey('delete')
.typeText(page.commentsTextArea, 'awesome!!!');
// Let's submit our form
await t
.wait(500)
.click(page.submitButton)
.expect(page.results.innerText).contains('Bruce Wayne');
});