-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (42 loc) · 1010 Bytes
/
index.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
'use strict';
// @ts-ignore
const { WebDriver } = require('webdriver');
/**
* @typedef {import('@mochify/mochify').MochifyDriver} MochifyDriver
*/
exports.mochifyDriver = mochifyDriver;
const default_url = `file:${__dirname}/index.html`;
/**
* @param {Object} [options]
* @returns {Promise<MochifyDriver>}
*/
async function mochifyDriver(options = {}) {
const { url } = options;
delete options.url;
const client = await WebDriver.newSession(
Object.assign(
{
logLevel: 'warn',
hostname: 'localhost',
path: '/wd/hub',
port: 4444,
capabilities: {
browserName: 'firefox'
}
},
options
)
);
await client.navigateTo(url || default_url);
return {
evaluate: (script) =>
client.executeAsyncScript(
`
var __mochify_return_value = ${script};
arguments[arguments.length - 1](__mochify_return_value)
`,
[]
),
end: () => client.deleteSession()
};
}