-
Notifications
You must be signed in to change notification settings - Fork 2
/
Common.js
46 lines (43 loc) · 1.1 KB
/
Common.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
const {page} = require("../main");
class Common
{
constructor(selector)
{
this._selector = selector;
}
async _getHandle()
{
return page().$(this._selector);
}
async _getShadowRoot()
{
const handle = await this._getHandle();
return handle.evaluateHandle((component) => component.shadowRoot);
}
async _getHandleTextContent(handle)
{
return await (await handle.getProperty("textContent")).jsonValue();
}
async _executeMethod()
{
const handle = await this._getHandle();
return handle.evaluate((component, methodName, ...args) => component[methodName](...args), ...arguments)
}
async _triggerEvent(handle, eventName, eventData = {})
{
return handle.evaluate((elem, eventName, eventData) =>
{
return new Promise((resolve) =>
{
elem.addEventListener(eventName, (e) =>
{
resolve(e);
});
const data = {bubbles: true};
const event = new DragEvent(eventName, Object.assign(data, eventData));
elem.dispatchEvent(event);
});
}, eventName, eventData);
}
}
module.exports = {Common};