-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
61 lines (48 loc) · 1.51 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
const path = require('path');
const { chromium } = require('playwright');
const start = async () => {
console.log('launch browser ...');
const browser = await chromium.launch({
// headless: false
});
const context = await browser.newContext();
await context.addInitScript({
path: './node_modules/mouse-helper/dist/mouse-helper.js'
});
const page = await context.newPage();
await page.setViewportSize({
width: 350,
height: 100
});
console.log('mock page ...');
await page.setContent(`<html>
<body style="background:#f8f8f8;">
<div>Mouse Helper (move or click your mouse)</div>
</body>
</html>`);
await page.evaluate(() => {
window['mouse-helper']();
});
console.log('take screenshots ...');
console.log('screenshot-none');
const screenshotNonePath = path.resolve(__dirname, '../docs/screenshot-none.png');
await page.screenshot({
path: screenshotNonePath
});
console.log('screenshot-move');
await page.mouse.move(20, 50);
const screenshotMovePath = path.resolve(__dirname, '../docs/screenshot-move.png');
await page.screenshot({
path: screenshotMovePath
});
console.log('screenshot-down');
await page.mouse.down();
const screenshotDownPath = path.resolve(__dirname, '../docs/screenshot-down.png');
await page.screenshot({
path: screenshotDownPath
});
await page.mouse.up();
await browser.close();
console.log('closed');
};
start();