Merge "RevisionStore: Introduce getContentBlobsForBatch"
[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://github.com/bermi/sauce-connect-launcher#advanced-usage
43 services: process.env.SAUCE_ACCESS_KEY ? [ 'sauce' ] : [],
44 user: process.env.SAUCE_USERNAME,
45 key: process.env.SAUCE_ACCESS_KEY,
46 sauceConnect: true,
47
48 // ==================
49 // Test Files
50 // ==================
51 specs: [
52 relPath( './tests/selenium/wdio-mediawiki/specs/*.js' ),
53 relPath( './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 // We disable it since we have our screenshot handler in the afterTest hook.
108 screenshotPath: null,
109
110 // Default timeout for each waitFor* command.
111 waitforTimeout: 10 * 1000,
112
113 // Framework you want to run your specs with.
114 // See also: http://webdriver.io/guide/testrunner/frameworks.html
115 framework: 'mocha',
116
117 // Test reporter for stdout.
118 // See also: http://webdriver.io/guide/testrunner/reporters.html
119 reporters: [ 'dot', 'junit' ],
120 reporterOptions: {
121 junit: {
122 outputDir: logPath
123 }
124 },
125
126 // Options to be passed to Mocha.
127 // See the full list at http://mochajs.org/
128 mochaOpts: {
129 ui: 'bdd',
130 timeout: 60 * 1000
131 },
132
133 // =====
134 // Hooks
135 // =====
136 // See also: http://webdriver.io/guide/testrunner/configurationfile.html
137
138 /**
139 * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
140 * @param {Object} test test details
141 */
142 beforeTest: function ( test ) {
143 if ( process.env.DISPLAY && process.env.DISPLAY.startsWith( ':' ) ) {
144 var logBuffer;
145 const videoPath = filePath( test, logPath, 'mp4' );
146 const { spawn } = require( 'child_process' );
147 ffmpeg = spawn( 'ffmpeg', [
148 '-f', 'x11grab', // grab the X11 display
149 '-video_size', '1280x1024', // video size
150 '-i', process.env.DISPLAY, // input file url
151 '-loglevel', 'error', // log only errors
152 '-y', // overwrite output files without asking
153 '-pix_fmt', 'yuv420p', // QuickTime Player support, "Use -pix_fmt yuv420p for compatibility with outdated media players"
154 videoPath // output file
155 ] );
156
157 logBuffer = function ( buffer, prefix ) {
158 const lines = buffer.toString().trim().split( '\n' );
159 lines.forEach( function ( line ) {
160 console.log( prefix + line );
161 } );
162 };
163
164 ffmpeg.stdout.on( 'data', ( data ) => {
165 logBuffer( data, 'ffmpeg stdout: ' );
166 } );
167
168 ffmpeg.stderr.on( 'data', ( data ) => {
169 logBuffer( data, 'ffmpeg stderr: ' );
170 } );
171
172 ffmpeg.on( 'close', ( code, signal ) => {
173 console.log( '\n\tVideo location:', videoPath, '\n' );
174 if ( code !== null ) {
175 console.log( `\tffmpeg exited with code ${code} ${videoPath}` );
176 }
177 if ( signal !== null ) {
178 console.log( `\tffmpeg received signal ${signal} ${videoPath}` );
179 }
180 } );
181 }
182 },
183
184 /**
185 * Save a screenshot when test fails.
186 *
187 * @param {Object} test Mocha Test object
188 */
189 afterTest: function ( test ) {
190 if ( ffmpeg ) {
191 // stop video recording
192 ffmpeg.kill( 'SIGINT' );
193 }
194
195 // if test passed, ignore, else take and save screenshot
196 if ( test.passed ) {
197 return;
198 }
199 // save screenshot
200 const screenshotfile = filePath( test, logPath, 'png' );
201 browser.saveScreenshot( screenshotfile );
202 console.log( '\n\tScreenshot location:', screenshotfile, '\n' );
203 }
204 };