Selenium/Node.js/Simple

From MediaWiki.org
< Selenium‎ | Node.js(Redirected from Selenium/Node.js/Write)
Jump to navigation Jump to search

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

A similar example is available as 5 and 17 minute videos. For more examples see Selenium/Node.js/Typical page and Selenium/Node.js#examples.

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

Code[edit]

Following code is available at gerrit:345378.

A new test file should be created:

tests/selenium/specs/specialpages.js

const assert = require( 'assert' ),
	SpecialPages = require( '../pageobjects/specialpages.page' );

describe( 'Special:SpecialPages', function () {
	it( 'should not have Edit link', function () {
		SpecialPages.open();
		assert( !SpecialPages.edit.isExisting() );
	} );
} );

A new page object file should be created:

tests/selenium/pageobjects/specialpages.page.js

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

class SpecialPages extends Page {

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

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

}
module.exports = new SpecialPages();

Output[edit]

Run Chromedriver in one terminal window or tab:

$ chromedriver --url-base=wd/hub --port=4444

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

$ npm run selenium-test

To run just the new test file, run this:

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