From 7aee98758a97cde1e111297b2e3706544d3fe2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDeljko=20Filipin?= Date: Mon, 19 Dec 2016 17:39:29 +0100 Subject: Selenium tests in Node.js using WebdriverIO Introduce the WebdriverIO browser testing framework driven by Node.js. The overall intents are: * have MediaWiki core to provide a platform to run tests that is shared between core and the extensions. * phase out ruby driven browser tests eventually. Code is namespaced in sub directory /tests/selenium The 'pages' sub directory provides helper representing a MediaWiki page such as Special:Login and human friendly helpers to interact with the elements. Add Grunt task webdriver:test. Provide a npm script to easily spawn/dispose chromedriver and run above grunt task. wdio.conf.js provides all the configuration. It defaults to point to a MediaWiki-Vagrant installation on http://127.0.0.1:8080. Can be overriden with environment settings as needed. glob patterns (specs) are made absolute paths from MediaWiki root path that let us run the tests either from the root path (eg the npm wrapper or from the tests/selenium directory when invoking wdio directly. wdio assumes they are relative to the current working directory, hence the normalization. wdio.conf.jenkins.js extends the configuration and is used solely for Jenkins. The switch is done from the Gruntfile.js whenever JENKINS_HOME is set. Specially we want junit reports to be generated. Provide a more specific eslint configuration. References: * MALU https://phabricator.wikimedia.org/source/malu/ * T151442 Research WebdriverIO * T151443 Research Nightwatch.js Bug: T139740 Signed-off-by: Antoine Musso Change-Id: Ibe7a004a120e82af637ab3e31b725de743134c99 --- tests/selenium/specs/page.js | 54 ++++++++++++++++++++++++++++++++++++++++ tests/selenium/specs/user.js | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tests/selenium/specs/page.js create mode 100644 tests/selenium/specs/user.js (limited to 'tests/selenium/specs') diff --git a/tests/selenium/specs/page.js b/tests/selenium/specs/page.js new file mode 100644 index 000000000000..da80aafe2342 --- /dev/null +++ b/tests/selenium/specs/page.js @@ -0,0 +1,54 @@ +'use strict'; +const assert = require( 'assert' ), + HistoryPage = require( '../pageobjects/history.page' ), + EditPage = require( '../pageobjects/edit.page' ); + +describe( 'Page', function () { + + var content, + name; + + beforeEach( function () { + content = Math.random().toString(); + name = Math.random().toString(); + } ); + + it( 'should be creatable', function () { + + // create + EditPage.edit( name, content ); + + // check + assert.equal( EditPage.heading.getText(), name ); + assert.equal( EditPage.displayedContent.getText(), content ); + + } ); + + it( 'should be editable', function () { + + var content2 = Math.random().toString(); + + // create + EditPage.edit( name, content ); + + // edit + EditPage.edit( name, content2 ); + + // check content + assert.equal( EditPage.heading.getText(), name ); + assert.equal( EditPage.displayedContent.getText(), content2 ); + + } ); + + it( 'should have history', function () { + + // create + EditPage.edit( name, content ); + + // check + HistoryPage.open( name ); + assert.equal( HistoryPage.comment.getText(), `(Created page with "${content}")` ); + + } ); + +} ); diff --git a/tests/selenium/specs/user.js b/tests/selenium/specs/user.js new file mode 100644 index 000000000000..6746c5b5d91a --- /dev/null +++ b/tests/selenium/specs/user.js @@ -0,0 +1,59 @@ +'use strict'; +const assert = require( 'assert' ), + CreateAccountPage = require( '../pageobjects/createaccount.page' ), + UserLoginPage = require( '../pageobjects/userlogin.page' ), + UserLogoutPage = require( '../pageobjects/userlogout.page' ), + PreferencesPage = require( '../pageobjects/preferences.page' ); + +describe( 'User', function () { + + var password, + username; + + beforeEach( function () { + username = `User-${Math.random().toString()}`; + password = Math.random().toString(); + } ); + + it( 'should be able to create account', function () { + + // create + CreateAccountPage.createAccount( username, password ); + + // check + assert.equal( CreateAccountPage.heading.getText(), `Welcome, ${username}!` ); + + } ); + + it( 'should be able to log in', function () { + + // create + CreateAccountPage.createAccount( username, password ); + + // logout + UserLogoutPage.open(); + + // log in + UserLoginPage.login( username, password ); + + // check + assert.equal( UserLoginPage.userPage.getText(), username ); + + } ); + + it( 'should be able to change preferences', function () { + + var realName = Math.random().toString(); + + // create + CreateAccountPage.createAccount( username, password ); + + // change real name + PreferencesPage.changeRealName( realName ); + + // check + assert.equal( PreferencesPage.realName.getValue(), realName ); + + } ); + +} ); -- cgit v1.2.3