2018-04-10 21:19:08 +00:00
|
|
|
const assert = require( 'assert' ),
|
2019-04-05 21:09:47 +00:00
|
|
|
Api = require( 'wdio-mediawiki/Api' ),
|
|
|
|
{ ArticlePage, UserLoginPage, api } = require( '../support/world.js' );
|
|
|
|
|
|
|
|
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';
|
|
|
|
return login().then( () =>
|
|
|
|
api.batch(
|
|
|
|
pages.map( ( page ) => [ 'create' ].concat( page ).concat( [ summary ] ) )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const createPage = ( title, wikitext ) => {
|
|
|
|
return login().then( () => Api.edit( title, wikitext ) );
|
|
|
|
};
|
2018-04-10 21:19:08 +00:00
|
|
|
|
|
|
|
const iAmUsingTheMobileSite = () => {
|
|
|
|
ArticlePage.setMobileMode();
|
|
|
|
};
|
|
|
|
|
|
|
|
const iAmInBetaMode = () => {
|
|
|
|
ArticlePage.setBetaMode();
|
|
|
|
};
|
|
|
|
|
|
|
|
const iAmOnPage = ( article ) => {
|
|
|
|
ArticlePage.open( article );
|
2019-04-05 21:09:47 +00:00
|
|
|
// Make sure the article opened and JS loaded.
|
|
|
|
ArticlePage.waitUntilResourceLoaderModuleReady( 'skins.minerva.scripts' );
|
2018-04-10 21:19:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const iAmLoggedIn = () => {
|
|
|
|
UserLoginPage.open();
|
|
|
|
UserLoginPage.loginAdmin();
|
|
|
|
assert.strictEqual( ArticlePage.is_authenticated_element.isExisting(), true );
|
|
|
|
};
|
|
|
|
|
|
|
|
const iAmLoggedIntoTheMobileWebsite = () => {
|
|
|
|
iAmUsingTheMobileSite();
|
|
|
|
iAmLoggedIn();
|
|
|
|
};
|
|
|
|
|
2019-04-05 21:09:47 +00:00
|
|
|
const pageExists = ( title ) => {
|
|
|
|
return createPage( title, 'Page created by Selenium browser test.' ).then( () => {
|
|
|
|
const d = new Date();
|
|
|
|
// wait 2 seconds so the change can propogate.
|
|
|
|
browser.waitUntil( () => new Date() - d > 2000 );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
const iAmOnAPageThatDoesNotExist = () => {
|
|
|
|
return iAmOnPage( `NewPage ${new Date()}` );
|
|
|
|
};
|
|
|
|
|
|
|
|
const iShouldSeeAToastNotification = () => {
|
|
|
|
ArticlePage.notification_element.waitForVisible();
|
|
|
|
};
|
|
|
|
|
2018-04-10 21:19:08 +00:00
|
|
|
module.exports = {
|
2019-04-05 21:09:47 +00:00
|
|
|
createPage, createPages,
|
|
|
|
pageExists, iAmOnAPageThatDoesNotExist, iShouldSeeAToastNotification,
|
2018-04-10 21:19:08 +00:00
|
|
|
iAmLoggedIntoTheMobileWebsite,
|
|
|
|
iAmUsingTheMobileSite,
|
|
|
|
iAmLoggedIn, iAmOnPage, iAmInBetaMode
|
|
|
|
};
|