2020-06-02 21:21:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
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.
|
2019-07-09 18:08:02 +00:00
|
|
|
// Replace this with a more dynamic statement.
|
|
|
|
browser.pause( timeMs );
|
2019-04-08 21:11:33 +00:00
|
|
|
};
|
|
|
|
|
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 ) => {
|
2020-06-15 14:54:05 +00:00
|
|
|
browser.call( async () => {
|
|
|
|
const bot = await Api.bot();
|
|
|
|
await bot.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
|
|
|
};
|
|
|
|
|
2019-12-17 19:31:52 +00:00
|
|
|
const pageExistsWithText = ( title, text ) => {
|
|
|
|
browser.call( () =>
|
|
|
|
createPage( title, text )
|
|
|
|
);
|
|
|
|
// 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 = () => {
|
2020-06-15 14:54:05 +00:00
|
|
|
ArticlePage.notification_element.waitForDisplayed();
|
2019-04-05 21:09:47 +00:00
|
|
|
};
|
|
|
|
|
2019-04-08 23:45:11 +00:00
|
|
|
const iShouldSeeAToastNotificationWithMessage = ( msg ) => {
|
|
|
|
iShouldSeeAToastNotification();
|
2020-06-15 14:54:05 +00:00
|
|
|
const notificationBody = ArticlePage.notification_element.$( '.mw-notification-content' );
|
2021-11-09 14:48:40 +00:00
|
|
|
assert.strictEqual( notificationBody.getText().includes( msg ), true );
|
2019-04-08 23:45:11 +00:00
|
|
|
};
|
|
|
|
|
2019-04-08 21:11:33 +00:00
|
|
|
const iClickTheBrowserBackButton = () => {
|
|
|
|
browser.back();
|
|
|
|
};
|
|
|
|
|
|
|
|
const iClickTheOverlayCloseButton = () => {
|
|
|
|
waitForPropagation( 2000 );
|
|
|
|
ArticlePageWithOverlay.overlay_close_element.click();
|
|
|
|
};
|
|
|
|
|
|
|
|
const iSeeAnOverlay = () => {
|
2020-06-15 14:54:05 +00:00
|
|
|
ArticlePageWithOverlay.overlay_element.waitForDisplayed();
|
|
|
|
assert.strictEqual( ArticlePageWithOverlay.overlay_element.isDisplayed(), true );
|
2019-04-08 21:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const iDoNotSeeAnOverlay = () => {
|
2019-04-08 23:45:11 +00:00
|
|
|
waitForPropagation( 5000 );
|
2020-06-15 14:54:05 +00:00
|
|
|
browser.waitUntil( () => !ArticlePageWithOverlay.overlay_element.isDisplayed() );
|
|
|
|
assert.strictEqual( ArticlePageWithOverlay.overlay_element.isDisplayed(), false );
|
2019-04-08 21:11:33 +00:00
|
|
|
};
|
|
|
|
|
2019-04-08 23:45:11 +00:00
|
|
|
const iAmUsingMobileScreenResolution = () => {
|
2020-06-15 14:54:05 +00:00
|
|
|
browser.setWindowSize( 320, 480 );
|
2019-04-08 23:45:11 +00:00
|
|
|
};
|
|
|
|
|
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,
|
2019-12-17 19:31:52 +00:00
|
|
|
pageExistsWithText,
|
2019-04-05 21:09:47 +00:00
|
|
|
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
|
|
|
|
};
|