mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-17 19:21:39 +00:00
26e413e04d
Porting first selenium test from Ruby to Node.js using the mocha framework. Starting with `category.feature` test. Tests are placed in a new `tests/selenium` folder with their own eslint config. Bug: T190710 Change-Id: Iad954405a5ae0608fd5dc90dd5dfa434b3781037
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const { api } = require( '../support/world' ),
|
|
Api = require( 'wdio-mediawiki/Api' );
|
|
|
|
const login = () => {
|
|
return api.loginGetEditToken( {
|
|
username: browser.options.username,
|
|
password: browser.options.password,
|
|
apiUrl: `${browser.options.baseUrl}/api.php`
|
|
} );
|
|
};
|
|
|
|
const waitForPropagation = ( timeMs ) => {
|
|
// wait 2 seconds so the change can propogate.
|
|
const d = new Date();
|
|
browser.waitUntil( () => new Date() - d > timeMs );
|
|
};
|
|
|
|
const iAmInAWikiThatHasCategories = ( title ) => {
|
|
const msg = 'This page is used by Selenium to test category related features.',
|
|
summary = 'edit by selenium test',
|
|
wikitext = `
|
|
${msg}
|
|
|
|
[[Category:Test category]]
|
|
[[Category:Selenium artifacts]]
|
|
[[Category:Selenium hidden category]]
|
|
`;
|
|
|
|
login().then( () => api.batch( [
|
|
[ 'create', 'Category:Selenium artifacts', msg, summary ],
|
|
[ 'create', 'Category:Test category', msg, summary ],
|
|
[ 'create', 'Category:Selenium hidden category', '__HIDDENCAT__', summary ]
|
|
] ) )
|
|
.catch( ( err ) => {
|
|
if ( err.code === 'articleexists' ) {
|
|
return;
|
|
}
|
|
throw err;
|
|
} );
|
|
|
|
// A pause is necessary to let the categories register with database before trying to use
|
|
// them in an article
|
|
waitForPropagation( 5000 );
|
|
Api.edit( title, wikitext );
|
|
// categories are handled by a JobRunner so need extra time to appear via API calls!
|
|
waitForPropagation( 5000 );
|
|
};
|
|
|
|
module.exports = {
|
|
waitForPropagation,
|
|
iAmInAWikiThatHasCategories
|
|
};
|