mediawiki-skins-MinervaNeue/tests/selenium/features/step_definitions/editor_steps.js
Vaughn Walters 677ce50b24 selenium: Refactor WebdriverIO tests from sync to async mode
WebdriverIO has dropped support of sync mode, hence changed to async.

Update npm packages: @wdio/*, wdio-mediawiki
because async mode needs at least @wdio v7.9.

Remove npm packages: @wdio/dot-reporter and @wdio/sync.

Bug: T293084
Change-Id: I5babbdadf21e9f951f69de93bfca5213a50965aa
2023-04-08 16:18:28 -05:00

73 lines
2.4 KiB
JavaScript

'use strict';
const assert = require( 'assert' );
const { ArticlePageWithEditorOverlay, ArticlePage } = require( '../support/world.js' );
const iClickTheEditButton = async () => {
await ArticlePage.edit_link_element.waitForDisplayed();
await ArticlePage.edit_link_element.click();
};
const iSeeTheWikitextEditorOverlay = async () => {
await ArticlePageWithEditorOverlay.editor_overlay_element.waitForDisplayed();
await ArticlePageWithEditorOverlay.editor_textarea_element.waitForExist();
};
const iClearTheEditor = () => {
ArticlePageWithEditorOverlay.editor_textarea_element.setValue( '' );
};
const iDoNotSeeTheWikitextEditorOverlay = () => {
browser.waitUntil( () => {
return ArticlePageWithEditorOverlay.editor_overlay_element.isDisplayed() === false;
}, 10000 );
};
const iTypeIntoTheEditor = ( text ) => {
ArticlePageWithEditorOverlay.editor_overlay_element.waitForExist();
ArticlePageWithEditorOverlay.editor_textarea_element.waitForExist();
ArticlePageWithEditorOverlay.editor_textarea_element.waitForDisplayed();
ArticlePageWithEditorOverlay.editor_textarea_element.addValue( text );
browser.waitUntil( () => {
return !ArticlePageWithEditorOverlay
.continue_element.getAttribute( 'disabled' );
} );
};
const iClickContinue = () => {
ArticlePageWithEditorOverlay.continue_element.waitForExist();
ArticlePageWithEditorOverlay.continue_element.click();
};
const iClickSubmit = () => {
ArticlePageWithEditorOverlay.submit_element.waitForExist();
ArticlePageWithEditorOverlay.submit_element.click();
};
const iSayOkayInTheConfirmDialog = () => {
browser.waitUntil( () => {
try {
const text = browser.getAlertText();
return text && true;
} catch ( e ) {
return false;
}
}, 2000 );
browser.acceptAlert();
};
const theTextOfTheFirstHeadingShouldBe = async ( title ) => {
await ArticlePage.first_heading_element.waitForDisplayed();
assert.match(
await ArticlePage.first_heading_element.getText(),
new RegExp( `.*${title}$` )
);
};
const thereShouldBeARedLinkWithText = ( text ) => {
ArticlePage.red_link_element.waitForExist();
assert.strictEqual(
ArticlePage.red_link_element.getText(),
text
);
};
module.exports = {
iClickTheEditButton, iSeeTheWikitextEditorOverlay, iClearTheEditor,
thereShouldBeARedLinkWithText,
iDoNotSeeTheWikitextEditorOverlay,
iTypeIntoTheEditor, iClickContinue, iClickSubmit, iSayOkayInTheConfirmDialog,
theTextOfTheFirstHeadingShouldBe
};