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
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const waitForPropagation = async ( timeMs ) => {
|
2019-04-08 21:11:33 +00:00
|
|
|
// wait 2 seconds so the change can propogate.
|
2019-07-09 18:08:02 +00:00
|
|
|
// Replace this with a more dynamic statement.
|
2022-05-07 00:57:25 +00:00
|
|
|
// eslint-disable-next-line wdio/no-pause
|
2023-04-06 22:25:40 +00:00
|
|
|
await 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
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iAmUsingTheMobileSite = async () => {
|
|
|
|
await ArticlePage.setMobileMode();
|
2018-04-10 21:19:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const iAmInBetaMode = () => {
|
|
|
|
ArticlePage.setBetaMode();
|
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iAmOnPage = async ( article ) => {
|
|
|
|
await ArticlePage.open( article );
|
2019-04-05 21:09:47 +00:00
|
|
|
// Make sure the article opened and JS loaded.
|
2023-04-06 22:25:40 +00:00
|
|
|
await ArticlePage.waitUntilResourceLoaderModuleReady( 'skins.minerva.scripts' );
|
2018-04-10 21:19:08 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iAmLoggedIn = async () => {
|
|
|
|
await UserLoginPage.open();
|
|
|
|
await UserLoginPage.loginAdmin();
|
|
|
|
assert.strictEqual( await ArticlePage.is_authenticated_element.isExisting(), true );
|
2018-04-10 21:19:08 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iAmLoggedIntoTheMobileWebsite = async () => {
|
|
|
|
await iAmUsingTheMobileSite();
|
|
|
|
await iAmLoggedIn();
|
2018-04-10 21:19:08 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const pageExists = async ( title ) => {
|
|
|
|
await browser.call( async () =>
|
|
|
|
await createPage( title, 'Page created by Selenium browser test.' )
|
2019-05-07 16:14:52 +00:00
|
|
|
);
|
|
|
|
// wait 2 seconds so the change can propogate.
|
2023-04-06 22:25:40 +00:00
|
|
|
await 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()}` );
|
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iShouldSeeAToastNotification = async () => {
|
|
|
|
await ArticlePage.notification_element.waitForDisplayed();
|
2019-04-05 21:09:47 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iShouldSeeAToastNotificationWithMessage = async ( msg ) => {
|
|
|
|
await iShouldSeeAToastNotification();
|
|
|
|
const notificationBody = await ArticlePage.notification_element.$( '.mw-notification-content' ).getText();
|
|
|
|
assert.strictEqual( await notificationBody.includes( msg ), true );
|
2019-04-08 23:45:11 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iClickTheBrowserBackButton = async () => {
|
|
|
|
await browser.back();
|
2019-04-08 21:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const iClickTheOverlayCloseButton = () => {
|
|
|
|
waitForPropagation( 2000 );
|
2022-02-03 20:18:02 +00:00
|
|
|
ArticlePageWithOverlay.overlay_close_element.waitForDisplayed();
|
2019-04-08 21:11:33 +00:00
|
|
|
ArticlePageWithOverlay.overlay_close_element.click();
|
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iSeeAnOverlay = async () => {
|
|
|
|
await ArticlePageWithOverlay.overlay_element.waitForDisplayed();
|
|
|
|
assert.strictEqual( await ArticlePageWithOverlay.overlay_element.isDisplayed(), true );
|
2019-04-08 21:11:33 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iDoNotSeeAnOverlay = async () => {
|
|
|
|
await waitForPropagation( 5000 );
|
|
|
|
await browser.waitUntil(
|
|
|
|
async () => !( await ArticlePageWithOverlay.overlay_element.isDisplayed() )
|
|
|
|
);
|
|
|
|
assert.strictEqual( await ArticlePageWithOverlay.overlay_element.isDisplayed(), false );
|
2019-04-08 21:11:33 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iAmUsingMobileScreenResolution = async () => {
|
|
|
|
await 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
|
|
|
|
};
|