-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
41 lines (31 loc) · 901 Bytes
/
index.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
const fs = require('fs');
const sizzleCode = fs.readFileSync(require.resolve('sizzle'));
const getElementBySizzle = eval("(selector) => { \n" + sizzleCode + "\n const elements = Sizzle(selector); return elements[0] }");
function css3Assert(instance) {
const assertElementPresent = async (selector) =>{
try {
const element = await instance.evaluateHandle(
getElementBySizzle,
selector,
);
if (element.asElement()) {
return true
} else {
throw new Error('an element with selector: "'+ selector+ '" not found');
}
} catch (error) {
throw error
}
};
const getElement = async (selector) => {
return await instance.evaluateHandle(
getElementBySizzle,
selector,
);
};
return {
assertElementPresent: assertElementPresent,
getElement: getElement
};
}
module.exports = css3Assert;