forked from rexagod/matcher-core
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
52 lines (42 loc) · 1.22 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
41
42
43
44
45
46
47
48
49
50
51
52
const chromeLauncher = require('chrome-launcher');
const CRI = require('chrome-remote-interface');
const liveServer = require('live-server');
const ejs = require('ejs');
const fs = require('fs');
(async function () {
await chromeLauncher.launch({
port: 9222,
chromeFlags: ['--remote-debugging-port=9222', '--headless'],
});
})();
const XY = global.XY || ['../assets/resources/small.jpg', '../assets/resources/big.jpg'];
liveServer.start({
open: false,
port: 9097
});
ejs.renderFile('./demo/template.html.ejs', {X:XY[0], Y:XY[1]}, function(err, str) {
if(err) console.error(err);
fs.writeFile('./demo/index.html', str, function(err){
if(err) console.error(err);
})
});
CRI((client) => {
const {Page, Runtime} = client;
Promise.all([
Page.enable()
]).then(() => {
return Page.navigate({url: 'http://localhost:9097/demo/index.html'});
});
Page.loadEventFired(() => {
Runtime.evaluate({expression: 'document.getElementById("res").innerHTML'})
.then((result) => {
client.close();
liveServer.shutdown();
console.log(result.result.value);
process.exit();
});
});
})
.on('error', (err) => {
console.error('Cannot connect to browser:', err);
});