Selenium/Getting Started/Create a simple test

This tutorial will assume that you are running tests from your machine, targeting MediaWiki-Docker. A similar example is available as 5 and 17 minute videos.

Let's write a new simple test for MediaWiki Core. For example, Special:SpecialPages is one of the rare pages that does not have an Edit link. Let's write a test to check that.

Code

A new page object file describing the page we are testing should be created.

tests/selenium/docs/Create_a_simple_test/pageobjects/specialpages.page.js

import Page from 'wdio-mediawiki/Page.js';

class SpecialPages extends Page {

	get edit() {
		return $( '#ca-edit a[accesskey="e"]' );
	}

	async open() {
		return super.openTitle( 'Special:SpecialPages' );
	}

}
export default new SpecialPages();

A new test file should be created. The file is using the page object file we just created.

tests/selenium/docs/Create_a_simple_test/specs/specialpages.js

import SpecialPages from '../pageobjects/specialpages.page.js';

describe( 'Special:SpecialPages', () => {
	it( 'should not have Edit link', async () => {
		await SpecialPages.open();
		await expect( SpecialPages.edit ).not.toExist();
	} );
} );

Run Selenium tests

To run all tests, run this from MediaWiki Core folder:

npm run selenium-test

To run just the new test file:

npm run selenium-test -- --spec tests/selenium/docs/Create_a_simple_test/specs/specialpages.js

More information

Category:Selenium/Node.js
Category:Selenium/Node.js