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