Merge "Make wgDisableAnonTalk disable anon links in automatic edit summaries"
[lhc/web/wiklou.git] / tests / selenium / wdio.conf.js
1 const fs = require( 'fs' ),
2 path = require( 'path' ),
3 logPath = process.env.LOG_DIR || path.join( __dirname, '/log' );
4
5 let ffmpeg;
6
7 // get current test title and clean it, to use it as file name
8 function fileName( title ) {
9 return encodeURIComponent( title.replace( /\s+/g, '-' ) );
10 }
11
12 // build file path
13 function filePath( test, screenshotPath, extension ) {
14 return path.join( screenshotPath, `${fileName( test.parent )}-${fileName( test.title )}.${extension}` );
15 }
16
17 // relative path
18 function relPath( foo ) {
19 return path.resolve( __dirname, '../..', foo );
20 }
21
22 exports.config = {
23 // ======
24 // Custom WDIO config specific to MediaWiki
25 // ======
26 // Use in a test as `browser.options.<key>`.
27 // Defaults are for convenience with MediaWiki-Vagrant
28
29 // Wiki admin
30 username: process.env.MEDIAWIKI_USER || 'Admin',
31 password: process.env.MEDIAWIKI_PASSWORD || 'vagrant',
32
33 // Base for browser.url() and Page#openTitle()
34 baseUrl: ( process.env.MW_SERVER || 'http://127.0.0.1:8080' ) + (
35 process.env.MW_SCRIPT_PATH || '/w'
36 ),
37
38 // ======
39 // Sauce Labs
40 // ======
41 // See http://webdriver.io/guide/services/sauce.html
42 // and https://docs.saucelabs.com/reference/platforms-configurator
43 services: [ 'sauce' ],
44 user: process.env.SAUCE_USERNAME,
45 key: process.env.SAUCE_ACCESS_KEY,
46
47 // Default timeout in milliseconds for Selenium Grid requests
48 connectionRetryTimeout: 90 * 1000,
49
50 // Default request retries count
51 connectionRetryCount: 3,
52
53 // ==================
54 // Test Files
55 // ==================
56 specs: [
57 relPath( './tests/selenium/wdio-mediawiki/specs/*.js' ),
58 relPath( './tests/selenium/specs/**/*.js' )
59 ],
60
61 // ============
62 // Capabilities
63 // ============
64
65 // How many instances of the same capability (browser) may be started at the same time.
66 maxInstances: 1,
67
68 capabilities: [ {
69 // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
70 browserName: 'chrome',
71 maxInstances: 1,
72 chromeOptions: {
73 // If DISPLAY is set, assume developer asked non-headless or CI 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 // Chrome sandbox does not work in Docker
79 ...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
80 ]
81 }
82 } ],
83
84 // ===================
85 // Test Configurations
86 // ===================
87
88 // Enabling synchronous mode (via the wdio-sync package), means specs don't have to
89 // use Promise#then() or await for browser commands, such as like `brower.element()`.
90 // Instead, it will automatically pause JavaScript execution until th command finishes.
91 //
92 // For non-browser commands (such as MWBot and other promises), this means you
93 // have to use `browser.call()` to make sure WDIO waits for it before the next
94 // browser command.
95 sync: true,
96
97 // Level of logging verbosity: silent | verbose | command | data | result | error
98 logLevel: 'error',
99
100 // Enables colors for log output.
101 coloredLogs: true,
102
103 // Warns when a deprecated command is used
104 deprecationWarnings: true,
105
106 // Stop the tests once a certain number of failed tests have been recorded.
107 // Default is 0 - don't bail, run all tests.
108 bail: 0,
109
110 // Setting this enables automatic screenshots for when a browser command fails
111 // It is also used by afterTest for capturig failed assertions.
112 // We disable it since we have our screenshot handler in the afterTest hook.
113 screenshotPath: null,
114
115 // Default timeout for each waitFor* command.
116 waitforTimeout: 10 * 1000,
117
118 // Framework you want to run your specs with.
119 // See also: http://webdriver.io/guide/testrunner/frameworks.html
120 framework: 'mocha',
121
122 // Test reporter for stdout.
123 // See also: http://webdriver.io/guide/testrunner/reporters.html
124 reporters: [ 'dot', 'junit' ],
125 reporterOptions: {
126 junit: {
127 outputDir: logPath
128 }
129 },
130
131 // Options to be passed to Mocha.
132 // See the full list at http://mochajs.org/
133 mochaOpts: {
134 ui: 'bdd',
135 timeout: 60 * 1000
136 },
137
138 // =====
139 // Hooks
140 // =====
141 // See also: http://webdriver.io/guide/testrunner/configurationfile.html
142
143 /**
144 * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
145 * @param {Object} test test details
146 */
147 beforeTest: function ( test ) {
148 if ( process.env.DISPLAY && process.env.DISPLAY.startsWith( ':' ) ) {
149 var logBuffer;
150 const videoPath = filePath( test, logPath, 'mp4' );
151 const { spawn } = require( 'child_process' );
152 ffmpeg = spawn( 'ffmpeg', [
153 '-f', 'x11grab', // grab the X11 display
154 '-video_size', '1280x1024', // video size
155 '-i', process.env.DISPLAY, // input file url
156 '-loglevel', 'error', // log only errors
157 '-y', // overwrite output files without asking
158 '-pix_fmt', 'yuv420p', // QuickTime Player support, "Use -pix_fmt yuv420p for compatibility with outdated media players"
159 videoPath // output file
160 ] );
161
162 logBuffer = function ( buffer, prefix ) {
163 const lines = buffer.toString().trim().split( '\n' );
164 lines.forEach( function ( line ) {
165 console.log( prefix + line );
166 } );
167 };
168
169 ffmpeg.stdout.on( 'data', ( data ) => {
170 logBuffer( data, 'ffmpeg stdout: ' );
171 } );
172
173 ffmpeg.stderr.on( 'data', ( data ) => {
174 logBuffer( data, 'ffmpeg stderr: ' );
175 } );
176
177 ffmpeg.on( 'close', ( code, signal ) => {
178 console.log( '\n\tVideo location:', videoPath, '\n' );
179 if ( code !== null ) {
180 console.log( `\tffmpeg exited with code ${code} ${videoPath}` );
181 }
182 if ( signal !== null ) {
183 console.log( `\tffmpeg received signal ${signal} ${videoPath}` );
184 }
185 } );
186 }
187 },
188
189 /**
190 * Save a screenshot when test fails.
191 *
192 * @param {Object} test Mocha Test object
193 */
194 afterTest: function ( test ) {
195 if ( ffmpeg ) {
196 // stop video recording
197 ffmpeg.kill( 'SIGINT' );
198 }
199
200 // if test passed, ignore, else take and save screenshot
201 if ( test.passed ) {
202 return;
203 }
204 // save screenshot
205 const screenshotfile = filePath( test, logPath, 'png' );
206 browser.saveScreenshot( screenshotfile );
207 console.log( '\n\tScreenshot location:', screenshotfile, '\n' );
208 }
209 };