-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (75 loc) · 2 KB
/
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
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
const Nightwatch = require('nightwatch');
const NodeEnvironment = require('jest-environment-node');
const createNightwatchClient = function({
headless = true,
browserName = undefined,
silent = true,
verbose = false,
output = true,
env = null,
parallel = false,
devtools = false,
debug = false,
persistGlobals = true,
configFile = './nightwatch.conf.js',
globals = {},
webdriver = {},
timeout = null,
enableGlobalApis = false,
reporter = null,
alwaysAsync = true,
desiredCapabilities = {}
} = {}) {
const client = Nightwatch.createClient({
headless,
browserName,
reporter,
env,
timeout,
parallel,
output,
devtools,
debug,
enable_global_apis: enableGlobalApis,
silent: silent && !verbose,
always_async_commands: alwaysAsync,
test_runner: {
type: 'jest'
},
webdriver,
persist_globals: persistGlobals,
config: configFile,
globals,
desiredCapabilities
});
client.updateCapabilities(desiredCapabilities);
return client;
};
class NightwatchEnvironment extends NodeEnvironment {
constructor(config = {}, context) {
super(config, context);
this.opts = config.testEnvironmentOptions || {};
this.client = createNightwatchClient(this.opts);
this.global.jestNightwatch = this.client;
}
async setup() {
this.opts.autoStartSession = this.opts.autoStartSession || typeof this.opts.autoStartSession == 'undefined';
// autoStartSession is true by default
if (this.opts.autoStartSession) {
this.global.browser = await this.client.launchBrowser();
}
if (this.opts.baseUrl) {
this.global.browser.baseUrl = this.opts.baseUrl;
}
if (typeof this.opts.setup == 'function') {
await this.opts.setup.call(this.global, this.global.browser);
}
}
async teardown() {
await super.teardown();
if (typeof this.opts.teardown == 'function') {
await this.opts.teardown.call(this.global, this.global.browser);
}
}
}
module.exports = NightwatchEnvironment;