Debian Codegraph @

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

raw symbols SCIP
1 'use strict';
2
3 const { ArticlePage } = require( '../support/world' ),
4 RunJobs = require( 'wdio-mediawiki/RunJobs' ),
5 Api = require( 'wdio-mediawiki/Api' ),
6 Page = require( 'wdio-mediawiki/Page' ),
7 MWBot = require( 'mwbot' ),
8 {
9 iAmOnPage,
10 waitForPropagation,
11 createPages,
12 createPage
13 } = require( './common_steps' );
14
15 const iAmInAWikiThatHasCategories = ( title ) => {
16 const msg = 'This page is used by Selenium to test category related features.',
17 wikitext = `
18 ${ msg }
19
20 [[Category:Test category]]
21 [[Category:Selenium artifacts]]
22 [[Category:Selenium hidden category]]
23 `;
24
25 createPages( [
26 [ 'create', 'Category:Selenium artifacts', msg ],
27 [ 'create', 'Category:Test category', msg ],
28 [ 'create', 'Category:Selenium hidden category', '__HIDDENCAT__' ]
29 ] );
30
31 // A pause is necessary to let the categories register with database before trying to use
32 // them in an article
33 waitForPropagation( 5000 );
34 browser.call( async () => {
35 const bot = await Api.bot();
36 await bot.edit( title, wikitext );
37 } );
38
39 browser.call(
40 // The category overlay uses the category API
41 // which will only return results if the job queue has completed.
42 // Run before continuing!
43 () => RunJobs.run()
44 );
45 };
46
47 const iAmOnAPageThatHasTheFollowingEdits = function ( table ) {
48 const randomString = Math.random().toString( 36 ).slice( 7 ),
49 pageTitle = `Selenium_diff_test_${ randomString }`,
50 edits = table.rawTable.map( ( row, i ) => [ i === 0 ? 'create' : 'edit', pageTitle, row[ 0 ] ] );
51
52 browser.call( () => {
53 const bot = new MWBot();
54 return bot.loginGetEditToken( {
55 username: browser.options.username,
56 password: browser.options.password,
57 apiUrl: `${ browser.options.baseUrl }/api.php`
58 } )
59 .then( () => bot.batch( edits ) )
60 .catch( ( err ) => {
61 throw err;
62 } );
63 } );
64
65 browser.call( () => RunJobs.run() );
66 ArticlePage.open( pageTitle );
67 };
68
69 const iGoToAPageThatHasLanguages = () => {
70 const wikitext = `This page is used by Selenium to test language related features.
71
72 [[es:Selenium language test page]]
73 `;
74
75 browser.call( () => {
76 createPage( 'Selenium language test page', wikitext );
77 } );
78 browser.call( () => {
79 iAmOnPage( 'Selenium language test page' );
80 } );
81 };
82
83 const watch = ( title ) => {
84 // Ideally this would use the API but mwbot / Selenium's API can't do this right now
85 // So we run the non-js workflow.
86 const page = new Page();
87 page.openTitle( title, { action: 'watch' } );
88 $( '#mw-content-text button[type="submit"]' ).waitForDisplayed();
89 $( '#mw-content-text button[type="submit"]' ).click();
90 waitForPropagation( 10000 );
91 page.openTitle( title );
92 };
93
94 const iAmViewingAWatchedPage = () => {
95 const title = `I am on the "Selenium mobile watched page test ${ Date.now() }`;
96 browser.call( () => createPage( title, 'watch test' ) );
97 watch( title );
98 // navigate away from page
99 iAmOnPage( 'Main Page' );
100 waitForPropagation( 5000 );
101 // and back to page
102 iAmOnPage( title );
103 waitForPropagation( 5000 );
104 };
105
106 const iAmViewingAnUnwatchedPage = async () => {
107 // new pages are watchable but unwatched by default
108 const title = 'I am on the "Selenium mobile unwatched test ' + new Date();
109 await iAmOnPage( title );
110 };
111
112 const iAmOnATalkPageWithNoTalkTopics = () => {
113 const title = `Selenium talk test ${ new Date() }`;
114
115 createPage( title, 'Selenium' );
116 iAmOnPage( `Talk:${ title }` );
117 };
118
119 module.exports = {
120 waitForPropagation,
121 iAmOnAPageThatHasTheFollowingEdits,
122 iAmOnATalkPageWithNoTalkTopics,
123 iAmViewingAWatchedPage,
124 iAmViewingAnUnwatchedPage,
125 iAmInAWikiThatHasCategories,
126 iGoToAPageThatHasLanguages
127 };