selenium: Add a basic wdio.conf.js to wdio-mediawiki

So far, each repository had it's own wdio.conf.js file. That lead to a
lot of duplicated code. This patch moves core's wdio.conf.js file to
wdio-mediawiki package. The file can be used by core, extensions and
skins. Each repository can override settings, if needed.

Bug: T281484
Change-Id: Icd098a2adf8f6183aad5fb6b33196c67fd809e15
This commit is contained in:
Željko Filipin 2021-04-30 15:48:48 +02:00 committed by Zfilipin
parent f6508708a6
commit 8a4fab569c
2 changed files with 133 additions and 110 deletions

View file

@ -0,0 +1,121 @@
'use strict';
require( 'dotenv' ).config();
const fs = require( 'fs' );
const path = require( 'path' );
const video = require( 'wdio-video-reporter' );
const logPath = process.env.LOG_DIR || path.join( process.cwd(), 'tests/selenium/log' );
const { makeFilenameDate, saveScreenshot } = require( 'wdio-mediawiki' );
if ( !process.env.MW_SERVER || !process.env.MW_SCRIPT_PATH ) {
throw new Error( 'MW_SERVER or MW_SCRIPT_PATH not defined.\nSee https://www.mediawiki.org/wiki/Selenium/How-to/Set_environment_variables\n' );
}
/**
* For more details documentation and available options:
* - https://webdriver.io/docs/configurationfile/
* - https://webdriver.io/docs/options/
*/
exports.config = {
// ==================
// Automation Protocols
// ==================
// See https://webdriver.io/docs/automationProtocols/
automationProtocol: 'devtools',
// ======
// Custom conf keys for MediaWiki
//
// Access via `browser.config.<key>`.
// Defaults are for MediaWiki-Docker
// ======
mwUser: process.env.MEDIAWIKI_USER,
mwPwd: process.env.MEDIAWIKI_PASSWORD,
// ==================
// Runner Configuration
// ==================
runner: 'local',
// ==================
// Test Files
// ==================
specs: [
'./tests/selenium/specs/**/*.js'
],
// ============
// Capabilities
// Define the different browser configurations to use ("capabilities") here.
// ============
maxInstances: 1,
capabilities: [ {
// For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
browserName: 'chrome',
'goog:chromeOptions': {
// If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
// Otherwise, use --headless.
args: [
...( process.env.DISPLAY ? [] : [ '--headless' ] ),
// Chrome sandbox does not work in Docker
...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
]
}
} ],
// ===================
// Test Configurations
// Define all options that are relevant for the WebdriverIO instance here
// ===================
// Level of logging verbosity: trace | debug | info | warn | error | silent
logLevel: 'error',
// Setting this enables automatic screenshots for when a browser command fails
// It is also used by afterTest for capturing screenshots.
screenshotPath: logPath,
// Stop after this many failures, or 0 to run all tests before reporting failures.
bail: 0,
// Base for browser.url() and wdio-mediawiki/Page#openTitle()
baseUrl: process.env.MW_SERVER + process.env.MW_SCRIPT_PATH,
// See also: https://webdriver.io/docs/frameworks/
framework: 'mocha',
// See also: https://mochajs.org/
mochaOpts: {
ui: 'bdd',
timeout: process.env.DEBUG ? ( 60 * 60 * 1000 ) : ( 60 * 1000 )
},
// See also: https://webdriver.io/docs/dot-reporter.html
reporters: [
// See also: https://webdriver.io/docs/dot-reporter/
'dot',
// See also: https://webdriver.io/docs/junit-reporter/
[ 'junit', {
outputDir: logPath,
outputFileFormat: function () {
return `WDIO.xunit-${makeFilenameDate()}.xml`;
}
} ],
// See also: https://webdriver.io/docs/wdio-video-reporter/
[
video, {
saveAllVideos: true,
outputDir: logPath
}
]
],
// =====
// Hooks
// =====
/**
* Executed after a Mocha test ends.
*
* @param {Object} test Mocha Test object
*/
afterTest: function ( test ) {
saveScreenshot( `${test.parent}-${test.title}` );
}
};

View file

@ -1,122 +1,24 @@
'use strict';
require( 'dotenv' ).config();
const fs = require( 'fs' );
const path = require( 'path' );
const video = require( 'wdio-video-reporter' );
const logPath = process.env.LOG_DIR || path.join( __dirname, '/log' );
const { makeFilenameDate, saveScreenshot } = require( 'wdio-mediawiki' );
const { config } = require( 'wdio-mediawiki/wdio.conf.js' );
/**
* For more details documentation and available options,
* see <https://webdriver.io/docs/configurationfile.html>
* and <https://webdriver.io/docs/options.html>.
*/
exports.config = {
// ==================
// Automation Protocols
// ==================
// See https://webdriver.io/docs/automationProtocols/
automationProtocol: 'devtools',
// ======
// Custom conf keys for MediaWiki
exports.config = Object.assign( config, {
// Override, or add to, the setting from wdio-mediawiki.
// Learn more at https://webdriver.io/docs/configurationfile/
//
// Access via `browser.config.<key>`.
// Defaults are for MediaWiki-Vagrant
// ======
mwUser: process.env.MEDIAWIKI_USER,
mwPwd: process.env.MEDIAWIKI_PASSWORD,
// Example:
// logLevel: 'info',
// ==================
// Runner Configuration
// ==================
runner: 'local',
// ==================
// Test Files
// ==================
specs: [
'./tests/selenium/wdio-mediawiki/specs/*.js',
'./tests/selenium/specs/**/*.js'
'tests/selenium/specs/**/*.js',
'tests/selenium/wdio-mediawiki/specs/*.js'
],
suites: {
daily: [
'./tests/selenium/wdio-mediawiki/specs/*.js',
'./tests/selenium/specs/page.js',
'./tests/selenium/specs/user.js'
'tests/selenium/wdio-mediawiki/specs/*.js',
'tests/selenium/specs/page.js',
'tests/selenium/specs/user.js'
]
},
// ============
// Capabilities
// Define the different browser configurations to use ("capabilities") here.
// ============
maxInstances: 1,
capabilities: [ {
// For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
browserName: 'chrome',
'goog:chromeOptions': {
// If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
// Otherwise, use --headless.
args: [
...( process.env.DISPLAY ? [] : [ '--headless' ] ),
// Chrome sandbox does not work in Docker
...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
]
}
} ],
// ===================
// Test Configurations
// Define all options that are relevant for the WebdriverIO instance here
// ===================
// Level of logging verbosity: trace | debug | info | warn | error | silent
logLevel: 'error',
// Setting this enables automatic screenshots for when a browser command fails
// It is also used by afterTest for capturing screenshots.
screenshotPath: logPath,
// Stop after this many failures, or 0 to run all tests before reporting failures.
bail: 0,
// Base for browser.url() and wdio-mediawiki/Page#openTitle()
baseUrl: ( process.env.MW_SERVER ) + (
process.env.MW_SCRIPT_PATH
),
// See also: https://webdriver.io/docs/frameworks.html
framework: 'mocha',
// See also: https://webdriver.io/docs/dot-reporter.html
reporters: [
'dot',
// See also: https://webdriver.io/docs/junit-reporter.html#configuration
[ 'junit', {
outputDir: logPath,
outputFileFormat: function () {
return `WDIO.xunit-${makeFilenameDate()}.xml`;
}
} ],
[
video, {
saveAllVideos: true,
outputDir: logPath
}
]
],
// See also: http://mochajs.org/
mochaOpts: {
ui: 'bdd',
timeout: process.env.DEBUG ? ( 60 * 60 * 1000 ) : ( 60 * 1000 )
},
// =====
// Hooks
// =====
/**
* Executed after a Mocha test ends.
*
* @param {Object} test Mocha Test object
*/
afterTest: function ( test ) {
saveScreenshot( `${test.parent}-${test.title}` );
}
};
} );