-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (36 loc) · 1.3 KB
/
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 puppeteer = require('puppeteer');
const path = require('path');
const fs = require('fs');
const config = require('./config.json');
const sites = require('./credentials.json');
const directory = path.resolve(__dirname, './');
const imagesDirectory = path.join(directory, 'images');
fs.readdir(imagesDirectory, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(imagesDirectory, file), err => {
if (err) throw err;
});
}
});
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
for (site in sites) {
console.log(`Opening ${config[site].name}`);
await page.goto(config[site].url);
for (step of config[site].steps) {
if (step.action === 'type') {
await page[step.action](step.selector, sites[site][step.field]);
} else if (step.action === 'click') {
await Promise.all([
page.waitForNavigation(),
page[step.action](step.selector)
]);
}
await page.waitFor(2);
}
await page.screenshot({path: path.join(directory, `images/${config[site].name}.png`)});
}
await browser.close();
})();