932a8aaeaadef26d4b40e09a71a2988c263486a5
1 const fs
= require( 'fs' ),
2 path
= require( 'path' ),
3 startChromedriver
= !process
.argv
.includes( '--skip-chromedriver' ),
4 logPath
= process
.env
.LOG_DIR
|| path
.join( __dirname
, '/log' );
8 // get current test title and clean it, to use it as file name
9 function fileName( title
) {
10 return encodeURIComponent( title
.replace( /\s+/g, '-' ) );
14 function filePath( test
, screenshotPath
, extension
) {
15 return path
.join( screenshotPath
, `${fileName( test.parent )}-${fileName( test.title )}.${extension}` );
19 * For more details documentation and available options,
20 * see <https://webdriver.io/docs/configurationfile.html>
21 * and <https://webdriver.io/docs/options.html>.
25 // Custom conf keys for MediaWiki
27 // Access via `browser.config.<key>`.
28 // Defaults are for MediaWiki-Vagrant
30 mwUser
: process
.env
.MEDIAWIKI_USER
|| 'Admin',
31 mwPwd
: process
.env
.MEDIAWIKI_PASSWORD
|| 'vagrant',
34 // Runner Configuration
37 // The standalone chromedriver (also used by WMF CI) uses "/wd/hub".
38 // The one provided by wdio uses "/".
39 path
: startChromedriver
? '/' : '/wd/hub',
44 // See http://webdriver.io/guide/services/sauce.html
45 // and https://github.com/bermi/sauce-connect-launcher#advanced-usage
46 user
: process
.env
.SAUCE_USERNAME
,
47 key
: process
.env
.SAUCE_ACCESS_KEY
,
54 './tests/selenium/wdio-mediawiki/specs/*.js',
55 './tests/selenium/specs/**/*.js'
60 // Define the different browser configurations to use ("capabilities") here.
64 // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
65 browserName
: 'chrome',
66 'goog:chromeOptions': {
67 // If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
68 // Otherwise, use --headless.
70 ...( process
.env
.DISPLAY
? [] : [ '--headless' ] ),
71 // Chrome sandbox does not work in Docker
72 ...( fs
.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
77 // ===================
78 // Test Configurations
79 // Define all options that are relevant for the WebdriverIO instance here
80 // ===================
81 // Level of logging verbosity: trace | debug | info | warn | error | silent
83 // Stop after this many failures, or 0 to run all tests before reporting failures.
85 // Base for browser.url() and wdio-mediawiki/Page#openTitle()
86 baseUrl
: ( process
.env
.MW_SERVER
|| 'http://127.0.0.1:8080' ) + (
87 process
.env
.MW_SCRIPT_PATH
|| '/w'
90 ...( startChromedriver
? [ 'chromedriver' ] : [] ),
91 ...( process
.env
.SAUCE_ACCESS_KEY
? [ 'sauce' ] : [] )
93 // See also: https://webdriver.io/docs/frameworks.html
95 // See also: https://webdriver.io/docs/dot-reporter.html
98 // See also: https://webdriver.io/docs/junit-reporter.html#configuration
103 // See also: http://mochajs.org/
113 * Executed before a Mocha test starts.
114 * @param {Object} test Mocha Test object
116 beforeTest: function ( test
) {
117 if ( process
.env
.DISPLAY
&& process
.env
.DISPLAY
.startsWith( ':' ) ) {
118 const videoPath
= filePath( test
, logPath
, 'mp4' );
119 const { spawn
} = require( 'child_process' );
120 ffmpeg
= spawn( 'ffmpeg', [
121 '-f', 'x11grab', // grab the X11 display
122 '-video_size', '1280x1024', // video size
123 '-i', process
.env
.DISPLAY
, // input file url
124 '-loglevel', 'error', // log only errors
125 '-y', // overwrite output files without asking
126 '-pix_fmt', 'yuv420p', // QuickTime Player support, "Use -pix_fmt yuv420p for compatibility with outdated media players"
127 videoPath
// output file
130 const logBuffer = function ( buffer
, prefix
) {
131 const lines
= buffer
.toString().trim().split( '\n' );
132 lines
.forEach( function ( line
) {
133 console
.log( prefix
+ line
);
137 ffmpeg
.stdout
.on( 'data', ( data
) => {
138 logBuffer( data
, 'ffmpeg stdout: ' );
141 ffmpeg
.stderr
.on( 'data', ( data
) => {
142 logBuffer( data
, 'ffmpeg stderr: ' );
145 ffmpeg
.on( 'close', ( code
, signal
) => {
146 console
.log( '\n\tVideo location:', videoPath
, '\n' );
147 if ( code
!== null ) {
148 console
.log( `\tffmpeg exited with code ${code} ${videoPath}` );
150 if ( signal
!== null ) {
151 console
.log( `\tffmpeg received signal ${signal} ${videoPath}` );
157 * Executed after a Mocha test ends.
158 * @param {Object} test Mocha Test object
160 afterTest: function ( test
) {
162 // stop video recording
163 ffmpeg
.kill( 'SIGINT' );
166 // if test passed, ignore, else take and save screenshot
171 const screenshotfile
= filePath( test
, logPath
, 'png' );
172 browser
.saveScreenshot( screenshotfile
);
173 console
.log( '\n\tScreenshot location:', screenshotfile
, '\n' );