forked from recurly/recurly-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wdio.conf.js
209 lines (179 loc) · 4.29 KB
/
wdio.conf.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
const { spawn } = require('child_process');
const path = require('path');
const {
capabilities: browserStackCapabilities
} = require('./test/conf/browserstack');
const {
API,
API_PROXY,
BROWSER = 'chrome',
BROWSER_VERSION,
DEBUG = false,
PUBLIC_KEY
} = process.env;
exports.config = Object.assign({
runner: 'local',
path: '/',
specs: [
'./test/e2e/**/*.test.js'
],
maxInstances: maxInstances(),
capabilities: capabilities(),
execArgv: execArgv(),
logLevel: 'info',
baseUrl: baseUrl(),
waitforTimeout: Math.round(timeout() * 2/3),
connectionRetryCount: 3,
services: services(),
framework: 'mocha',
reporters: ['spec'],
mochaOpts: {
ui: 'bdd',
timeout: timeout()
},
onPrepare,
before: async () => {
global.testEnvironment = { API, API_PROXY, PUBLIC_KEY };
await browser.setTimeout({
script: timeout(),
// implicit: Math.round(timeout() * 1/3)
});
}
}, assignPort());
exports.isMobile = isMobile;
exports.imageComparisonService = imageComparisonService;
// attributes
function maxInstances () {
if (DEBUG || isMobile()) {
return 1;
} else {
return 5;
}
}
function capabilities () {
if (isIos()) {
return [{
platformName: 'iOS',
browserName: 'Safari',
'appium:deviceName': 'iPhone 11',
'appium:platformVersion': BROWSER_VERSION || '13.6',
'appium:orientation': 'PORTRAIT',
'appium:automationName': 'XCUITest',
}];
}
if (isAndroid()) {
return [{
platformName: 'Android',
browserName: 'Chrome',
'appium:deviceName': 'Android Emulator',
'appium:platformVersion': BROWSER_VERSION || '10.0',
'appium:automationName': 'UIAutomator2',
'appium:chromedriver_autodownload': true
}];
}
return [{
browserName: browserName(),
'goog:chromeOptions': chromeOptions(),
'moz:firefoxOptions': firefoxOptions()
}];
}
function execArgv () {
if (DEBUG) {
return ['--inspect'];
}
return [];
}
function baseUrl () {
if (isAndroid()) return 'http://10.0.2.2:9877';
return 'http://localhost:9877';
}
function timeout () {
if (DEBUG) return 24 * 60 * 60 * 1000;
return 120000;
}
function onPrepare () {
if (isMobile()) {
process.env.API_PROXY = `${baseUrl()}/api-proxy`;
}
require('./test/server');
}
function services () {
const definition = [];
if (browserName() === 'firefox') {
definition.push('geckodriver');
} else if (isMobile()) {
definition.push(['appium', {
logPath : './build/reports/e2e/log/'
}]);
} else {
definition.push('chromedriver');
}
definition.push(imageComparisonService());
return definition;
}
/**
* Configuration options for wdio-image-comparison-service
* @see https://github.com/wswebcreation/webdriver-image-comparison/blob/master/docs/OPTIONS.md#plugin-options
*/
function imageComparisonService () {
const service = [
'image-comparison',
{
baselineFolder: path.resolve(__dirname, './test/e2e/support/snapshots'),
screenshotPath: path.resolve(__dirname, './tmp'),
diffPath: path.resolve(__dirname, './tmp/diff'),
formatImageName: `${BROWSER}/{tag}-{width}x{height}`,
savePerInstance: true,
// Change to true and remove snapshots to generate new baselines
autoSaveBaseline: false,
blockOutStatusBar: true,
blockOutToolBar: true,
}
]
return service;
}
function assignPort () {
if (isMobile() && isLocal()) return { port: 4723 };
}
function browserName () {
if (DEBUG || isElectron() || isAndroid()) return 'chrome';
if (isIos()) return 'safari';
return BROWSER;
}
function chromeOptions () {
if (DEBUG) {
return {
args: ['--auto-open-devtools-for-tabs']
};
}
if (isElectron()) {
return {
binary: path.resolve(__dirname, 'node_modules/.bin/electron')
};
}
return {};
}
function firefoxOptions () {
if (DEBUG) {
return {
args: ['-jsconsole']
};
}
return {};
}
// utilities
function isMobile () {
return isIos() || isAndroid();
}
function isIos () {
return BROWSER.toLowerCase().includes('ios') || BROWSER === 'MobileSafari';
}
function isAndroid () {
return BROWSER.toLowerCase().includes('android');
}
function isElectron () {
return BROWSER.toLowerCase() === 'electron';
}
function isLocal () {
return !browserStackCapabilities[BROWSER];
}