selenium: Initial version of wdio-mediawiki package
[lhc/web/wiklou.git] / tests / selenium / wdio.conf.js
1 const fs = require( 'fs' ),
2 path = require( 'path' ),
3 saveScreenshot = require( 'wdio-mediawiki' ).saveScreenshot,
4 logPath = process.env.LOG_DIR || __dirname + '/log';
5
6 function relPath( foo ) {
7 return path.resolve( __dirname, '../..', foo );
8 }
9
10 exports.config = {
11 // ======
12 // Custom WDIO config specific to MediaWiki
13 // ======
14 // Use in a test as `browser.options.<key>`.
15 // Defaults are for convenience with MediaWiki-Vagrant
16
17 // Wiki admin
18 username: process.env.MEDIAWIKI_USER || 'Admin',
19 password: process.env.MEDIAWIKI_PASSWORD || 'vagrant',
20
21 // Base for browser.url() and Page#openTitle()
22 baseUrl: ( process.env.MW_SERVER || 'http://127.0.0.1:8080' ) + (
23 process.env.MW_SCRIPT_PATH || '/w'
24 ),
25
26 // ======
27 // Sauce Labs
28 // ======
29 // See http://webdriver.io/guide/services/sauce.html
30 // and https://docs.saucelabs.com/reference/platforms-configurator
31 services: [ 'sauce' ],
32 user: process.env.SAUCE_USERNAME,
33 key: process.env.SAUCE_ACCESS_KEY,
34
35 // Default timeout in milliseconds for Selenium Grid requests
36 connectionRetryTimeout: 90 * 1000,
37
38 // Default request retries count
39 connectionRetryCount: 3,
40
41 // ==================
42 // Test Files
43 // ==================
44 specs: [
45 relPath( './tests/selenium/wdio-mediawiki/specs/*.js' ),
46 relPath( './tests/selenium/specs/**/*.js' ),
47 relPath( './extensions/*/tests/selenium/specs/**/*.js' ),
48 relPath( './extensions/VisualEditor/modules/ve-mw/tests/selenium/specs/**/*.js' ),
49 relPath( './skins/*/tests/selenium/specs/**/*.js' )
50 ],
51 // Patterns to exclude
52 exclude: [
53 relPath( './extensions/CirrusSearch/tests/selenium/specs/**/*.js' )
54 ],
55
56 // ============
57 // Capabilities
58 // ============
59
60 // How many instances of the same capability (browser) may be started at the same time.
61 maxInstances: 1,
62
63 capabilities: [ {
64 // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
65 browserName: 'chrome',
66 maxInstances: 1,
67 chromeOptions: {
68 // If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
69 // Otherwise, use --headless (added in Chrome 59)
70 // https://chromium.googlesource.com/chromium/src/+/59.0.3030.0/headless/README.md
71 args: [
72 ...( process.env.DISPLAY ? [] : [ '--headless' ] ),
73 // Chrome sandbox does not work in Docker
74 ...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
75 ]
76 }
77 } ],
78
79 // ===================
80 // Test Configurations
81 // ===================
82
83 // Enabling synchronous mode (via the wdio-sync package), means specs don't have to
84 // use Promise#then() or await for browser commands, such as like `brower.element()`.
85 // Instead, it will automatically pause JavaScript execution until th command finishes.
86 //
87 // For non-browser commands (such as MWBot and other promises), this means you
88 // have to use `browser.call()` to make sure WDIO waits for it before the next
89 // browser command.
90 sync: true,
91
92 // Level of logging verbosity: silent | verbose | command | data | result | error
93 logLevel: 'error',
94
95 // Enables colors for log output.
96 coloredLogs: true,
97
98 // Warns when a deprecated command is used
99 deprecationWarnings: true,
100
101 // Stop the tests once a certain number of failed tests have been recorded.
102 // Default is 0 - don't bail, run all tests.
103 bail: 0,
104
105 // Setting this enables automatic screenshots for when a browser command fails
106 // It is also used by afterTest for capturig failed assertions.
107 screenshotPath: logPath,
108
109 // Default timeout for each waitFor* command.
110 waitforTimeout: 10 * 1000,
111
112 // Framework you want to run your specs with.
113 // See also: http://webdriver.io/guide/testrunner/frameworks.html
114 framework: 'mocha',
115
116 // Test reporter for stdout.
117 // See also: http://webdriver.io/guide/testrunner/reporters.html
118 reporters: [ 'spec', 'junit' ],
119 reporterOptions: {
120 junit: {
121 outputDir: logPath
122 }
123 },
124
125 // Options to be passed to Mocha.
126 // See the full list at http://mochajs.org/
127 mochaOpts: {
128 ui: 'bdd',
129 timeout: 60 * 1000
130 },
131
132 // =====
133 // Hooks
134 // =====
135 // See also: http://webdriver.io/guide/testrunner/configurationfile.html
136
137 /**
138 * Save a screenshot when test fails.
139 *
140 * @param {Object} test Mocha Test object
141 */
142 afterTest: function ( test ) {
143 var filePath;
144 if ( !test.passed ) {
145 filePath = saveScreenshot( test.title );
146 console.log( '\n\tScreenshot: ' + filePath + '\n' );
147 }
148 }
149 };