Merge "Ensure each api call creates a new instance of MWBot"

This commit is contained in:
jenkins-bot 2019-06-06 19:55:53 +00:00 committed by Gerrit Code Review
commit 129de0821d
3 changed files with 44 additions and 43 deletions

View file

@ -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 ) );
};

View file

@ -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 = () => {

View file

@ -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 );