Create users and pages for Selenium tests using action API
This will make tests slightly more robust. Bug: T164721 Bug: T167502 Change-Id: I9b2fea77b28af4f7f521490a0105e7d04730bc87
This commit is contained in:
parent
8e185ecb2b
commit
853cba1deb
8 changed files with 105 additions and 29 deletions
|
|
@ -24,6 +24,7 @@
|
|||
"karma-firefox-launcher": "1.0.1",
|
||||
"karma-mocha-reporter": "2.2.3",
|
||||
"karma-qunit": "1.0.0",
|
||||
"nodemw": "0.10.1",
|
||||
"qunitjs": "1.23.1",
|
||||
"stylelint-config-wikimedia": "0.4.1",
|
||||
"wdio-junit-reporter": "0.2.0",
|
||||
|
|
|
|||
|
|
@ -10,5 +10,8 @@
|
|||
},
|
||||
"globals": {
|
||||
"browser": false
|
||||
},
|
||||
"rules":{
|
||||
"no-console":0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ To run only one file (for example page.js), you first need to spawn the chromedr
|
|||
|
||||
Then in another terminal:
|
||||
|
||||
cd mediawiki/tests/selenium
|
||||
../../node_modules/.bin/wdio --spec page.js
|
||||
cd tests/selenium
|
||||
../../node_modules/.bin/wdio --spec specs/page.js
|
||||
|
||||
The runner reads the config file `wdio.conf.js` and runs the spec listed in
|
||||
`page.js`.
|
||||
|
|
|
|||
|
|
@ -21,5 +21,57 @@ class CreateAccountPage extends Page {
|
|||
this.create.click();
|
||||
}
|
||||
|
||||
apiCreateAccount( username, password ) {
|
||||
const url = require( 'url' ), // https://nodejs.org/docs/latest/api/url.html
|
||||
baseUrl = url.parse( browser.options.baseUrl ), // http://webdriver.io/guide/testrunner/browserobject.html
|
||||
Bot = require( 'nodemw' ), // https://github.com/macbre/nodemw
|
||||
client = new Bot( {
|
||||
protocol: baseUrl.protocol,
|
||||
server: baseUrl.hostname,
|
||||
port: baseUrl.port,
|
||||
path: baseUrl.path,
|
||||
debug: false
|
||||
} );
|
||||
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
client.api.call(
|
||||
{
|
||||
action: 'query',
|
||||
meta: 'tokens',
|
||||
type: 'createaccount'
|
||||
},
|
||||
/**
|
||||
* @param {Error|null} err
|
||||
* @param {Object} info Processed query result
|
||||
* @param {Object} next More results?
|
||||
* @param {Object} data Raw data
|
||||
*/
|
||||
function ( err, info, next, data ) {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
return;
|
||||
}
|
||||
client.api.call( {
|
||||
action: 'createaccount',
|
||||
createreturnurl: browser.options.baseUrl,
|
||||
createtoken: data.query.tokens.createaccounttoken,
|
||||
username: username,
|
||||
password: password,
|
||||
retype: password
|
||||
}, function ( err ) {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
}, 'POST' );
|
||||
},
|
||||
'POST'
|
||||
);
|
||||
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
module.exports = new CreateAccountPage();
|
||||
|
|
|
|||
|
|
@ -8,15 +8,37 @@ class EditPage extends Page {
|
|||
get heading() { return browser.element( '#firstHeading' ); }
|
||||
get save() { return browser.element( '#wpSave' ); }
|
||||
|
||||
open( name ) {
|
||||
openForEditing( name ) {
|
||||
super.open( name + '&action=edit' );
|
||||
}
|
||||
|
||||
edit( name, content ) {
|
||||
this.open( name );
|
||||
this.openForEditing( name );
|
||||
this.content.setValue( content );
|
||||
this.save.click();
|
||||
}
|
||||
|
||||
apiEdit( name, content ) {
|
||||
const url = require( 'url' ), // https://nodejs.org/docs/latest/api/url.html
|
||||
baseUrl = url.parse( browser.options.baseUrl ), // http://webdriver.io/guide/testrunner/browserobject.html
|
||||
Bot = require( 'nodemw' ), // https://github.com/macbre/nodemw
|
||||
client = new Bot( {
|
||||
protocol: baseUrl.protocol,
|
||||
server: baseUrl.hostname,
|
||||
port: baseUrl.port,
|
||||
path: baseUrl.path,
|
||||
debug: false
|
||||
} );
|
||||
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
client.edit( name, content, `Created page with "${content}"`, function ( err ) {
|
||||
if ( err ) {
|
||||
return reject( err );
|
||||
}
|
||||
resolve();
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
module.exports = new EditPage();
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
const Page = require( './page' );
|
||||
|
||||
class UserLogoutPage extends Page {
|
||||
|
||||
open() {
|
||||
super.open( 'Special:UserLogout' );
|
||||
}
|
||||
|
||||
}
|
||||
module.exports = new UserLogoutPage();
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
const assert = require( 'assert' ),
|
||||
HistoryPage = require( '../pageobjects/history.page' ),
|
||||
EditPage = require( '../pageobjects/edit.page' );
|
||||
EditPage = require( '../pageobjects/edit.page' ),
|
||||
HistoryPage = require( '../pageobjects/history.page' );
|
||||
|
||||
describe( 'Page', function () {
|
||||
|
||||
|
|
@ -9,6 +9,7 @@ describe( 'Page', function () {
|
|||
name;
|
||||
|
||||
beforeEach( function () {
|
||||
browser.deleteCookie();
|
||||
content = Math.random().toString();
|
||||
name = Math.random().toString();
|
||||
} );
|
||||
|
|
@ -29,12 +30,14 @@ describe( 'Page', function () {
|
|||
var content2 = Math.random().toString();
|
||||
|
||||
// create
|
||||
EditPage.edit( name, content );
|
||||
browser.call( function () {
|
||||
return EditPage.apiEdit( name, content );
|
||||
} );
|
||||
|
||||
// edit
|
||||
EditPage.edit( name, content2 );
|
||||
|
||||
// check content
|
||||
// check
|
||||
assert.equal( EditPage.heading.getText(), name );
|
||||
assert.equal( EditPage.displayedContent.getText(), content2 );
|
||||
|
||||
|
|
@ -43,7 +46,9 @@ describe( 'Page', function () {
|
|||
it( 'should have history', function () {
|
||||
|
||||
// create
|
||||
EditPage.edit( name, content );
|
||||
browser.call( function () {
|
||||
return EditPage.apiEdit( name, content );
|
||||
} );
|
||||
|
||||
// check
|
||||
HistoryPage.open( name );
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
'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' );
|
||||
PreferencesPage = require( '../pageobjects/preferences.page' ),
|
||||
UserLoginPage = require( '../pageobjects/userlogin.page' );
|
||||
|
||||
describe( 'User', function () {
|
||||
|
||||
|
|
@ -11,6 +10,7 @@ describe( 'User', function () {
|
|||
username;
|
||||
|
||||
beforeEach( function () {
|
||||
browser.deleteCookie();
|
||||
username = `User-${Math.random().toString()}`;
|
||||
password = Math.random().toString();
|
||||
} );
|
||||
|
|
@ -28,10 +28,9 @@ describe( 'User', function () {
|
|||
it( 'should be able to log in', function () {
|
||||
|
||||
// create
|
||||
CreateAccountPage.createAccount( username, password );
|
||||
|
||||
// logout
|
||||
UserLogoutPage.open();
|
||||
browser.call( function () {
|
||||
return CreateAccountPage.apiCreateAccount( username, password );
|
||||
} );
|
||||
|
||||
// log in
|
||||
UserLoginPage.login( username, password );
|
||||
|
|
@ -46,9 +45,14 @@ describe( 'User', function () {
|
|||
var realName = Math.random().toString();
|
||||
|
||||
// create
|
||||
CreateAccountPage.createAccount( username, password );
|
||||
browser.call( function () {
|
||||
return CreateAccountPage.apiCreateAccount( username, password );
|
||||
} );
|
||||
|
||||
// change real name
|
||||
// log in
|
||||
UserLoginPage.login( username, password );
|
||||
|
||||
// change
|
||||
PreferencesPage.changeRealName( realName );
|
||||
|
||||
// check
|
||||
|
|
|
|||
Loading…
Reference in a new issue