Selenium/How-to/Create the first test in a repository

This tutorial will assume that you are running tests from your machine, targeting MediaWiki-Docker.

For more examples see Selenium/Getting Started/Create a simple test page and Selenium/Reference/Example Code.

Let's write a new simple test for Extension:Examples. For example, let's check if the extension is listed at Special:Version page.

Following code is available at gerrit:674939.

SimpleEdit

The minimal amount of code is just one spec file and just one page object file.

tests/selenium/pageobjects/version.page.js

'use strict';

const Page = require( 'wdio-mediawiki/Page' );

// this is just a sample on how to create a page
class VersionPage extends Page {
	// this is just a sample on how to find an element
	get extension() { return $( '#mw-version-ext-other-examples' ); }

	// this is just a sample on how to open a page
	open() {
		super.openTitle( 'Special:Version' );
	}
}

module.exports = new VersionPage();

tests/selenium/specs/version.js

'use strict';

const assert = require( 'assert' ),
	// this is just a sample on how to use a page
	VersionPage = require( '../pageobjects/version.page' );

describe( 'Examples', function () {

	// this is just a sample test
	it( 'is configured correctly', function () {
		VersionPage.open();

		// this is just a sample assertion, checking if an element exists
		assert( VersionPage.extension.isExisting() );

	} );

} );

TypicalEdit

Typical patch will have a few more files. You will need these files if this is the first Selenium test in the repository.

.gitignore

tests/selenium/log

package.json

{
	"scripts": {
		"selenium-daily": "npm run selenium-test",
		"selenium-test": "wdio tests/selenium/wdio.conf.js"
	},
	"devDependencies": {
		"@wdio/cli": "7.4.6",
		"@wdio/dot-reporter": "7.4.2",
		"@wdio/junit-reporter": "7.4.2",
		"@wdio/local-runner": "7.4.6",
		"@wdio/mocha-framework": "7.4.6",
		"@wdio/sync": "7.4.6",
		"wdio-mediawiki": "1.1.1",
		"webdriverio": "7.4.6"
	}
}

tests/selenium/.eslintrc.json

{
	"root": true,
	"extends": [
		"wikimedia/selenium"
	]
}

tests/selenium/README.md

# Selenium tests

For more information see https://www.mediawiki.org/wiki/Selenium

## Setup

See https://www.mediawiki.org/wiki/MediaWiki-Docker/Extension/Examples

## Run all specs

    npm run selenium-test

## Run specific tests

Filter by file name:

    npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME]

Filter by file name and test name:

    npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME] --mochaOpts.grep [TEST-NAME]

tests/selenium/wdio.conf.js

'use strict';

const { config } = require( 'wdio-mediawiki/wdio-defaults.conf.js' );

exports.config = { ...config
	// Override, or add to, the setting from wdio-mediawiki.
	// Learn more at https://webdriver.io/docs/configurationfile/
	//
	// Example:
	// logLevel: 'info',
};