From 8a4fab569ce8d54cf5b8b1f774e6ed57552fc0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDeljko=20Filipin?= Date: Fri, 30 Apr 2021 15:48:48 +0200 Subject: [PATCH] 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 --- tests/selenium/wdio-mediawiki/wdio.conf.js | 121 ++++++++++++++++++++ tests/selenium/wdio.conf.js | 122 ++------------------- 2 files changed, 133 insertions(+), 110 deletions(-) create mode 100644 tests/selenium/wdio-mediawiki/wdio.conf.js diff --git a/tests/selenium/wdio-mediawiki/wdio.conf.js b/tests/selenium/wdio-mediawiki/wdio.conf.js new file mode 100644 index 00000000000..5f02818c697 --- /dev/null +++ b/tests/selenium/wdio-mediawiki/wdio.conf.js @@ -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.`. + // 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}` ); + } +}; diff --git a/tests/selenium/wdio.conf.js b/tests/selenium/wdio.conf.js index 6dec0482de4..95df6ce695b 100644 --- a/tests/selenium/wdio.conf.js +++ b/tests/selenium/wdio.conf.js @@ -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 - * and . - */ -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.`. - // 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}` ); } -}; +} );