2020-06-02 21:21:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-06-06 11:33:54 +00:00
|
|
|
const { ArticlePage } = require( '../support/world' ),
|
|
|
|
RunJobs = require( 'wdio-mediawiki/RunJobs' ),
|
|
|
|
Api = require( 'wdio-mediawiki/Api' ),
|
|
|
|
Page = require( 'wdio-mediawiki/Page' ),
|
|
|
|
MWBot = require( 'mwbot' ),
|
|
|
|
{
|
|
|
|
iAmOnPage,
|
|
|
|
waitForPropagation,
|
|
|
|
createPages,
|
|
|
|
createPage
|
|
|
|
} = require( './common_steps' );
|
2018-04-10 21:19:08 +00:00
|
|
|
|
|
|
|
const iAmInAWikiThatHasCategories = ( title ) => {
|
|
|
|
const msg = 'This page is used by Selenium to test category related features.',
|
|
|
|
wikitext = `
|
2024-01-24 22:02:12 +00:00
|
|
|
${ msg }
|
2018-04-10 21:19:08 +00:00
|
|
|
|
|
|
|
[[Category:Test category]]
|
|
|
|
[[Category:Selenium artifacts]]
|
|
|
|
[[Category:Selenium hidden category]]
|
|
|
|
`;
|
|
|
|
|
2019-04-05 21:09:47 +00:00
|
|
|
createPages( [
|
|
|
|
[ 'create', 'Category:Selenium artifacts', msg ],
|
|
|
|
[ 'create', 'Category:Test category', msg ],
|
|
|
|
[ 'create', 'Category:Selenium hidden category', '__HIDDENCAT__' ]
|
2019-05-18 07:49:41 +00:00
|
|
|
] );
|
2018-04-10 21:19:08 +00:00
|
|
|
|
|
|
|
// A pause is necessary to let the categories register with database before trying to use
|
|
|
|
// them in an article
|
|
|
|
waitForPropagation( 5000 );
|
2020-06-15 14:54:05 +00:00
|
|
|
browser.call( async () => {
|
|
|
|
const bot = await Api.bot();
|
|
|
|
await bot.edit( title, wikitext );
|
2019-04-09 19:43:39 +00:00
|
|
|
} );
|
2020-06-15 14:54:05 +00:00
|
|
|
|
2024-07-27 05:52:33 +00:00
|
|
|
browser.call( () =>
|
2019-04-09 19:43:39 +00:00
|
|
|
// The category overlay uses the category API
|
|
|
|
// which will only return results if the job queue has completed.
|
|
|
|
// Run before continuing!
|
2024-07-27 05:52:33 +00:00
|
|
|
RunJobs.run()
|
|
|
|
);
|
2018-04-10 21:19:08 +00:00
|
|
|
};
|
|
|
|
|
2018-04-10 21:35:50 +00:00
|
|
|
const iAmOnAPageThatHasTheFollowingEdits = function ( table ) {
|
2021-11-09 14:48:40 +00:00
|
|
|
const randomString = Math.random().toString( 36 ).slice( 7 ),
|
2024-01-24 22:02:12 +00:00
|
|
|
pageTitle = `Selenium_diff_test_${ randomString }`,
|
2024-07-27 05:52:33 +00:00
|
|
|
edits = table.rawTable.map( ( row, i ) => [ i === 0 ? 'create' : 'edit', pageTitle, row[ 0 ] ] );
|
2018-04-10 21:35:50 +00:00
|
|
|
|
2019-06-06 11:33:54 +00:00
|
|
|
browser.call( () => {
|
|
|
|
const bot = new MWBot();
|
|
|
|
return bot.loginGetEditToken( {
|
|
|
|
username: browser.options.username,
|
|
|
|
password: browser.options.password,
|
2024-01-24 22:02:12 +00:00
|
|
|
apiUrl: `${ browser.options.baseUrl }/api.php`
|
2019-06-06 11:33:54 +00:00
|
|
|
} )
|
|
|
|
.then( () => bot.batch( edits ) )
|
2024-01-24 22:02:12 +00:00
|
|
|
.catch( ( err ) => {
|
|
|
|
throw err;
|
|
|
|
} );
|
2019-06-06 11:33:54 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
browser.call( () => RunJobs.run() );
|
|
|
|
ArticlePage.open( pageTitle );
|
2018-04-10 21:35:50 +00:00
|
|
|
};
|
|
|
|
|
2019-04-05 21:09:47 +00:00
|
|
|
const iGoToAPageThatHasLanguages = () => {
|
|
|
|
const wikitext = `This page is used by Selenium to test language related features.
|
|
|
|
|
|
|
|
[[es:Selenium language test page]]
|
|
|
|
`;
|
|
|
|
|
2019-05-18 07:49:41 +00:00
|
|
|
browser.call( () => {
|
|
|
|
createPage( 'Selenium language test page', wikitext );
|
|
|
|
} );
|
|
|
|
browser.call( () => {
|
2019-04-05 21:09:47 +00:00
|
|
|
iAmOnPage( 'Selenium language test page' );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2019-04-08 23:45:11 +00:00
|
|
|
const watch = ( title ) => {
|
|
|
|
// Ideally this would use the API but mwbot / Selenium's API can't do this right now
|
|
|
|
// So we run the non-js workflow.
|
|
|
|
const page = new Page();
|
|
|
|
page.openTitle( title, { action: 'watch' } );
|
2022-02-03 20:18:02 +00:00
|
|
|
$( '#mw-content-text button[type="submit"]' ).waitForDisplayed();
|
2020-06-15 14:54:05 +00:00
|
|
|
$( '#mw-content-text button[type="submit"]' ).click();
|
2019-04-08 23:45:11 +00:00
|
|
|
waitForPropagation( 10000 );
|
2019-10-16 21:01:59 +00:00
|
|
|
page.openTitle( title );
|
2019-04-08 23:45:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const iAmViewingAWatchedPage = () => {
|
2024-01-24 22:02:12 +00:00
|
|
|
const title = `I am on the "Selenium mobile watched page test ${ Date.now() }`;
|
2024-07-27 05:52:33 +00:00
|
|
|
browser.call( () => createPage( title, 'watch test' ) );
|
2019-10-16 21:01:59 +00:00
|
|
|
watch( title );
|
|
|
|
// navigate away from page
|
|
|
|
iAmOnPage( 'Main Page' );
|
|
|
|
waitForPropagation( 5000 );
|
|
|
|
// and back to page
|
|
|
|
iAmOnPage( title );
|
|
|
|
waitForPropagation( 5000 );
|
2019-04-08 23:45:11 +00:00
|
|
|
};
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const iAmViewingAnUnwatchedPage = async () => {
|
2019-04-08 23:45:11 +00:00
|
|
|
// new pages are watchable but unwatched by default
|
|
|
|
const title = 'I am on the "Selenium mobile unwatched test ' + new Date();
|
2023-04-06 22:25:40 +00:00
|
|
|
await iAmOnPage( title );
|
2019-04-08 23:45:11 +00:00
|
|
|
};
|
|
|
|
|
2019-10-17 22:46:07 +00:00
|
|
|
const iAmOnATalkPageWithNoTalkTopics = () => {
|
2024-01-24 22:02:12 +00:00
|
|
|
const title = `Selenium talk test ${ new Date() }`;
|
2019-04-08 23:45:11 +00:00
|
|
|
|
|
|
|
createPage( title, 'Selenium' );
|
2024-01-24 22:02:12 +00:00
|
|
|
iAmOnPage( `Talk:${ title }` );
|
2019-04-08 23:45:11 +00:00
|
|
|
};
|
|
|
|
|
2018-04-10 21:19:08 +00:00
|
|
|
module.exports = {
|
|
|
|
waitForPropagation,
|
2018-04-10 21:35:50 +00:00
|
|
|
iAmOnAPageThatHasTheFollowingEdits,
|
2019-10-17 22:46:07 +00:00
|
|
|
iAmOnATalkPageWithNoTalkTopics,
|
2019-04-08 23:45:11 +00:00
|
|
|
iAmViewingAWatchedPage,
|
|
|
|
iAmViewingAnUnwatchedPage,
|
2019-04-05 21:09:47 +00:00
|
|
|
iAmInAWikiThatHasCategories,
|
|
|
|
iGoToAPageThatHasLanguages
|
2018-04-10 21:19:08 +00:00
|
|
|
};
|