selenium: Temporarily drop all tests and wdio-mocha-framework
[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 // FIXME: The non-core patterns to be removed once T199116 is fixed.
56 // ==================
57 specs: [
58 // T222406: Temporarily disabling all selenium tests for node6->10 CI migration
59 // relPath( './tests/selenium/wdio-mediawiki/specs/*.js' ),
60 // relPath( './tests/selenium/specs/**/*.js' ),
61 // relPath( './extensions/*/tests/selenium/specs/**/*.js' ),
62 // relPath( './extensions/VisualEditor/modules/ve-mw/tests/selenium/specs/**/*.js' ),
63 // relPath( './extensions/Wikibase/repo/tests/selenium/specs/**/*.js' ),
64 // relPath( './skins/*/tests/selenium/specs/**/*.js' )
65 ],
66 // Patterns to exclude
67 exclude: [
68 relPath( './extensions/CirrusSearch/tests/selenium/specs/**/*.js' ),
69 // Disabled because these tests modify LocalSettings.php, see T199116 for the long-term fix.
70 relPath( './extensions/FileImporter/tests/selenium/specs/**/*.js' ),
71 // Disabled per T222517
72 relPath( './skins/MinervaNeue/tests/selenium/specs/**/*.js' )
73 ],
74
75 // ============
76 // Capabilities
77 // ============
78
79 // How many instances of the same capability (browser) may be started at the same time.
80 maxInstances: 1,
81
82 capabilities: [ {
83 // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
84 browserName: 'chrome',
85 maxInstances: 1,
86 chromeOptions: {
87 // If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
88 // Otherwise, use --headless (added in Chrome 59)
89 // https://chromium.googlesource.com/chromium/src/+/59.0.3030.0/headless/README.md
90 args: [
91 ...( process.env.DISPLAY ? [] : [ '--headless' ] ),
92 // Chrome sandbox does not work in Docker
93 ...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
94 ]
95 }
96 } ],
97
98 // ===================
99 // Test Configurations
100 // ===================
101
102 // Enabling synchronous mode (via the wdio-sync package), means specs don't have to
103 // use Promise#then() or await for browser commands, such as like `brower.element()`.
104 // Instead, it will automatically pause JavaScript execution until th command finishes.
105 //
106 // For non-browser commands (such as MWBot and other promises), this means you
107 // have to use `browser.call()` to make sure WDIO waits for it before the next
108 // browser command.
109 sync: true,
110
111 // Level of logging verbosity: silent | verbose | command | data | result | error
112 logLevel: 'error',
113
114 // Enables colors for log output.
115 coloredLogs: true,
116
117 // Warns when a deprecated command is used
118 deprecationWarnings: true,
119
120 // Stop the tests once a certain number of failed tests have been recorded.
121 // Default is 0 - don't bail, run all tests.
122 bail: 0,
123
124 // Setting this enables automatic screenshots for when a browser command fails
125 // It is also used by afterTest for capturig failed assertions.
126 // We disable it since we have our screenshot handler in the afterTest hook.
127 screenshotPath: null,
128
129 // Default timeout for each waitFor* command.
130 waitforTimeout: 10 * 1000,
131
132 // Framework you want to run your specs with.
133 // See also: http://webdriver.io/guide/testrunner/frameworks.html
134 framework: 'mocha',
135
136 // Test reporter for stdout.
137 // See also: http://webdriver.io/guide/testrunner/reporters.html
138 reporters: [ 'spec', 'junit' ],
139 reporterOptions: {
140 junit: {
141 outputDir: logPath
142 }
143 },
144
145 // Options to be passed to Mocha.
146 // See the full list at http://mochajs.org/
147 mochaOpts: {
148 ui: 'bdd',
149 timeout: 60 * 1000
150 },
151
152 // =====
153 // Hooks
154 // =====
155 // See also: http://webdriver.io/guide/testrunner/configurationfile.html
156
157 /**
158 * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
159 * @param {Object} test test details
160 */
161 beforeTest: function ( test ) {
162 if ( process.env.DISPLAY && process.env.DISPLAY.startsWith( ':' ) ) {
163 var logBuffer;
164 let videoPath = filePath( test, logPath, 'mp4' );
165 const { spawn } = require( 'child_process' );
166 ffmpeg = spawn( 'ffmpeg', [
167 '-f', 'x11grab', // grab the X11 display
168 '-video_size', '1280x1024', // video size
169 '-i', process.env.DISPLAY, // input file url
170 '-loglevel', 'error', // log only errors
171 '-y', // overwrite output files without asking
172 '-pix_fmt', 'yuv420p', // QuickTime Player support, "Use -pix_fmt yuv420p for compatibility with outdated media players"
173 videoPath // output file
174 ] );
175
176 logBuffer = function ( buffer, prefix ) {
177 let lines = buffer.toString().trim().split( '\n' );
178 lines.forEach( function ( line ) {
179 console.log( prefix + line );
180 } );
181 };
182
183 ffmpeg.stdout.on( 'data', ( data ) => {
184 logBuffer( data, 'ffmpeg stdout: ' );
185 } );
186
187 ffmpeg.stderr.on( 'data', ( data ) => {
188 logBuffer( data, 'ffmpeg stderr: ' );
189 } );
190
191 ffmpeg.on( 'close', ( code, signal ) => {
192 console.log( '\n\tVideo location:', videoPath, '\n' );
193 if ( code !== null ) {
194 console.log( `\tffmpeg exited with code ${code} ${videoPath}` );
195 }
196 if ( signal !== null ) {
197 console.log( `\tffmpeg received signal ${signal} ${videoPath}` );
198 }
199 } );
200 }
201 },
202
203 /**
204 * Save a screenshot when test fails.
205 *
206 * @param {Object} test Mocha Test object
207 */
208 afterTest: function ( test ) {
209 if ( ffmpeg ) {
210 // stop video recording
211 ffmpeg.kill( 'SIGINT' );
212 }
213
214 // if test passed, ignore, else take and save screenshot
215 if ( test.passed ) {
216 return;
217 }
218 // save screenshot
219 let screenshotfile = filePath( test, logPath, 'png' );
220 browser.saveScreenshot( screenshotfile );
221 console.log( '\n\tScreenshot location:', screenshotfile, '\n' );
222 }
223 };