selenium: Fix inefficient use of MWBot in specs/page.js

This test previously took 4 minutes to run locally and ended up
running the MWBot.login process 9 times.

After this, the specs/page tests only log-in once.

Bug: T234002
Change-Id: I374620a01f49d4da559070d0982bdbe4c1269e2e
This commit is contained in:
Timo Tijhof 2019-09-29 04:24:47 +01:00
parent 3845dba69e
commit 058d5b7cd8

View file

@ -10,13 +10,13 @@ const assert = require( 'assert' ),
Util = require( 'wdio-mediawiki/Util' ); Util = require( 'wdio-mediawiki/Util' );
describe( 'Page', function () { describe( 'Page', function () {
var content, var content, name, bot;
name;
before( function () { before( async function () {
// disable VisualEditor welcome dialog // disable VisualEditor welcome dialog
BlankPage.open(); BlankPage.open();
browser.setLocalStorage( 've-beta-welcome-dialog', '1' ); browser.setLocalStorage( 've-beta-welcome-dialog', '1' );
bot = await Api.bot();
} ); } );
beforeEach( function () { beforeEach( function () {
@ -46,17 +46,13 @@ describe( 'Page', function () {
it( 'should be re-creatable', function () { it( 'should be re-creatable', function () {
const initialContent = Util.getTestString( 'initialContent-' ); const initialContent = Util.getTestString( 'initialContent-' );
// create // create and delete
browser.call( function () { browser.call( async () => {
return Api.edit( name, initialContent ); await bot.edit( name, initialContent, 'create for delete' );
await bot.delete( name, 'delete prior to recreate' );
} ); } );
// delete // re-create
browser.call( function () {
return Api.delete( name, 'delete prior to recreate' );
} );
// create
EditPage.edit( name, content ); EditPage.edit( name, content );
// check // check
@ -66,8 +62,8 @@ describe( 'Page', function () {
it( 'should be editable @daily', function () { it( 'should be editable @daily', function () {
// create // create
browser.call( function () { browser.call( async () => {
return Api.edit( name, content ); await bot.edit( name, content, 'create for edit' );
} ); } );
// edit // edit
@ -81,26 +77,26 @@ describe( 'Page', function () {
it( 'should have history @daily', function () { it( 'should have history @daily', function () {
// create // create
browser.call( function () { browser.call( async () => {
return Api.edit( name, content ); await bot.edit( name, content, `created with "${content}"` );
} ); } );
// check // check
HistoryPage.open( name ); HistoryPage.open( name );
assert.strictEqual( HistoryPage.comment.getText(), `Created or updated page with "${content}"` ); assert.strictEqual( HistoryPage.comment.getText(), `created with "${content}"` );
} ); } );
it( 'should be deletable', function () { it( 'should be deletable', function () {
// create
browser.call( async () => {
await bot.edit( name, content, 'create for delete' );
} );
// login // login
UserLoginPage.loginAdmin(); UserLoginPage.loginAdmin();
// create
browser.call( function () {
return Api.edit( name, content );
} );
// delete // delete
DeletePage.delete( name, content + '-deletereason' ); DeletePage.delete( name, 'delete reason' );
// check // check
assert.strictEqual( assert.strictEqual(
@ -110,40 +106,32 @@ describe( 'Page', function () {
} ); } );
it( 'should be restorable', function () { it( 'should be restorable', function () {
// create and delete
browser.call( async () => {
await bot.edit( name, content, 'create for delete' );
await bot.delete( name, 'delete for restore' );
} );
// login // login
UserLoginPage.loginAdmin(); UserLoginPage.loginAdmin();
// create
browser.call( function () {
return Api.edit( name, content );
} );
// delete
browser.call( function () {
return Api.delete( name, content + '-deletereason' );
} );
// restore // restore
RestorePage.restore( name, content + '-restorereason' ); RestorePage.restore( name, 'restore reason' );
// check // check
assert.strictEqual( RestorePage.displayedContent.getText(), name + ' has been restored\nConsult the deletion log for a record of recent deletions and restorations.' ); assert.strictEqual( RestorePage.displayedContent.getText(), name + ' has been restored\nConsult the deletion log for a record of recent deletions and restorations.' );
} ); } );
it( 'should be undoable', function () { it( 'should be undoable', function () {
// create
browser.call( function () {
return Api.edit( name, content );
} );
// edit
let previousRev, undoRev; let previousRev, undoRev;
browser.call( function () { browser.call( async () => {
return Api.edit( name, Util.getTestString( 'editContent-' ) ) // create
.then( ( response ) => { await bot.edit( name, content, 'create to edit and undo' );
previousRev = response.edit.oldrevid;
undoRev = response.edit.newrevid; // edit
} ); const response = await bot.edit( name, Util.getTestString( 'editContent-' ) );
previousRev = response.edit.oldrevid;
undoRev = response.edit.newrevid;
} ); } );
UndoPage.undo( name, previousRev, undoRev ); UndoPage.undo( name, previousRev, undoRev );