2018-04-10 21:19:08 +00:00
|
|
|
const assert = require( 'assert' ),
|
2019-06-06 11:33:54 +00:00
|
|
|
MWBot = require( 'mwbot' ),
|
2019-04-05 21:09:47 +00:00
|
|
|
Api = require( 'wdio-mediawiki/Api' ),
|
2019-04-08 21:11:33 +00:00
|
|
|
ArticlePageWithOverlay = require( '../support/pages/article_page_with_overlay' ),
|
2019-06-06 11:33:54 +00:00
|
|
|
{ ArticlePage, UserLoginPage } = require( '../support/world.js' );
|
2019-04-05 21:09:47 +00:00
|
|
|
|
2019-04-08 21:11:33 +00:00
|
|
|
const waitForPropagation = ( timeMs ) => {
|
|
|
|
// wait 2 seconds so the change can propogate.
|
|
|
|
const d = new Date();
|
|
|
|
browser.waitUntil( () => new Date() - d > timeMs );
|
|
|
|
};
|
|
|
|
|
2019-04-05 21:09:47 +00:00
|
|
|
const createPages = ( pages ) => {
|
|
|
|
const summary = 'edit by selenium test';
|
2019-05-18 07:49:41 +00:00
|
|
|
browser.call( () => {
|
2019-06-06 11:33:54 +00:00
|
|
|
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; } );
|
2019-05-18 07:49:41 +00:00
|
|
|
} );
|
2019-04-05 21:09:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const createPage = ( title, wikitext ) => {
|
2019-05-07 16:14:52 +00:00
|
|
|
browser.call( () => Api.edit( title, wikitext ) );
|
2019-04-05 21:09:47 +00:00
|
|
|
};
|
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 ) => {
|
2019-05-07 16:14:52 +00:00
|
|
|
browser.call( () =>
|
|
|
|
createPage( title, 'Page created by Selenium browser test.' )
|
|
|
|
);
|
|
|
|
// wait 2 seconds so the change can propogate.
|
|
|
|
waitForPropagation( 2000 );
|
2019-04-05 21:09:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const iAmOnAPageThatDoesNotExist = () => {
|
|
|
|
return iAmOnPage( `NewPage ${new Date()}` );
|
|
|
|
};
|
|
|
|
|
|
|
|
const iShouldSeeAToastNotification = () => {
|
|
|
|
ArticlePage.notification_element.waitForVisible();
|
|
|
|
};
|
|
|
|
|
2019-04-08 23:45:11 +00:00
|
|
|
const iShouldSeeAToastNotificationWithMessage = ( msg ) => {
|
|
|
|
iShouldSeeAToastNotification();
|
|
|
|
const notificationBody = ArticlePage.notification_element.element( '.mw-notification-content' );
|
|
|
|
assert.strictEqual( notificationBody.getText().indexOf( msg ) > -1, true );
|
|
|
|
};
|
|
|
|
|
2019-04-08 21:11:33 +00:00
|
|
|
const iClickTheBrowserBackButton = () => {
|
|
|
|
browser.back();
|
|
|
|
};
|
|
|
|
|
|
|
|
const iClickTheOverlayCloseButton = () => {
|
|
|
|
waitForPropagation( 2000 );
|
|
|
|
ArticlePageWithOverlay.overlay_close_element.click();
|
|
|
|
};
|
|
|
|
|
|
|
|
const iSeeAnOverlay = () => {
|
|
|
|
ArticlePageWithOverlay.overlay_element.waitForVisible();
|
|
|
|
assert.strictEqual( ArticlePageWithOverlay.overlay_element.isVisible(), true );
|
|
|
|
};
|
|
|
|
|
|
|
|
const iDoNotSeeAnOverlay = () => {
|
2019-04-08 23:45:11 +00:00
|
|
|
waitForPropagation( 5000 );
|
2019-04-08 21:11:33 +00:00
|
|
|
browser.waitUntil( () => !ArticlePageWithOverlay.overlay_element.isVisible() );
|
|
|
|
assert.strictEqual( ArticlePageWithOverlay.overlay_element.isVisible(), false );
|
|
|
|
};
|
|
|
|
|
2019-04-08 23:45:11 +00:00
|
|
|
const iAmUsingMobileScreenResolution = () => {
|
|
|
|
browser.setViewportSize( { width: 320, height: 480 }, true );
|
|
|
|
};
|
|
|
|
|
2018-04-10 21:19:08 +00:00
|
|
|
module.exports = {
|
2019-04-08 21:11:33 +00:00
|
|
|
waitForPropagation,
|
2019-04-08 23:45:11 +00:00
|
|
|
iAmUsingMobileScreenResolution,
|
2019-04-08 21:11:33 +00:00
|
|
|
iSeeAnOverlay, iDoNotSeeAnOverlay,
|
|
|
|
iClickTheOverlayCloseButton,
|
|
|
|
iClickTheBrowserBackButton,
|
2019-04-05 21:09:47 +00:00
|
|
|
createPage, createPages,
|
|
|
|
pageExists, iAmOnAPageThatDoesNotExist, iShouldSeeAToastNotification,
|
2019-04-08 23:45:11 +00:00
|
|
|
iShouldSeeAToastNotificationWithMessage,
|
2018-04-10 21:19:08 +00:00
|
|
|
iAmLoggedIntoTheMobileWebsite,
|
|
|
|
iAmUsingTheMobileSite,
|
|
|
|
iAmLoggedIn, iAmOnPage, iAmInBetaMode
|
|
|
|
};
|