-
Notifications
You must be signed in to change notification settings - Fork 41
/
test.js
129 lines (105 loc) · 3.68 KB
/
test.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
const UI = require('./test/UI');
try {
require('puppeteer')
} catch (e) {
console.warn(`[microdraw]: dependency error: puppeteer needs to be installed manually. - npm i puppeteer`)
process.exit(1)
}
const puppeteer = require('puppeteer');
const delay = (timeout) => {
console.log('delay', timeout, 'milliseconds');
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}
const shadow = (sel) => `document.querySelector("#content").shadowRoot.querySelector("${sel}")`;
const test = async () => {
const browser = await puppeteer.launch({headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
console.log('puppeteer launched');
const page = await browser.newPage();
async function shadowclick(sel) {
const handle = await page.evaluateHandle(shadow(sel));
return handle.click();
}
console.log('browser open');
// capture console
// page.on('console', (msg) => {
// console.log('PAGE LOG:', ...msg.args);
// });
// set viewport
await page.setViewport({width: 1600, height: 1200});
// OPEN HOMEPAGE
console.log('go to home page');
await page.goto('http://localhost:3000');
await delay(2000);
await page.screenshot({path:'test/01.home.png'});
// OPEN DATA
console.log('go to cat');
await page.goto('http://localhost:3000/data?source=/test_data/cat.json&slice=0');
await delay(2000);
await page.screenshot({path:'test/02.cat.png'});
// DELETE TRIANGLE
// select tool
console.log('DELETE TRIANGLE');
await shadowclick(UI.SELECT);
// select triangle
await shadowclick(UI.CANVAS);
await page.mouse.click(450, 250) ;
// delete tool
await shadowclick(UI.DELETE);
await page.screenshot({path:'test/03.cat-delete.png'});
// DRAW SQUARE
// select the polygon tool
await shadowclick(UI.DRAWPOLYGON);
// draw a square A
await page.mouse.click(400, 400) ;
await page.mouse.click(500, 400) ;
await page.mouse.click(500, 500) ;
await page.mouse.click(400, 500) ;
await page.mouse.click(400, 400) ;
await page.screenshot({path:'test/04.cat-square-A.png'}) ;
console.log('draw square A');
// DRAW SQUARE B
// draw a square B
await page.mouse.click(450, 450) ;
await page.mouse.click(550, 450) ;
await page.mouse.click(550, 550) ;
await page.mouse.click(450, 550) ;
await page.mouse.click(450, 450) ;
await page.screenshot({path:'test/05.cat-square-B.png'}) ;
console.log('draw square B');
// UNION OF SQUARES A AND B
// select union tool
await shadowclick(UI.ADDREGION);
// click on square A (square B is already selected)
await page.mouse.click(405, 405) ;
// click on square B (square A is already selected)
await page.mouse.click(540, 540) ;
await page.screenshot({path:'test/06.cat-union.png'}) ;
console.log('union');
// DELETE A+B
// select delete tool
await shadowclick(UI.DELETE);
await page.screenshot({path:'test/07.cat-delete.png'}) ;
console.log('delete');
// DRAW AGAIN THE INITIAL TRIANGLE
// select the polygon tool
await shadowclick(UI.DRAWPOLYGON);
// draw a triangle
await page.mouse.click(400, 200) ;
await page.mouse.click(500, 200) ;
await page.mouse.click(450, 300) ;
await page.mouse.click(400, 200) ;
await page.screenshot({path:'test/08.cat-triangle.png'}) ;
console.log('draw triangle');
// SAVE TO DB
// select the save tool
await shadowclick(UI.SAVE);
await page.screenshot({path:'test/09.cat-save.png'}) ;
console.log('save');
// CLOSE
await browser.close();
console.log('browser closed');
}
test();