mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-13 17:37:07 +00:00
Merge "Ensure each api call creates a new instance of MWBot"
This commit is contained in:
commit
129de0821d
|
@ -1,7 +1,8 @@
|
||||||
const assert = require( 'assert' ),
|
const assert = require( 'assert' ),
|
||||||
|
MWBot = require( 'mwbot' ),
|
||||||
Api = require( 'wdio-mediawiki/Api' ),
|
Api = require( 'wdio-mediawiki/Api' ),
|
||||||
ArticlePageWithOverlay = require( '../support/pages/article_page_with_overlay' ),
|
ArticlePageWithOverlay = require( '../support/pages/article_page_with_overlay' ),
|
||||||
{ ArticlePage, UserLoginPage, api } = require( '../support/world.js' );
|
{ ArticlePage, UserLoginPage } = require( '../support/world.js' );
|
||||||
|
|
||||||
const waitForPropagation = ( timeMs ) => {
|
const waitForPropagation = ( timeMs ) => {
|
||||||
// wait 2 seconds so the change can propogate.
|
// wait 2 seconds so the change can propogate.
|
||||||
|
@ -9,32 +10,30 @@ const waitForPropagation = ( timeMs ) => {
|
||||||
browser.waitUntil( () => new Date() - d > 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 createPages = ( pages ) => {
|
||||||
const summary = 'edit by selenium test';
|
const summary = 'edit by selenium test';
|
||||||
browser.call( () => login() );
|
|
||||||
browser.call( () => {
|
browser.call( () => {
|
||||||
return api.batch(
|
const bot = new MWBot();
|
||||||
pages.map( ( page ) => [ 'create' ].concat( page ).concat( [ summary ] ) )
|
return bot.loginGetEditToken( {
|
||||||
).catch( ( err ) => {
|
username: browser.options.username,
|
||||||
if ( err.code === 'articleexists' ) {
|
password: browser.options.password,
|
||||||
return;
|
apiUrl: `${browser.options.baseUrl}/api.php`
|
||||||
}
|
} )
|
||||||
throw err;
|
.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 ) => {
|
const createPage = ( title, wikitext ) => {
|
||||||
browser.call( () => login() );
|
|
||||||
browser.call( () => Api.edit( title, wikitext ) );
|
browser.call( () => Api.edit( title, wikitext ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
const { api, ArticlePage } = require( '../support/world' );
|
const { ArticlePage } = require( '../support/world' ),
|
||||||
const RunJobs = require( 'wdio-mediawiki/RunJobs' );
|
RunJobs = require( 'wdio-mediawiki/RunJobs' ),
|
||||||
const Api = require( 'wdio-mediawiki/Api' );
|
Api = require( 'wdio-mediawiki/Api' ),
|
||||||
const Page = require( 'wdio-mediawiki/Page' );
|
Page = require( 'wdio-mediawiki/Page' ),
|
||||||
const {
|
MWBot = require( 'mwbot' ),
|
||||||
iAmOnPage,
|
{
|
||||||
waitForPropagation,
|
iAmOnPage,
|
||||||
createPages,
|
waitForPropagation,
|
||||||
createPage
|
createPages,
|
||||||
} = require( './common_steps' );
|
createPage
|
||||||
|
} = require( './common_steps' );
|
||||||
|
|
||||||
const iAmInAWikiThatHasCategories = ( title ) => {
|
const iAmInAWikiThatHasCategories = ( title ) => {
|
||||||
const msg = 'This page is used by Selenium to test category related features.',
|
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 ) =>
|
edits = table.rawTable.map( ( row, i ) =>
|
||||||
[ i === 0 ? 'create' : 'edit', pageTitle, row[ 0 ] ] );
|
[ i === 0 ? 'create' : 'edit', pageTitle, row[ 0 ] ] );
|
||||||
|
|
||||||
api.loginGetEditToken( {
|
browser.call( () => {
|
||||||
username: browser.options.username,
|
const bot = new MWBot();
|
||||||
password: browser.options.password,
|
return bot.loginGetEditToken( {
|
||||||
apiUrl: `${browser.options.baseUrl}/api.php`
|
username: browser.options.username,
|
||||||
} )
|
password: browser.options.password,
|
||||||
.then( () => api.batch( edits ) )
|
apiUrl: `${browser.options.baseUrl}/api.php`
|
||||||
.then( () => ArticlePage.open( pageTitle ) )
|
} )
|
||||||
.catch( ( err ) => { throw err; } );
|
.then( () => bot.batch( edits ) )
|
||||||
waitForPropagation( 5000 );
|
.catch( ( err ) => { throw err; } );
|
||||||
|
} );
|
||||||
|
|
||||||
|
browser.call( () => RunJobs.run() );
|
||||||
|
ArticlePage.open( pageTitle );
|
||||||
};
|
};
|
||||||
|
|
||||||
const iGoToAPageThatHasLanguages = () => {
|
const iGoToAPageThatHasLanguages = () => {
|
||||||
|
|
|
@ -15,13 +15,10 @@
|
||||||
* allowing us to use the dependencies across scenarios.
|
* allowing us to use the dependencies across scenarios.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const MwBot = require( 'mwbot' ),
|
const mwCorePages = require( '../support/pages/mw_core_pages' ),
|
||||||
mwCorePages = require( '../support/pages/mw_core_pages' ),
|
|
||||||
minervaPages = require( '../support/pages/minerva_pages' );
|
minervaPages = require( '../support/pages/minerva_pages' );
|
||||||
|
|
||||||
function MinervaWorld() {
|
function MinervaWorld() {
|
||||||
/* dependencies */
|
|
||||||
this.api = new MwBot();
|
|
||||||
/* pageObjects */
|
/* pageObjects */
|
||||||
Object.assign( this, mwCorePages );
|
Object.assign( this, mwCorePages );
|
||||||
Object.assign( this, minervaPages );
|
Object.assign( this, minervaPages );
|
||||||
|
|
Loading…
Reference in a new issue