Debian Codegraph @

skins/MinervaNeue/tests/selenium/features/step_definitions/common_steps.js

raw symbols SCIP
1 'use strict';
2
3 const assert = require( 'assert' ),
4 MWBot = require( 'mwbot' ),
5 Api = require( 'wdio-mediawiki/Api' ),
6 ArticlePageWithOverlay = require( '../support/pages/article_page_with_overlay' ),
7 { ArticlePage, UserLoginPage } = require( '../support/world.js' );
8
9 const waitForPropagation = async ( timeMs ) => {
10 // wait 2 seconds so the change can propogate.
11 // Replace this with a more dynamic statement.
12 // eslint-disable-next-line wdio/no-pause
13 await browser.pause( timeMs );
14 };
15
16 const createPages = ( pages ) => {
17 const summary = 'edit by selenium test';
18 browser.call( () => {
19 const bot = new MWBot();
20 return bot.loginGetEditToken( {
21 username: browser.options.username,
22 password: browser.options.password,
23 apiUrl: `${ browser.options.baseUrl }/api.php`
24 } )
25 .then( () => bot.batch(
26 pages.map( ( page ) => [ 'create' ].concat( page ).concat( [ summary ] ) )
27 ).catch( ( err ) => {
28 if ( err.code === 'articleexists' ) {
29 return;
30 }
31 throw err;
32 } ) )
33 .catch( ( err ) => {
34 throw err;
35 } );
36 } );
37 };
38
39 const createPage = ( title, wikitext ) => {
40 browser.call( async () => {
41 const bot = await Api.bot();
42 await bot.edit( title, wikitext );
43 } );
44 };
45
46 const iAmUsingTheMobileSite = async () => {
47 await ArticlePage.setMobileMode();
48 };
49
50 const iAmInBetaMode = () => {
51 ArticlePage.setBetaMode();
52 };
53
54 const iAmOnPage = async ( article ) => {
55 await ArticlePage.open( article );
56 // Make sure the article opened and JS loaded.
57 await ArticlePage.waitUntilResourceLoaderModuleReady( 'skins.minerva.scripts' );
58 };
59
60 const iAmLoggedIn = async () => {
61 await UserLoginPage.open();
62 await UserLoginPage.loginAdmin();
63 assert.strictEqual( await ArticlePage.is_authenticated_element.isExisting(), true );
64 };
65
66 const iAmLoggedIntoTheMobileWebsite = async () => {
67 await iAmUsingTheMobileSite();
68 await iAmLoggedIn();
69 };
70
71 const pageExists = async ( title ) => {
72 await browser.call( async () => await createPage( title, 'Page created by Selenium browser test.' )
73 );
74 // wait 2 seconds so the change can propogate.
75 await waitForPropagation( 2000 );
76 };
77
78 const pageExistsWithText = ( title, text ) => {
79 browser.call( () => createPage( title, text )
80 );
81 // wait 2 seconds so the change can propogate.
82 waitForPropagation( 2000 );
83 };
84
85 const iAmOnAPageThatDoesNotExist = () => iAmOnPage( `NewPage ${ new Date() }` );
86
87 const iShouldSeeAToastNotification = async () => {
88 await ArticlePage.notification_element.waitForDisplayed();
89 };
90
91 const iShouldSeeAToastNotificationWithMessage = async ( msg ) => {
92 await iShouldSeeAToastNotification();
93 const notificationBody = await ArticlePage.notification_element.$( '.mw-notification-content' ).getText();
94 assert.strictEqual( await notificationBody.includes( msg ), true );
95 };
96
97 const iClickTheBrowserBackButton = async () => {
98 await browser.back();
99 };
100
101 const iClickTheOverlayCloseButton = () => {
102 waitForPropagation( 2000 );
103 ArticlePageWithOverlay.overlay_close_element.waitForDisplayed();
104 ArticlePageWithOverlay.overlay_close_element.click();
105 };
106
107 const iSeeAnOverlay = async () => {
108 await ArticlePageWithOverlay.overlay_element.waitForDisplayed();
109 assert.strictEqual( await ArticlePageWithOverlay.overlay_element.isDisplayed(), true );
110 };
111
112 const iDoNotSeeAnOverlay = async () => {
113 await waitForPropagation( 5000 );
114 await browser.waitUntil(
115 async () => !( await ArticlePageWithOverlay.overlay_element.isDisplayed() )
116 );
117 assert.strictEqual( await ArticlePageWithOverlay.overlay_element.isDisplayed(), false );
118 };
119
120 const iAmUsingMobileScreenResolution = async () => {
121 await browser.setWindowSize( 320, 480 );
122 };
123
124 module.exports = {
125 waitForPropagation,
126 iAmUsingMobileScreenResolution,
127 iSeeAnOverlay, iDoNotSeeAnOverlay,
128 iClickTheOverlayCloseButton,
129 iClickTheBrowserBackButton,
130 createPage, createPages,
131 pageExistsWithText,
132 pageExists, iAmOnAPageThatDoesNotExist, iShouldSeeAToastNotification,
133 iShouldSeeAToastNotificationWithMessage,
134 iAmLoggedIntoTheMobileWebsite,
135 iAmUsingTheMobileSite,
136 iAmLoggedIn, iAmOnPage, iAmInBetaMode
137 };