2018-04-10 21:19:08 +00:00
|
|
|
/**
|
|
|
|
* Represents a page the can be presented in desktop
|
|
|
|
* or mobile mode (requires mobilefrontend), and has
|
|
|
|
* features like public 'beta' mode (requires mobilefrontend).
|
|
|
|
*
|
|
|
|
* @extends Page
|
|
|
|
* @example
|
|
|
|
* https://en.m.wikipedia.org/wiki/Barack_Obama
|
|
|
|
*/
|
|
|
|
|
2020-06-02 21:21:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-04-10 21:19:08 +00:00
|
|
|
const { Page } = require( './mw_core_pages' );
|
|
|
|
|
|
|
|
class MinervaPage extends Page {
|
|
|
|
|
2024-01-24 22:02:12 +00:00
|
|
|
get title() {
|
|
|
|
return browser.getTitle();
|
|
|
|
}
|
2018-04-10 21:19:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a page if it isn't already open.
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2018-04-10 21:19:08 +00:00
|
|
|
* @param {string} path
|
|
|
|
*/
|
|
|
|
open( path = 'Main_Page' ) {
|
|
|
|
const currentPage = browser.getUrl(),
|
|
|
|
newPage = browser.options.baseUrl + '/index.php?title=' + path;
|
|
|
|
if ( currentPage !== newPage ) {
|
|
|
|
browser.url( newPage );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure browser is opened on a MediaWiki page, and set a specified
|
|
|
|
* cookie for that domain.
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2018-04-10 21:19:08 +00:00
|
|
|
* @param {string} name - name of the cookie
|
|
|
|
* @param {string} value - value of the cookie
|
|
|
|
*/
|
2023-04-06 22:25:40 +00:00
|
|
|
async setCookie( name, value ) {
|
|
|
|
const currentPage = await browser.getUrl();
|
|
|
|
if ( !currentPage.includes( await browser.options.baseUrl ) ) {
|
2018-04-10 21:19:08 +00:00
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
|
2023-04-06 22:25:40 +00:00
|
|
|
const cookie = await browser.getCookies( [ name ] );
|
2018-04-10 21:19:08 +00:00
|
|
|
|
|
|
|
if ( !cookie || cookie.value !== value ) {
|
2023-04-06 22:25:40 +00:00
|
|
|
await browser.setCookies( {
|
2018-04-10 21:19:08 +00:00
|
|
|
name: name,
|
|
|
|
value: value } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the mobile cookie
|
|
|
|
*/
|
|
|
|
setMobileMode() {
|
|
|
|
this.setCookie( 'mf_useformat', 'true' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the beta cookie
|
|
|
|
*/
|
|
|
|
setBetaMode() {
|
|
|
|
this.setCookie( 'optin', 'beta' );
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:09:47 +00:00
|
|
|
waitUntilResourceLoaderModuleReady( moduleName ) {
|
|
|
|
browser.waitUntil( () => {
|
|
|
|
const state = browser.execute( ( m ) => {
|
|
|
|
return mw.loader.getState( m );
|
|
|
|
}, moduleName );
|
2020-06-15 14:54:05 +00:00
|
|
|
return state === 'ready';
|
2019-04-05 21:09:47 +00:00
|
|
|
} );
|
|
|
|
}
|
2018-04-10 21:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MinervaPage;
|