mediawiki-extensions-CodeMi.../tests/selenium/pageobjects/edit.page.js
James D. Forrester 9e9a38d6fc Refactor CodeMirror WebdriverIO tests from sync to async mode
Bug: T300205
Change-Id: Idfcfc984833ca6ca6c09500cd4715a4e5504f84e
2023-06-06 10:49:22 +02:00

49 lines
1.4 KiB
JavaScript

'use strict';
const Page = require( 'wdio-mediawiki/Page' );
// Copied from mediawiki-core edit.page.js
class EditPage extends Page {
async openForEditing( title ) {
await super.openTitle( title, { action: 'edit', vehidebetadialog: 1, hidewelcomedialog: 1 } );
}
get wikiEditorToolbar() { return $( '#wikiEditor-ui-toolbar' ); }
get legacyTextInput() { return $( '#wpTextbox1' ); }
async clickText() {
if ( await this.visualEditorSave.isDisplayed() ) {
await this.visualEditorSurface.click();
} else if ( await this.legacyTextInput.isDisplayed() ) {
await this.legacyTextInput.click();
} else {
// Click the container, if using WikiEditor etc.
await this.legacyTextInput.parentElement().click();
}
}
get visualEditorSave() { return $( '.ve-ui-toolbar-saveButton' ); }
get visualEditorToggle() { return $( '.ve-init-mw-editSwitch' ); }
get visualEditorSurface() { return $( '.ve-ui-surface-source' ); }
async cursorToPosition( index ) {
await this.clickText();
// Second "Control" deactivates the modifier.
const keys = [ 'Control', 'Home', 'Control' ];
for ( let i = 0; i < index; i++ ) {
keys.push( 'ArrowRight' );
}
await browser.keys( keys );
}
getHighlightedMatchingBrackets() {
const elements = $$( '.CodeMirror-line .cm-mw-matchingbracket' );
const matchingTexts = elements.map( function ( el ) {
return el.getText();
} );
return matchingTexts.join( '' );
}
}
module.exports = new EditPage();