Jump to content

Selenium/Getting Started/Create a simple test

From mediawiki.org

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. For more examples see Selenium/How-to/Create the first test in a repository page and Selenium/Reference/Example Code.

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

[edit]

A new test file should be created:

tests/selenium/specs/specialpages.js

'use strict';

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

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

A new page object file should be created:

tests/selenium/pageobjects/specialpages.page.js

'use strict';

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

class SpecialPages extends Page {

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

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

}
module.exports = new SpecialPages();

Run Selenium tests

[edit]

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/specs/specialpages.js