forked from r03ert0/microdraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
116 lines (95 loc) · 4.29 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
'use strict';
const UI = require('./test/UI');
const puppeteer = require('puppeteer');
function delay(timeout) {
console.log('delay', timeout, 'milliseconds');
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}
puppeteer.launch({headless: false, args: ['--no-sandbox', '--disable-setuid-sandbox'] })
.then(function(browser) {
console.log('puppeteer launched');
browser.newPage()
.then(function(page) {
console.log('browser open');
// capture console
// page.on('console', (msg) => {
// console.log('PAGE LOG:', ...msg.args);
// });
// set viewport
page.setViewport({width: 1600, height: 1200})
// OPEN HOMEPAGE
.then(() => console.log('go to home page'))
.then(() => page.goto('http://localhost:3000'))
.then(() => delay(2000))
.then(() => page.screenshot({path:'test/01.home.png'}))
// OPEN DATA
.then(() => console.log('go to cat'))
.then(() => page.goto('http://localhost:3000/data?source=/test_data/cat.json'))
.then(() => delay(2000))
.then(() => page.screenshot({path:'test/02.cat.png'}))
// DELETE TRIANGLE
// select tool
.then(() => console.log('DELETE TRIANGLE'))
.then(() => page.click(UI.SELECT))
// select triangle
.then(() => page.click(UI.CANVAS))
// delete tool
.then(() => page.click(UI.DELETE))
.then(() => page.screenshot({path:'test/03.cat-delete.png'}))
// DRAW SQUARE
// select the polygon tool
.then(() => page.click(UI.DRAWPOLYGON))
// draw a square A
.then(() => page.mouse.click(400, 400) )
.then(() => page.mouse.click(500, 400) )
.then(() => page.mouse.click(500, 500) )
.then(() => page.mouse.click(400, 500) )
.then(() => page.mouse.click(400, 400) )
.then(() => page.screenshot({path:'test/04.cat-square-A.png'}) )
.then(function() { console.log('draw square A'); })
// DRAW SQUARE B
// draw a square B
.then(() => page.mouse.click(450, 450) )
.then(() => page.mouse.click(550, 450) )
.then(() => page.mouse.click(550, 550) )
.then(() => page.mouse.click(450, 550) )
.then(() => page.mouse.click(450, 450) )
.then(() => page.screenshot({path:'test/05.cat-square-B.png'}) )
.then(function() { console.log('draw square B'); })
// UNION OF SQUARES A AND B
// select union tool
.then(() => page.click(UI.ADDREGION))
// click on square A (square B is already selected)
.then(() => page.mouse.click(405, 405) )
// click on square B (square A is already selected)
.then(() => page.mouse.click(540, 540) )
.then(() => page.screenshot({path:'test/06.cat-union.png'}) )
.then(function() { console.log('union'); })
// DELETE A+B
// select delete tool
.then(() => page.click(UI.DELETE))
.then(() => page.screenshot({path:'test/07.cat-delete.png'}) )
.then(function() { console.log('delete'); })
// DRAW AGAIN THE INITIAL TRIANGLE
// select the polygon tool
.then(() => page.click(UI.DRAWPOLYGON))
// draw a triangle
.then(() => page.mouse.click(400, 200) )
.then(() => page.mouse.click(500, 200) )
.then(() => page.mouse.click(450, 300) )
.then(() => page.mouse.click(400, 200) )
.then(() => page.screenshot({path:'test/08.cat-triangle.png'}) )
.then(function() { console.log('draw triangle'); })
// SAVE TO DB
// select the save tool
.then(() => page.click(UI.SAVE))
.then(() => page.screenshot({path:'test/09.cat-save.png'}) )
.then(function() { console.log('save'); })
// CLOSE
.then(() => browser.close())
.then(function() { console.log('browser closed'); })
.catch(e => console.log('puppeteer error', e));
});
});