Selenium: add selenium-daily NPM script

The script is needed to run the new Docker-based Jenkins job that runs daily and targets beta cluster.
selenium-test script and NPM packages are dependencies. selenium-daily now just calls selenium-test.

selenium-daily might seem redundant, but it provides flexibility. In case a
repository does not want to run all tests daily, that's easily fixed by updating the
selenium-daily script.

Bug: T188742
Change-Id: I35c93ff1897afc4b9e66703a1acf765e3fe7b643
This commit is contained in:
Željko Filipin 2018-07-31 18:04:12 +02:00 committed by Pmiazga
parent df9e724d89
commit c578de27d8
3 changed files with 134 additions and 5 deletions

View file

@ -9,7 +9,9 @@
"doc": "jsdoc -c jsdoc.json", "doc": "jsdoc -c jsdoc.json",
"check-built-assets": "echo 'CHECKING BUILD SOURCES ARE COMMITTED OR STAGED' && npm -s run build && git diff -q resources/dist", "check-built-assets": "echo 'CHECKING BUILD SOURCES ARE COMMITTED OR STAGED' && npm -s run build && git diff -q resources/dist",
"coverage": "SPAWN_WRAP_SHIM_ROOT=\"$PWD/.nyc_output\" nyc npm -s run test:node", "coverage": "SPAWN_WRAP_SHIM_ROOT=\"$PWD/.nyc_output\" nyc npm -s run test:node",
"precommit": "npm -s t" "precommit": "npm -s t",
"selenium-daily": "npm run selenium-test",
"selenium-test": "wdio tests/selenium/wdio.conf.js"
}, },
"devDependencies": { "devDependencies": {
"@wikimedia/mw-node-qunit": "5.0.0", "@wikimedia/mw-node-qunit": "5.0.0",
@ -35,6 +37,10 @@
"stylelint-config-wikimedia": "0.4.3", "stylelint-config-wikimedia": "0.4.3",
"svg-inline-loader": "0.8.0", "svg-inline-loader": "0.8.0",
"tap-mocha-reporter": "3.0.7", "tap-mocha-reporter": "3.0.7",
"wdio-mediawiki": "0.2.0",
"wdio-mocha-framework": "0.6.1",
"wdio-spec-reporter": "0.1.4",
"webdriverio": "4.13.1",
"webpack": "4.1.1", "webpack": "4.1.1",
"webpack-cli": "2.0.12" "webpack-cli": "2.0.12"
}, },

View file

@ -1,7 +1,7 @@
const const
fs = require( 'fs' ), fs = require( 'fs' ),
EditPage = require( '../../../../../tests/selenium/pageobjects/edit.page' ), Api = require( 'wdio-mediawiki/Api' ),
Page = require( '../../../../../tests/selenium/pageobjects/page' ), Page = require( 'wdio-mediawiki/Page' ),
TEST_PAGE_TITLE = 'Popups test page', TEST_PAGE_TITLE = 'Popups test page',
POPUPS_SELECTOR = '.mwe-popups', POPUPS_SELECTOR = '.mwe-popups',
POPUPS_MODULE_NAME = 'ext.popups.main'; POPUPS_MODULE_NAME = 'ext.popups.main';
@ -17,7 +17,7 @@ class PopupsPage extends Page {
resolve( content ); resolve( content );
} ); } );
} ).then( ( content ) => { } ).then( ( content ) => {
return EditPage.apiEdit( TEST_PAGE_TITLE, content ); return Api.edit( TEST_PAGE_TITLE, content );
} ); } );
} ); } );
} }
@ -64,7 +64,7 @@ class PopupsPage extends Page {
} }
open() { open() {
super.open( TEST_PAGE_TITLE ); super.openTitle( TEST_PAGE_TITLE );
} }
} }

123
tests/selenium/wdio.conf.js Normal file
View file

@ -0,0 +1,123 @@
const fs = require( 'fs' ),
saveScreenshot = require( 'wdio-mediawiki' ).saveScreenshot,
logPath = process.env.LOG_DIR || `${__dirname }/log`;
exports.config = {
// ======
// Custom WDIO config specific to MediaWiki
// ======
// Use in a test as `browser.options.<key>`.
// Defaults are for convenience with MediaWiki-Vagrant
// Wiki admin
username: process.env.MEDIAWIKI_USER || 'Admin',
password: process.env.MEDIAWIKI_PASSWORD || 'vagrant',
// Base for browser.url() and Page#openTitle()
baseUrl: ( process.env.MW_SERVER || 'http://127.0.0.1:8080' ) + (
process.env.MW_SCRIPT_PATH || '/w'
),
// ==================
// Test Files
// ==================
specs: [
`${__dirname }/specs/*.js`
],
// ============
// Capabilities
// ============
// How many instances of the same capability (browser) may be started at the same time.
maxInstances: 1,
capabilities: [ {
// For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
browserName: 'chrome',
maxInstances: 1,
chromeOptions: {
// If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
// Otherwise, use --headless (added in Chrome 59)
// https://chromium.googlesource.com/chromium/src/+/59.0.3030.0/headless/README.md
args: [
...( process.env.DISPLAY ? [] : [ '--headless' ] ),
// Chrome sandbox does not work in Docker
...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
]
}
} ],
// ===================
// Test Configurations
// ===================
// Enabling synchronous mode (via the wdio-sync package), means specs don't have to
// use Promise#then() or await for browser commands, such as like `brower.element()`.
// Instead, it will automatically pause JavaScript execution until th command finishes.
//
// For non-browser commands (such as MWBot and other promises), this means you
// have to use `browser.call()` to make sure WDIO waits for it before the next
// browser command.
sync: true,
// Level of logging verbosity: silent | verbose | command | data | result | error
logLevel: 'error',
// Enables colors for log output.
coloredLogs: true,
// Warns when a deprecated command is used
deprecationWarnings: true,
// Stop the tests once a certain number of failed tests have been recorded.
// Default is 0 - don't bail, run all tests.
bail: 0,
// Setting this enables automatic screenshots for when a browser command fails
// It is also used by afterTest for capturig failed assertions.
screenshotPath: logPath,
// Default timeout for each waitFor* command.
waitforTimeout: 10 * 1000,
// Framework you want to run your specs with.
// See also: http://webdriver.io/guide/testrunner/frameworks.html
framework: 'mocha',
// Test reporter for stdout.
// See also: http://webdriver.io/guide/testrunner/reporters.html
reporters: [ 'spec', 'junit' ],
reporterOptions: {
junit: {
outputDir: logPath
}
},
// Options to be passed to Mocha.
// See the full list at http://mochajs.org/
mochaOpts: {
ui: 'bdd',
timeout: 60 * 1000
},
// =====
// Hooks
// =====
// See also: http://webdriver.io/guide/testrunner/configurationfile.html
/**
* Save a screenshot when test fails.
*
* @param {Object} test Mocha Test object
* @returns {void}
*
*/
afterTest: function ( test ) {
let filePath;
if ( !test.passed ) {
filePath = saveScreenshot( test.title );
console.log( `\n\tScreenshot: ${ filePath }\n` );
}
}
};