forked from PrincetonUniversity/PsyNeuLinkView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-memory.js
42 lines (34 loc) · 1.47 KB
/
test-memory.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
// initial page load url: Google Maps
function url() {
return 'http://localhost:3000/';
}
const elementSelector = '#root > div > div.jss10 > div.jss12.MuiBox-root.css-0 > div.jss16.MuiBox-root.css-0 > div > div > div:nth-child(2) > div > div > div:nth-child(2) > div:nth-child(2)';
const dragAmount = 200;
const repetitions = 7;
async function dragLeft(page) {
const draggableElement = await page.$(elementSelector);
const boundingBox = await draggableElement.boundingBox();
const targetX = boundingBox.x - dragAmount;
await page.mouse.move(boundingBox.x + boundingBox.width / 2, boundingBox.y + boundingBox.height / 2);
await page.mouse.down();
await page.mouse.move(targetX, boundingBox.y + boundingBox.height / 2);
await page.mouse.up();
}
async function dragRight(page) {
const draggableElement = await page.$(elementSelector);
const boundingBox = await draggableElement.boundingBox();
const targetX = boundingBox.x + boundingBox.width + dragAmount;
await page.mouse.move(boundingBox.x + boundingBox.width / 2, boundingBox.y + boundingBox.height / 2);
await page.mouse.down();
await page.mouse.move(targetX, boundingBox.y + boundingBox.height / 2);
await page.mouse.up();
}
async function action(page) {
for(let i = 0; i < repetitions; i++) {
await dragLeft(page);
await page.waitForTimeout(1000);
await dragRight(page);
await page.waitForTimeout(1000);
}
}
module.exports = {action, url};