Add first browser test

This adds a test which checks if the extension appears on the
Special:Version page.

This is an initial step for adding more browser tests to check
changes done in I26fe41c328157233cc5b06d38d2ba0f7b036a853

Change-Id: I9a9d1cd2a25277f2c430f4e80b51b72c1621f91b
This commit is contained in:
Andrew Kostka 2018-11-15 17:19:28 +00:00 committed by WMDE-Fisch
parent ee8da566e3
commit 626d9d4188
7 changed files with 168 additions and 2 deletions

View file

@ -21,6 +21,7 @@ module.exports = function ( grunt ) {
'**/*.js',
'{.jsduck,build}/**/*.js',
'modules/**/*.js',
'tests/**/*.js',
'!node_modules/**',
'!vendor/**'
]

View file

@ -4,7 +4,8 @@
"private": true,
"description": "Build tools for the Cite extension.",
"scripts": {
"test": "grunt test"
"test": "grunt test",
"selenium-test": "wdio tests/selenium/wdio.conf.js"
},
"devDependencies": {
"eslint-config-wikimedia": "0.8.1",
@ -16,6 +17,10 @@
"grunt-stylelint": "0.10.1",
"grunt-svgmin": "5.0.0",
"stylelint": "9.2.0",
"stylelint-config-wikimedia": "0.4.3"
"stylelint-config-wikimedia": "0.4.3",
"wdio-mediawiki": "0.2.0",
"wdio-mocha-framework": "0.6.1",
"wdio-spec-reporter": "0.1.4",
"webdriverio": "4.13.1"
}
}

View file

@ -0,0 +1,14 @@
{
"extends": "wikimedia",
"env": {
"es6": true,
"mocha": true,
"node": true
},
"globals": {
"browser": false
},
"rules": {
"no-console": 0
}
}

38
tests/selenium/README.md Normal file
View file

@ -0,0 +1,38 @@
# Selenium tests
Please see tests/selenium/README.md file in mediawiki/core repository, usually at mediawiki/vagrant/mediawiki folder.
## Setup
Set up MediaWiki-Vagrant:
cd mediawiki/vagrant
vagrant up
vagrant roles enable cite
vagrant provision
cd mediawiki
npm install
## Run all specs
Run test specs from both mediawiki/core and installed extensions:
cd mediawiki
npm run selenium
## Run specific tests
To run only some tests, you first have to start Chromedriver in one terminal window:
chromedriver --url-base=wd/hub --port=4444
Then, in another terminal window run this the current extension directory:
npm install
npm run selenium-test -- --spec tests/selenium/specs/FILE-NAME.js
You can also filter specific test(s) by name:
npm run selenium-test -- --spec tests/selenium/specs/FILE-NAME.js --mochaOpts.grep TEST-NAME
Make sure Chromedriver is running when executing the above command.

View file

@ -0,0 +1,11 @@
const Page = require( 'wdio-mediawiki/Page' );
class VersionPage extends Page {
get extension() { return browser.element( '#mw-version-ext-parserhook-Cite' ); }
open() {
super.openTitle( 'Special:Version' );
}
}
module.exports = new VersionPage();

View file

@ -0,0 +1,9 @@
var assert = require( 'assert' ),
VersionPage = require( '../pageobjects/version.page' );
describe( 'Cite', function () {
it( 'is configured correctly', function () {
VersionPage.open();
assert( VersionPage.extension.isExisting() );
} );
} );

View file

@ -0,0 +1,88 @@
/**
* See also: http://webdriver.io/guide/testrunner/configurationfile.html
*/
const fs = require( 'fs' ),
saveScreenshot = require( 'wdio-mediawiki' ).saveScreenshot;
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
// ============
capabilities: [ {
// 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
// ===================
// Level of verbosity: silent | verbose | command | data | result | error
logLevel: 'error',
// Setting this enables automatic screenshots for when a browser command fails
// It is also used by afterTest for capturig failed assertions.
screenshotPath: process.env.LOG_DIR || __dirname + '/log',
// Default timeout for each waitFor* command.
waitforTimeout: 10 * 1000,
// See also: http://webdriver.io/guide/testrunner/reporters.html
reporters: [ 'spec' ],
// See also: http://mochajs.org
mochaOpts: {
ui: 'bdd',
timeout: 60 * 1000
},
// =====
// Hooks
// =====
/**
* Save a screenshot when test fails.
*
* @param {Object} test Mocha Test object
*/
afterTest: function ( test ) {
var filePath;
if ( !test.passed ) {
filePath = saveScreenshot( test.title );
console.log( '\n\tScreenshot: ' + filePath + '\n' );
}
}
};