-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.js
36 lines (34 loc) · 803 Bytes
/
utils.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
const buildDataAtr = s => `[data-automation-id="${s}"]`;
const dataAutoClick = async (page, s) => {
try {
const divs = await page.$$eval(buildDataAtr(s), divs => {
console.log(`found elements: `, divs);
if (divs[0]) {
divs[0].click();
}
return divs.length;
});
if (divs) {
console.log(`Clicked ${buildDataAtr(s)}`);
}
} catch (e) {
console.log(`Could not find ${buildDataAtr(s)}`, e);
}
};
let logger = () => {};
if (process.env.OUTPUT_LOGS === "true") {
logger = console.log;
}
let screen = () => {};
if (process.env.OUTPUT_SCREENSHOTS === "true") {
screen = async (page, filename) => {
await page.screenshot({
path: `./screenshots/${filename}.png`
});
};
}
module.exports = {
dataAutoClick,
logger,
screen
};