forked from getgauge/taiko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate.test.js
106 lines (97 loc) · 3.04 KB
/
evaluate.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
const { createHtml, openBrowserArgs, removeFile, resetConfig } = require('./test-util');
const { openBrowser, goto, evaluate, text, closeBrowser, setConfig } = require('../../lib/taiko');
const expect = require('chai').expect;
const testName = 'Evaluate';
describe(testName, () => {
let filePath;
before(async () => {
let innerHtml = `<section class="header">
<h1>${testName} tests</h1>
</section>
<section class='main-content'>
<div class='item'>
Item 1
</div>
<div class='item'>
Item 2
</div>
</section>
`;
filePath = createHtml(innerHtml, testName);
await openBrowser(openBrowserArgs);
await goto(filePath);
setConfig({
waitForNavigation: false,
retryTimeout: 10,
retryInterval: 10,
});
});
after(async () => {
resetConfig();
await closeBrowser();
removeFile(filePath);
});
describe('with selector', () => {
it('should return the result on the evaluation', async () => {
let expected = 'Item 1';
let actual = await evaluate(text('Item 1'), (element) => {
return element.textContent.trim();
});
expect(actual).to.be.equal(expected);
});
it('should pass args to the callback', async () => {
let expected = 'Updated Item 1 with new item';
await evaluate(
text('Item 1'),
(element, args) => {
element.textContent = args[0];
},
{ args: [expected] },
);
let actual = await text(expected).exists();
expect(actual).to.be.true;
});
});
describe('without selector', () => {
it('should pass root html element to the function to be evaluated', async () => {
const actual = await evaluate((rootElement) => {
return rootElement.outerHTML;
});
expect(actual).to.match(/^<html>/);
expect(actual).to.match(/<\/html>$/);
});
it('should pass args to the callback', async () => {
let newText = 'Updated Item 1 with new item';
await evaluate(
(element, args) => {
document.body.innerHTML = args[0];
},
{ args: [newText] },
);
expect(await text('Item 2').exists()).to.be.false;
});
it('should return the result of the evaluation', async () => {
const actual = await evaluate(() => {
return document.title;
});
expect(actual).to.equal(testName);
});
it('should return the result of evaluation with async function', async () => {
const actual = await evaluate(async () => {
return document.title;
});
expect(actual).to.equal(testName);
});
it('should pass args to the callback', async () => {
let newText = 'Updated Item 1 with new item';
await evaluate(
(element, args) => {
element.innerHTML = args[0];
},
{ args: [newText] },
);
let actual = await text('Item 2').exists();
expect(actual).to.be.false;
});
});
});