Ensure each api call creates a new instance of MWBot
As a hold-over from a previous porting attempt, thw World.js file (a cucumber.js convention) exported an instance of MWBot. This instance was used in several tests, however, since MWBot had been instantiated multiple times since then, the original edit token was invalid, causing several tests to fail. Bug: T224947 Change-Id: I56c06600c43d53bbc4e103d446a1de7a52c2cfad
This commit is contained in:
parent
11c4309193
commit
018d436bfe
|
@ -1,7 +1,8 @@
|
|||
const assert = require( 'assert' ),
|
||||
MWBot = require( 'mwbot' ),
|
||||
Api = require( 'wdio-mediawiki/Api' ),
|
||||
ArticlePageWithOverlay = require( '../support/pages/article_page_with_overlay' ),
|
||||
{ ArticlePage, UserLoginPage, api } = require( '../support/world.js' );
|
||||
{ ArticlePage, UserLoginPage } = require( '../support/world.js' );
|
||||
|
||||
const waitForPropagation = ( timeMs ) => {
|
||||
// wait 2 seconds so the change can propogate.
|
||||
|
@ -9,32 +10,30 @@ const waitForPropagation = ( timeMs ) => {
|
|||
browser.waitUntil( () => new Date() - d > timeMs );
|
||||
};
|
||||
|
||||
const login = () => {
|
||||
return api.loginGetEditToken( {
|
||||
username: browser.options.username,
|
||||
password: browser.options.password,
|
||||
apiUrl: `${browser.options.baseUrl}/api.php`
|
||||
} );
|
||||
};
|
||||
|
||||
const createPages = ( pages ) => {
|
||||
const summary = 'edit by selenium test';
|
||||
browser.call( () => login() );
|
||||
browser.call( () => {
|
||||
return api.batch(
|
||||
pages.map( ( page ) => [ 'create' ].concat( page ).concat( [ summary ] ) )
|
||||
).catch( ( err ) => {
|
||||
if ( err.code === 'articleexists' ) {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
} );
|
||||
|
||||
const bot = new MWBot();
|
||||
return bot.loginGetEditToken( {
|
||||
username: browser.options.username,
|
||||
password: browser.options.password,
|
||||
apiUrl: `${browser.options.baseUrl}/api.php`
|
||||
} )
|
||||
.then( () => {
|
||||
return bot.batch(
|
||||
pages.map( ( page ) => [ 'create' ].concat( page ).concat( [ summary ] ) )
|
||||
).catch( ( err ) => {
|
||||
if ( err.code === 'articleexists' ) {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
} );
|
||||
} )
|
||||
.catch( ( err ) => { throw err; } );
|
||||
} );
|
||||
};
|
||||
|
||||
const createPage = ( title, wikitext ) => {
|
||||
browser.call( () => login() );
|
||||
browser.call( () => Api.edit( title, wikitext ) );
|
||||
};
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
const { api, ArticlePage } = require( '../support/world' );
|
||||
const RunJobs = require( 'wdio-mediawiki/RunJobs' );
|
||||
const Api = require( 'wdio-mediawiki/Api' );
|
||||
const Page = require( 'wdio-mediawiki/Page' );
|
||||
const {
|
||||
iAmOnPage,
|
||||
waitForPropagation,
|
||||
createPages,
|
||||
createPage
|
||||
} = require( './common_steps' );
|
||||
const { ArticlePage } = require( '../support/world' ),
|
||||
RunJobs = require( 'wdio-mediawiki/RunJobs' ),
|
||||
Api = require( 'wdio-mediawiki/Api' ),
|
||||
Page = require( 'wdio-mediawiki/Page' ),
|
||||
MWBot = require( 'mwbot' ),
|
||||
{
|
||||
iAmOnPage,
|
||||
waitForPropagation,
|
||||
createPages,
|
||||
createPage
|
||||
} = require( './common_steps' );
|
||||
|
||||
const iAmInAWikiThatHasCategories = ( title ) => {
|
||||
const msg = 'This page is used by Selenium to test category related features.',
|
||||
|
@ -45,15 +46,19 @@ const iAmOnAPageThatHasTheFollowingEdits = function ( table ) {
|
|||
edits = table.rawTable.map( ( row, i ) =>
|
||||
[ i === 0 ? 'create' : 'edit', pageTitle, row[ 0 ] ] );
|
||||
|
||||
api.loginGetEditToken( {
|
||||
username: browser.options.username,
|
||||
password: browser.options.password,
|
||||
apiUrl: `${browser.options.baseUrl}/api.php`
|
||||
} )
|
||||
.then( () => api.batch( edits ) )
|
||||
.then( () => ArticlePage.open( pageTitle ) )
|
||||
.catch( ( err ) => { throw err; } );
|
||||
waitForPropagation( 5000 );
|
||||
browser.call( () => {
|
||||
const bot = new MWBot();
|
||||
return bot.loginGetEditToken( {
|
||||
username: browser.options.username,
|
||||
password: browser.options.password,
|
||||
apiUrl: `${browser.options.baseUrl}/api.php`
|
||||
} )
|
||||
.then( () => bot.batch( edits ) )
|
||||
.catch( ( err ) => { throw err; } );
|
||||
} );
|
||||
|
||||
browser.call( () => RunJobs.run() );
|
||||
ArticlePage.open( pageTitle );
|
||||
};
|
||||
|
||||
const iGoToAPageThatHasLanguages = () => {
|
||||
|
|
|
@ -15,13 +15,10 @@
|
|||
* allowing us to use the dependencies across scenarios.
|
||||
*/
|
||||
|
||||
const MwBot = require( 'mwbot' ),
|
||||
mwCorePages = require( '../support/pages/mw_core_pages' ),
|
||||
const mwCorePages = require( '../support/pages/mw_core_pages' ),
|
||||
minervaPages = require( '../support/pages/minerva_pages' );
|
||||
|
||||
function MinervaWorld() {
|
||||
/* dependencies */
|
||||
this.api = new MwBot();
|
||||
/* pageObjects */
|
||||
Object.assign( this, mwCorePages );
|
||||
Object.assign( this, minervaPages );
|
||||
|
|
Loading…
Reference in New Issue