selenium: Create local ./log directory if needed
[lhc/web/wiklou.git] / tests / selenium / wdio.conf.js
1 const fs = require( 'fs' ),
2 path = require( 'path' ),
3 logPath = process.env.LOG_DIR || __dirname + '/log';
4
5 function relPath( foo ) {
6 return path.resolve( __dirname, '../..', foo );
7 }
8
9 exports.config = {
10 // ======
11 // Custom WDIO config specific to MediaWiki
12 // ======
13 // Use in a test as `browser.options.<key>`.
14
15 // Configure wiki admin user/pass via env
16 // Defaults are for convenience with MediaWiki-Vagrant
17 username: process.env.MEDIAWIKI_USER || 'Admin',
18 password: process.env.MEDIAWIKI_PASSWORD || 'vagrant',
19
20 // ======
21 // Sauce Labs
22 // ======
23 services: [ 'sauce' ],
24 user: process.env.SAUCE_USERNAME,
25 key: process.env.SAUCE_ACCESS_KEY,
26
27 // ==================
28 // Specify Test Files
29 // ==================
30 // Define which test specs should run. The pattern is relative to the directory
31 // from which `wdio` was called. Notice that, if you are calling `wdio` from an
32 // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
33 // directory is where your package.json resides, so `wdio` will be called from there.
34 specs: [
35 relPath( './tests/selenium/specs/**/*.js' ),
36 relPath( './extensions/*/tests/selenium/specs/**/*.js' ),
37 relPath( './extensions/VisualEditor/modules/ve-mw/tests/selenium/specs/**/*.js' ),
38 relPath( './skins/*/tests/selenium/specs/**/*.js' )
39 ],
40 // Patterns to exclude.
41 exclude: [
42 relPath( './extensions/CirrusSearch/tests/selenium/specs/**/*.js' )
43 ],
44
45 // ============
46 // Capabilities
47 // ============
48 // Define your capabilities here. WebdriverIO can run multiple capabilities at the same
49 // time. Depending on the number of capabilities, WebdriverIO launches several test
50 // sessions. Within your capabilities you can overwrite the spec and exclude options in
51 // order to group specific specs to a specific capability.
52
53 // First, you can define how many instances should be started at the same time. Let's
54 // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
55 // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
56 // files and you set maxInstances to 10, all spec files will get tested at the same time
57 // and 30 processes will get spawned. The property handles how many capabilities
58 // from the same test should run tests.
59 maxInstances: 1,
60
61 // If you have trouble getting all important capabilities together, check out the
62 // Sauce Labs platform configurator - a great tool to configure your capabilities:
63 // https://docs.saucelabs.com/reference/platforms-configurator
64 //
65 // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
66 capabilities: [ {
67 // maxInstances can get overwritten per capability. So if you have an in-house Selenium
68 // grid with only 5 firefox instances available you can make sure that not more than
69 // 5 instances get started at a time.
70 maxInstances: 1,
71 browserName: 'chrome',
72 chromeOptions: {
73 // If DISPLAY is set, assume running from developer machine and/or with Xvfb.
74 // Otherwise, use --headless (added in Chrome 59)
75 // https://chromium.googlesource.com/chromium/src/+/59.0.3030.0/headless/README.md
76 args: (
77 process.env.DISPLAY ? [] : [ '--headless' ]
78 ).concat(
79 // Chrome sandbox does not work in Docker
80 fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : []
81 )
82 }
83 } ],
84
85 // ===================
86 // Test Configurations
87 // ===================
88 // Define all options that are relevant for the WebdriverIO instance here
89 //
90 // By default WebdriverIO commands are executed in a synchronous way using
91 // the wdio-sync package. If you still want to run your tests in an async way
92 // e.g. using promises you can set the sync option to false.
93 sync: true,
94
95 // Level of logging verbosity: silent | verbose | command | data | result | error
96 logLevel: 'error',
97
98 // Enables colors for log output.
99 coloredLogs: true,
100
101 // Warns when a deprecated command is used
102 deprecationWarnings: true,
103
104 // If you only want to run your tests until a specific amount of tests have failed use
105 // bail (default is 0 - don't bail, run all tests).
106 bail: 0,
107
108 // Saves a screenshot to a given path if a command fails.
109 screenshotPath: logPath,
110
111 // Set a base URL in order to shorten url command calls. If your `url` parameter starts
112 // with `/`, the base url gets prepended, not including the path portion of your baseUrl.
113 // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
114 // gets prepended directly.
115 baseUrl: (
116 process.env.MW_SERVER || 'http://127.0.0.1:8080'
117 ) + (
118 process.env.MW_SCRIPT_PATH || '/w'
119 ),
120
121 // Default timeout for all waitFor* commands.
122 waitforTimeout: 10000,
123
124 // Default timeout in milliseconds for request
125 // if Selenium Grid doesn't send response
126 connectionRetryTimeout: 90000,
127
128 // Default request retries count
129 connectionRetryCount: 3,
130
131 // Initialize the browser instance with a WebdriverIO plugin. The object should have the
132 // plugin name as key and the desired plugin options as properties. Make sure you have
133 // the plugin installed before running any tests. The following plugins are currently
134 // available:
135 // WebdriverCSS: https://github.com/webdriverio/webdrivercss
136 // WebdriverRTC: https://github.com/webdriverio/webdriverrtc
137 // Browserevent: https://github.com/webdriverio/browserevent
138 // plugins: {
139 // webdrivercss: {
140 // screenshotRoot: 'my-shots',
141 // failedComparisonsRoot: 'diffs',
142 // misMatchTolerance: 0.05,
143 // screenWidth: [320,480,640,1024]
144 // },
145 // webdriverrtc: {},
146 // browserevent: {}
147 // },
148 //
149 // Test runner services
150 // Services take over a specific job you don't want to take care of. They enhance
151 // your test setup with almost no effort. Unlike plugins, they don't add new
152 // commands. Instead, they hook themselves up into the test process.
153 // services: [],//
154 // Framework you want to run your specs with.
155 // The following are supported: Mocha, Jasmine, and Cucumber
156 // see also: http://webdriver.io/guide/testrunner/frameworks.html
157 //
158 // Make sure you have the wdio adapter package for the specific framework installed
159 // before running any tests.
160 framework: 'mocha',
161
162 // Test reporter for stdout.
163 // The only one supported by default is 'dot'
164 // see also: http://webdriver.io/guide/testrunner/reporters.html
165 reporters: [ 'spec', 'junit' ],
166 reporterOptions: {
167 junit: {
168 outputDir: logPath
169 }
170 },
171
172 // Options to be passed to Mocha.
173 // See the full list at http://mochajs.org/
174 mochaOpts: {
175 ui: 'bdd',
176 timeout: 60000
177 },
178
179 // =====
180 // Hooks
181 // =====
182 // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
183 // it and to build services around it. You can either apply a single function or an array of
184 // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
185 // resolved to continue.
186
187 /**
188 * Gets executed once before all workers get launched.
189 * @param {Object} config wdio configuration object
190 * @param {Array.<Object>} capabilities list of capabilities details
191 */
192 // onPrepare: function (config, capabilities) {
193 // },
194
195 /**
196 * Gets executed just before initialising the webdriver session and test framework. It allows you
197 * to manipulate configurations depending on the capability or spec.
198 * @param {Object} config wdio configuration object
199 * @param {Array.<Object>} capabilities list of capabilities details
200 * @param {Array.<String>} specs List of spec file paths that are to be run
201 */
202 // beforeSession: function (config, capabilities, specs) {
203 // },
204
205 /**
206 * Gets executed before test execution begins. At this point you can access to all global
207 * variables like `browser`. It is the perfect place to define custom commands.
208 * @param {Array.<Object>} capabilities list of capabilities details
209 * @param {Array.<String>} specs List of spec file paths that are to be run
210 */
211 // before: function (capabilities, specs) {
212 // },
213
214 /**
215 * Runs before a WebdriverIO command gets executed.
216 * @param {String} commandName hook command name
217 * @param {Array} args arguments that command would receive
218 */
219 // beforeCommand: function (commandName, args) {
220 // },
221
222 /**
223 * Hook that gets executed before the suite starts
224 * @param {Object} suite suite details
225 */
226 // beforeSuite: function (suite) {
227 // },
228
229 /**
230 * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
231 * @param {Object} test test details
232 */
233 // beforeTest: function (test) {
234 // },
235
236 /**
237 * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
238 * beforeEach in Mocha)
239 */
240 // beforeHook: function () {
241 // },
242
243 /**
244 * Hook that gets executed _after_ a hook within the suite ends (e.g. runs after calling
245 * afterEach in Mocha)
246 */
247 // afterHook: function () {
248 // },
249 /**
250 * Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) ends.
251 * @param {Object} test test details
252 */
253 // from https://github.com/webdriverio/webdriverio/issues/269#issuecomment-306342170
254 afterTest: function ( test ) {
255 var filename, filePath;
256 // if test passed, ignore, else take and save screenshot
257 if ( test.passed ) {
258 return;
259 }
260 // Create sane file name for current test title
261 filename = encodeURIComponent( test.title.replace( /\s+/g, '-' ) );
262 filePath = `${browser.options.screenshotPath}/${filename}.png`;
263 // Ensure directory exists, based on WebDriverIO#saveScreenshotSync()
264 try {
265 fs.statSync( browser.options.screenshotPath );
266 } catch ( err ) {
267 fs.mkdirSync( browser.options.screenshotPath );
268 }
269 // Create and save screenshot
270 browser.saveScreenshot( filePath );
271 console.log( '\n\tScreenshot location:', filePath, '\n' );
272 }
273
274 /**
275 * Hook that gets executed after the suite has ended
276 * @param {Object} suite suite details
277 */
278 // afterSuite: function (suite) {
279 // },
280
281 /**
282 * Runs after a WebdriverIO command gets executed
283 * @param {String} commandName hook command name
284 * @param {Array} args arguments that command would receive
285 * @param {Number} result 0 - command success, 1 - command error
286 * @param {Object} error error object if any
287 */
288 // afterCommand: function (commandName, args, result, error) {
289 // },
290
291 /**
292 * Gets executed after all tests are done. You still have access to all global variables from
293 * the test.
294 * @param {Number} result 0 - test pass, 1 - test fail
295 * @param {Array.<Object>} capabilities list of capabilities details
296 * @param {Array.<String>} specs List of spec file paths that ran
297 */
298 // after: function (result, capabilities, specs) {
299 // },
300
301 /**
302 * Gets executed right after terminating the webdriver session.
303 * @param {Object} config wdio configuration object
304 * @param {Array.<Object>} capabilities list of capabilities details
305 * @param {Array.<String>} specs List of spec file paths that ran
306 */
307 // afterSession: function (config, capabilities, specs) {
308 // },
309
310 /**
311 * Gets executed after all workers got shut down and the process is about to exit.
312 * @param {Object} exitCode 0 - success, 1 - fail
313 * @param {Object} config wdio configuration object
314 * @param {Array.<Object>} capabilities list of capabilities details
315 */
316 // onComplete: function(exitCode, config, capabilities) {
317 // }
318 };