Debian Codegraph @

tests/selenium/wdio-mediawiki/wdio-defaults.conf.js

raw symbols SCIP
1 /**
2 * Base WebdriverIO configuration, meant to be imported from skins and extensions like so:
3 *
4 * const { config } = require( 'wdio-mediawiki/wdio-defaults.conf.js' );
5 *
6 * exports.config = { ...config,
7 * logLevel: 'info'
8 * };
9 */
10
11 'use strict';
12
13 let ffmpeg;
14 const fs = require( 'fs' );
15 const path = require( 'path' );
16 const logPath = process.env.LOG_DIR || path.join( process.cwd(), 'tests/selenium/log' );
17 const { makeFilenameDate, saveScreenshot, startVideo, stopVideo } = require( 'wdio-mediawiki' );
18 // T355556: remove when T324766 is resolved
19 const dns = require( 'dns' );
20
21 if ( !process.env.MW_SERVER || !process.env.MW_SCRIPT_PATH ) {
22 throw new Error( 'MW_SERVER or MW_SCRIPT_PATH not defined.\nSee https://www.mediawiki.org/wiki/Selenium/How-to/Set_environment_variables\n' );
23 }
24
25 /**
26 * For more details documentation and available options:
27 * - https://webdriver.io/docs/configurationfile
28 * - https://webdriver.io/docs/configuration
29 */
30 exports.config = {
31 // ======
32 // Custom conf keys for MediaWiki
33 //
34 // Access via `browser.config.<key>`.
35 // Defaults are for MediaWiki-Docker
36 // ======
37 mwUser: process.env.MEDIAWIKI_USER,
38 mwPwd: process.env.MEDIAWIKI_PASSWORD,
39
40 // ==================
41 // Runner Configuration
42 // ==================
43 runner: 'local',
44
45 // ==================
46 // Test Files
47 // ==================
48 specs: [
49 './tests/selenium/specs/**/*.js'
50 ],
51
52 // ============
53 // Capabilities
54 // Define the different browser configurations to use ("capabilities") here.
55 // ============
56
57 maxInstances: 1,
58 capabilities: [ {
59 // For Chrome/Chromium https://www.w3.org/TR/webdriver
60 browserName: 'chrome',
61 'goog:chromeOptions': {
62 // If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
63 // Otherwise, use --headless.
64 args: [
65 // Dismissed Chrome's `Save password?` popup
66 '--enable-automation',
67 ...( process.env.DISPLAY ? [] : [ '--headless' ] ),
68 // Chrome sandbox does not work in Docker
69 ...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] ),
70 // Workaround inputs not working consistently post-navigation on Chrome 90
71 // https://issuetracker.google.com/issues/42322798
72 '--allow-pre-commit-input'
73 ]
74 }
75 } ],
76
77 // ===================
78 // Test Configurations
79 // Define all options that are relevant for the WebdriverIO instance here
80 // ===================
81
82 // Level of logging verbosity: trace | debug | info | warn | error | silent
83 logLevel: 'error',
84 // Setting this enables automatic screenshots for when a browser command fails
85 // It is also used by afterTest for capturing screenshots.
86 screenshotPath: logPath,
87 // Stop after this many failures, or 0 to run all tests before reporting failures.
88 bail: 0,
89 // Base for browser.url() and wdio-mediawiki/Page#openTitle()
90 baseUrl: process.env.MW_SERVER + process.env.MW_SCRIPT_PATH,
91 // See also: https://webdriver.io/docs/frameworks
92 framework: 'mocha',
93 // See also: https://mochajs.org
94 // The number of times to retry the entire specfile when it fails as a whole
95 specFileRetries: 1,
96 // Delay in seconds between the spec file retry attempts
97 specFileRetriesDelay: 0,
98 // Whether or not retried specfiles should be retried immediately or deferred to the end of the
99 // queue
100 specFileRetriesDeferred: false,
101 mochaOpts: {
102 ui: 'bdd',
103 timeout: process.env.DEBUG ? ( 60 * 60 * 1000 ) : ( 60 * 1000 )
104 },
105 // See also: https://webdriver.io/docs/dot-reporter
106 reporters: [
107 // See also: https://webdriver.io/docs/spec-reporter
108 'spec',
109 // See also: https://webdriver.io/docs/junit-reporter
110 [ 'junit', {
111 outputDir: logPath,
112 outputFileFormat: function () {
113 const random = Math.random().toString( 16 ).slice( 2, 10 );
114 return `WDIO.xunit-${ makeFilenameDate() }-${ random }.xml`;
115 }
116 } ]
117 ],
118
119 // =====
120 // Hooks
121 // =====
122
123 /**
124 * Gets executed just before initializing the webdriver session and test framework.
125 * It allows you to manipulate configurations depending on the capability or spec.
126 *
127 * @param {Object} config wdio configuration object
128 * @param {Array.<Object>} capabilities list of capabilities details
129 * @param {Array.<string>} specs List of spec file paths that are to be run
130 */
131 // T355556: remove when T324766 is resolved
132 beforeSession: function () {
133 // eslint-disable-next-line n/no-unsupported-features/node-builtins
134 dns.setDefaultResultOrder( 'ipv4first' );
135 },
136
137 /**
138 * Executed before a Mocha test starts.
139 *
140 * @param {Object} test Mocha Test object
141 */
142 beforeTest: function ( test ) {
143 ffmpeg = startVideo( ffmpeg, `${ test.parent }-${ test.title }` );
144 },
145
146 /**
147 * Executed after a Mocha test ends.
148 *
149 * @param {Object} test Mocha Test object
150 */
151 afterTest: async function ( test ) {
152 await saveScreenshot( `${ test.parent }-${ test.title }` );
153 stopVideo( ffmpeg );
154 }
155 };