]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - tests/selenium/wdio.conf.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / tests / selenium / wdio.conf.js
1 /* eslint-env node */
2 /* eslint no-undef: "error" */
3 /* eslint-disable no-console, comma-dangle */
4 'use strict';
5
6 const fs = require( 'fs' ),
7         path = require( 'path' );
8
9 function relPath( foo ) {
10         return path.resolve( __dirname, '../..', foo );
11 }
12
13 exports.config = {
14
15         //
16         // ======
17         //
18         // ======
19         // Custom
20         // ======
21         // Define any custom variables.
22         // Example:
23         // username: 'Admin',
24         // Use if from tests with:
25         // browser.options.username
26         username: process.env.MEDIAWIKI_USER === undefined ?
27                 'Admin' :
28                 process.env.MEDIAWIKI_USER,
29         password: process.env.MEDIAWIKI_PASSWORD === undefined ?
30                 'vagrant' :
31                 process.env.MEDIAWIKI_PASSWORD,
32         //
33         // ======
34         // Sauce Labs
35         // ======
36         //
37         services: [ 'sauce' ],
38         user: process.env.SAUCE_USERNAME,
39         key: process.env.SAUCE_ACCESS_KEY,
40         //
41         // ==================
42         // Specify Test Files
43         // ==================
44         // Define which test specs should run. The pattern is relative to the directory
45         // from which `wdio` was called. Notice that, if you are calling `wdio` from an
46         // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
47         // directory is where your package.json resides, so `wdio` will be called from there.
48         //
49         specs: [
50                 relPath( './tests/selenium/specs/**/*.js' ),
51                 relPath( './extensions/*/tests/selenium/specs/**/*.js' ),
52                 relPath( './extensions/VisualEditor/modules/ve-mw/tests/selenium/specs/**/*.js' ),
53                 relPath( './skins/*/tests/selenium/specs/**/*.js' ),
54         ],
55         // Patterns to exclude.
56         exclude: [
57         // 'path/to/excluded/files'
58         ],
59         //
60         // ============
61         // Capabilities
62         // ============
63         // Define your capabilities here. WebdriverIO can run multiple capabilities at the same
64         // time. Depending on the number of capabilities, WebdriverIO launches several test
65         // sessions. Within your capabilities you can overwrite the spec and exclude options in
66         // order to group specific specs to a specific capability.
67         //
68         // First, you can define how many instances should be started at the same time. Let's
69         // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
70         // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
71         // files and you set maxInstances to 10, all spec files will get tested at the same time
72         // and 30 processes will get spawned. The property handles how many capabilities
73         // from the same test should run tests.
74         //
75         maxInstances: 1,
76         //
77         // If you have trouble getting all important capabilities together, check out the
78         // Sauce Labs platform configurator - a great tool to configure your capabilities:
79         // https://docs.saucelabs.com/reference/platforms-configurator
80         //
81         // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
82         capabilities: [ {
83                 // maxInstances can get overwritten per capability. So if you have an in-house Selenium
84                 // grid with only 5 firefox instances available you can make sure that not more than
85                 // 5 instances get started at a time.
86                 maxInstances: 1,
87                 //
88                 browserName: 'chrome',
89                 chromeOptions: {
90                         // Run headless when there is no DISPLAY
91                         // --headless: since Chrome 59 https://chromium.googlesource.com/chromium/src/+/59.0.3030.0/headless/README.md
92                         args: (
93                                 process.env.DISPLAY ? [] : [ '--headless' ]
94                         ).concat(
95                                 // Disable Chrome sandbox when running in Docker
96                                 fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : []
97                         )
98                 }
99         } ],
100         //
101         // ===================
102         // Test Configurations
103         // ===================
104         // Define all options that are relevant for the WebdriverIO instance here
105         //
106         // By default WebdriverIO commands are executed in a synchronous way using
107         // the wdio-sync package. If you still want to run your tests in an async way
108         // e.g. using promises you can set the sync option to false.
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         // Saves a screenshot to a given path if a command fails.
118         screenshotPath: './log/',
119         //
120         // Set a base URL in order to shorten url command calls. If your url parameter starts
121         // with "/", then the base url gets prepended.
122         baseUrl: (
123                 process.env.MW_SERVER === undefined ?
124                         'http://127.0.0.1:8080' :
125                         process.env.MW_SERVER
126         ) + (
127                 process.env.MW_SCRIPT_PATH === undefined ?
128                         '/w' :
129                         process.env.MW_SCRIPT_PATH
130         ),
131         //
132         // Default timeout for all waitFor* commands.
133         waitforTimeout: 20000,
134         //
135         // Default timeout in milliseconds for request
136         // if Selenium Grid doesn't send response
137         connectionRetryTimeout: 90000,
138         //
139         // Default request retries count
140         connectionRetryCount: 3,
141         //
142         // Initialize the browser instance with a WebdriverIO plugin. The object should have the
143         // plugin name as key and the desired plugin options as properties. Make sure you have
144         // the plugin installed before running any tests. The following plugins are currently
145         // available:
146         // WebdriverCSS: https://github.com/webdriverio/webdrivercss
147         // WebdriverRTC: https://github.com/webdriverio/webdriverrtc
148         // Browserevent: https://github.com/webdriverio/browserevent
149         // plugins: {
150         //     webdrivercss: {
151         //         screenshotRoot: 'my-shots',
152         //         failedComparisonsRoot: 'diffs',
153         //         misMatchTolerance: 0.05,
154         //         screenWidth: [320,480,640,1024]
155         //     },
156         //     webdriverrtc: {},
157         //     browserevent: {}
158         // },
159         //
160         // Test runner services
161         // Services take over a specific job you don't want to take care of. They enhance
162         // your test setup with almost no effort. Unlike plugins, they don't add new
163         // commands. Instead, they hook themselves up into the test process.
164         // services: [],//
165         // Framework you want to run your specs with.
166         // The following are supported: Mocha, Jasmine, and Cucumber
167         // see also: http://webdriver.io/guide/testrunner/frameworks.html
168         //
169         // Make sure you have the wdio adapter package for the specific framework installed
170         // before running any tests.
171         framework: 'mocha',
172
173         // Test reporter for stdout.
174         // The only one supported by default is 'dot'
175         // see also: http://webdriver.io/guide/testrunner/reporters.html
176         reporters: [ 'spec' ],
177         //
178         // Options to be passed to Mocha.
179         // See the full list at http://mochajs.org/
180         mochaOpts: {
181                 ui: 'bdd',
182                 timeout: 20000
183         },
184         //
185         // =====
186         // Hooks
187         // =====
188         // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
189         // it and to build services around it. You can either apply a single function or an array of
190         // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
191         // resolved to continue.
192         //
193         // Gets executed once before all workers get launched.
194         // onPrepare: function ( config, capabilities ) {
195         // }
196         //
197         // Gets executed before test execution begins. At this point you can access all global
198         // variables, such as `browser`. It is the perfect place to define custom commands.
199         // before: function (capabilities, specs) {
200         // },
201         //
202         // Hook that gets executed before the suite starts
203         // beforeSuite: function (suite) {
204         // },
205         //
206         // Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
207         // beforeEach in Mocha)
208         // beforeHook: function () {
209         // },
210         //
211         // Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
212         // afterEach in Mocha)
213         //
214         // Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
215         // beforeTest: function (test) {
216         // },
217         //
218         // Runs before a WebdriverIO command gets executed.
219         // beforeCommand: function (commandName, args) {
220         // },
221         //
222         // Runs after a WebdriverIO command gets executed
223         // afterCommand: function (commandName, args, result, error) {
224         // },
225         //
226         // Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
227         // from https://github.com/webdriverio/webdriverio/issues/269#issuecomment-306342170
228         afterTest: function ( test ) {
229                 var filename, filePath;
230                 // if test passed, ignore, else take and save screenshot
231                 if ( test.passed ) {
232                         return;
233                 }
234                 // get current test title and clean it, to use it as file name
235                 filename = encodeURIComponent( test.title.replace( /\s+/g, '-' ) );
236                 // build file path
237                 filePath = this.screenshotPath + filename + '.png';
238                 // save screenshot
239                 browser.saveScreenshot( filePath );
240                 console.log( '\n\tScreenshot location:', filePath, '\n' );
241         },
242         //
243         // Hook that gets executed after the suite has ended
244         // afterSuite: function (suite) {
245         // },
246         //
247         // Gets executed after all tests are done. You still have access to all global variables from
248         // the test.
249         // after: function (result, capabilities, specs) {
250         // },
251         //
252         // Gets executed after all workers got shut down and the process is about to exit. It is not
253         // possible to defer the end of the process using a promise.
254         // onComplete: function(exitCode) {
255         // }
256 };