-
Notifications
You must be signed in to change notification settings - Fork 0
/
backstop-automator.js
executable file
·88 lines (82 loc) · 2.07 KB
/
backstop-automator.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
#!/usr/bin/env node
const Sitemapper = require('sitemapper');
const argv = require('minimist')(process.argv.slice(2));
const backstop = require('backstopjs');
const onReady = require('./backstopScripts/onReady')
const executePath = process.cwd();
const libPath = process.mainModule.path;
console.log(__dirname);
const scenarios = [];
const backstopConfig = {
id: argv.url,
scenarios,
viewports: [
{
label: "desktop",
width: 1920,
height: 1080
}
],
paths: {
bitmaps_reference: `./backstop_${argv.projectname}/bitmaps_reference`,
bitmaps_test: `./backstop_${argv.projectname}/bitmaps_test`,
engine_scripts: `${__dirname}/backstopScripts`,
html_report: `./backstop_${argv.projectname}/html_report`,
ci_report: `./backstop_${argv.projectname}/ci_report`
},
report: [
"browser"
],
engine: "puppeteer",
engineOptions: {
args: [
"--no-sandbox"
]
},
asyncCaptureLimit: 5,
asyncCompareLimit: 50,
delay: 1000,
debug: false,
debugWindow: false,
onReadyScript: 'onReady.js'
};
const sitemapFetcher = async (url) => {
const WebPage = new Sitemapper({
url: `${url}/sitemap.xml`,
timeout: 15000, // 15 seconds
});
try {
const {sites} = await WebPage.fetch();
return sites
} catch (error) {
console.log(error);
}
};
if (argv.url && argv.projectname && argv.reference && argv.run){
sitemapFetcher(argv.url).then(sites => {
sites.map(url => {
scenarios.push({
"label": url,
"url": url,
"misMatchThreshold": 2,
delay: 1000,
"selectors": [
"document"
],
"hideSelectors": [
"iframe"
]
})
})
console.log(scenarios);
backstop(argv.run, {config: backstopConfig})
.then(() => {
console.log('backstop successful');
}).catch(() => {
console.log('backstop failed');
});
});
} else {
console.log('No Domain given, please use:');
console.log('autoback --run=reference --projectname=projectname --url=https://projectname.local/ --reference=https://projectname.de/');
}