From 86c994a68e901d56216152e043fb6aee49282274 Mon Sep 17 00:00:00 2001 From: Ricki <141253288+RickiJay-WMDE@users.noreply.github.com> Date: Tue, 24 Oct 2023 13:18:54 +0200 Subject: [PATCH] T346214 await displayed (#490) * awaitDisplayed * timeout argument * Assert and * Rename * Extend * Submittable Page * T348506 Remove Git Tagging (#492) * Publishing Readme * Publishing YML * Remover * T346623 wikibase fork 1 (#491) * Forked Package * Remove * Fix --- test/helpers/await-displayed.ts | 15 ++++++++ test/helpers/default-functions.ts | 19 ++++------- test/helpers/pages/entity/property.page.ts | 14 +++++--- .../queryservice-ui/queryservice-ui.page.ts | 26 +++++++------- test/helpers/pages/special/new-item.page.ts | 28 ++++++++------- .../pages/special/new-property.page.ts | 34 +++++++++++-------- test/helpers/pages/submittable.page.ts | 15 ++++++++ test/specs/elasticsearch/elasticsearch.ts | 15 ++++---- test/specs/fedprops/item.ts | 13 +++---- test/specs/fedprops/prefetching.ts | 13 +++---- test/specs/quickstatements/quickstatements.ts | 22 +++++------- test/specs/repo/extensions/entityschema.ts | 27 ++++++++------- test/specs/repo/extensions/nuke.ts | 23 ++++++------- .../specs/repo/extensions/syntax-highlight.ts | 4 +-- .../extensions/universal-language-selector.ts | 10 +++--- test/specs/repo/extensions/visual-editor.ts | 29 +++++++--------- .../repo/extensions/wikibase-local-media.ts | 20 ++++------- test/specs/repo/property.ts | 14 +++----- test/specs/repo/queryservice.ts | 11 +++--- test/specs/repo/special-item.ts | 13 +++---- test/specs/repo/special-property.ts | 13 +++---- test/specs/repo/special-version.ts | 7 ++-- .../repo_client/extensions/scribunto-item.ts | 12 ++++--- test/specs/repo_client/item.ts | 29 +++++++--------- 24 files changed, 215 insertions(+), 211 deletions(-) create mode 100644 test/helpers/await-displayed.ts create mode 100644 test/helpers/pages/submittable.page.ts diff --git a/test/helpers/await-displayed.ts b/test/helpers/await-displayed.ts new file mode 100644 index 000000000..568b54d19 --- /dev/null +++ b/test/helpers/await-displayed.ts @@ -0,0 +1,15 @@ +type WaitForOptions = { + timeout?: number; +}; + +const awaitDisplayed = async ( + identifier: string | ChainablePromiseElement | WebdriverIO.Element, + options?: WaitForOptions +): Promise => { + const resultElement = + typeof identifier === 'string' ? await $( identifier ) : await identifier; + await resultElement.waitForDisplayed( options ); + return resultElement; +}; + +export default awaitDisplayed; diff --git a/test/helpers/default-functions.ts b/test/helpers/default-functions.ts index 1c552060f..7c4e5c113 100644 --- a/test/helpers/default-functions.ts +++ b/test/helpers/default-functions.ts @@ -9,6 +9,7 @@ import LuaCPUValue from './types/lua-cpu-value.js'; import Binding from './types/binding.js'; import ExternalChange from './types/external-change.js'; import { Context } from 'mocha'; +import awaitDisplayed from './await-displayed.js'; export function defaultFunctions(): void { /** @@ -147,13 +148,11 @@ export function defaultFunctions(): void { } // fill out form - const textBoxEl = await $( '#wpTextbox1' ); - await textBoxEl.waitForDisplayed(); + const textBoxEl = await awaitDisplayed( '#wpTextbox1' ); await textBoxEl.setValue( content.toString() ); if ( captcha ) { - const captchaEl = await $( '#wpCaptchaWord' ); - await captchaEl.waitForDisplayed(); + const captchaEl = await awaitDisplayed( '#wpCaptchaWord' ); await captchaEl.setValue( captcha ); } @@ -165,8 +164,7 @@ export function defaultFunctions(): void { await browser.pause( 2 * 1000 ); - const contentTextEl = await $( '#mw-content-text' ); - await contentTextEl.waitForDisplayed(); + const contentTextEl = await awaitDisplayed( '#mw-content-text' ); return await contentTextEl.getText(); } ); @@ -231,22 +229,19 @@ export function defaultFunctions(): void { await browser.url( `${process.env.QS_SERVER}/#/batch` ); // create a batch - const createBatchBoxTextareaEl = await $( '.create_batch_box textarea' ); - await createBatchBoxTextareaEl.waitForDisplayed(); + const createBatchBoxTextareaEl = await awaitDisplayed( '.create_batch_box textarea' ); await createBatchBoxTextareaEl.setValue( theQuery ); await browser.pause( 1000 ); // click import - const importButtonEl = await $( "button[tt='dialog_import_v1']" ); - await importButtonEl.waitForDisplayed(); + const importButtonEl = await awaitDisplayed( "button[tt='dialog_import_v1']" ); await importButtonEl.click(); await browser.pause( 1000 ); // click run - const runButtonEl = await $( "button[tt='run']" ); - await runButtonEl.waitForDisplayed(); + const runButtonEl = await awaitDisplayed( "button[tt='run']" ); await runButtonEl.click(); const commands = await $$( '.command_status' ); diff --git a/test/helpers/pages/entity/property.page.ts b/test/helpers/pages/entity/property.page.ts index 6e33acc78..82a722882 100644 --- a/test/helpers/pages/entity/property.page.ts +++ b/test/helpers/pages/entity/property.page.ts @@ -1,12 +1,18 @@ import Page from '../page.js'; class Property extends Page { - public get save(): ChainablePromiseElement { return $( '=save' ); } - public get addStatement(): ChainablePromiseElement { return $( '=add statement' ); } - public get addReference(): ChainablePromiseElement { return $( '=add reference' ); } + public get save(): ChainablePromiseElement { + return $( '=save' ); + } + public get addStatement(): ChainablePromiseElement { + return $( '=add statement' ); + } + public get addReference(): ChainablePromiseElement { + return $( '=add reference' ); + } public async open( id: string ): Promise { - await browser.url( process.env.MW_SERVER + '/wiki/Property:' + id ); + await browser.url( `${process.env.MW_SERVER}/wiki/Property:${id}` ); } } diff --git a/test/helpers/pages/queryservice-ui/queryservice-ui.page.ts b/test/helpers/pages/queryservice-ui/queryservice-ui.page.ts index fc23406ee..fcfa85365 100644 --- a/test/helpers/pages/queryservice-ui/queryservice-ui.page.ts +++ b/test/helpers/pages/queryservice-ui/queryservice-ui.page.ts @@ -1,10 +1,18 @@ -import Page from '../page.js'; +import SubmittablePage from '../submittable.page.js'; -class QueryServiceUI extends Page { - public get queryEditor(): ChainablePromiseElement { return $( '.queryEditor' ); } - public get submitBtn(): ChainablePromiseElement { return $( '#execute-button' ); } - public get resultTable(): ChainablePromiseElement { return $( '#query-result table.table.table-hover' ); } - public get resultTableRows(): ChainablePromiseElement { return $( '#query-result table.table.table-hover tr' ); } +class QueryServiceUI extends SubmittablePage { + public get queryEditor(): ChainablePromiseElement { + return $( '.queryEditor' ); + } + public get submitBtn(): ChainablePromiseElement { + return $( '#execute-button' ); + } + public get resultTable(): ChainablePromiseElement { + return $( '#query-result table.table.table-hover' ); + } + public get resultTableRows(): ChainablePromiseElement { + return $( '#query-result table.table.table-hover tr' ); + } public open( query: string, prefixes?: string[] ): Promise { if ( prefixes ) { @@ -13,12 +21,6 @@ class QueryServiceUI extends Page { return super.open( '/#' + encodeURI( query ) ); } - public async submit(): Promise { - const button = await this.submitBtn; - await button.waitForDisplayed(); - await button.click(); - } - public async resultIncludes( prop: string, value?: string ): Promise { const resultTable = await this.resultTable; const text = await resultTable.getText(); diff --git a/test/helpers/pages/special/new-item.page.ts b/test/helpers/pages/special/new-item.page.ts index be8a1b8bd..7d0e41801 100644 --- a/test/helpers/pages/special/new-item.page.ts +++ b/test/helpers/pages/special/new-item.page.ts @@ -1,19 +1,21 @@ -import Page from '../page.js'; +import SubmittablePage from '../submittable.page.js'; -class SpecialNewItem extends Page { - public get labelInput(): ChainablePromiseElement { return $( 'input[name="label"]' ); } - public get descriptionInput(): ChainablePromiseElement { return $( 'input[name="description"]' ); } - public get aliasesInput(): ChainablePromiseElement { return $( 'input[name="aliases"]' ); } - public get submitBtn(): ChainablePromiseElement { return $( 'button[type="submit"]' ); } - - public async open(): Promise { - await browser.url( process.env.MW_SERVER + '/wiki/Special:NewItem' ); +class SpecialNewItem extends SubmittablePage { + public get labelInput(): ChainablePromiseElement { + return $( 'input[name="label"]' ); + } + public get descriptionInput(): ChainablePromiseElement { + return $( 'input[name="description"]' ); + } + public get aliasesInput(): ChainablePromiseElement { + return $( 'input[name="aliases"]' ); + } + public get submitBtn(): ChainablePromiseElement { + return $( 'button[type="submit"]' ); } - public async submit(): Promise { - const button = await this.submitBtn; - await this.submitBtn.waitForDisplayed(); - await button.click(); + public async open(): Promise { + await browser.url( `${process.env.MW_SERVER}/wiki/Special:NewItem` ); } } diff --git a/test/helpers/pages/special/new-property.page.ts b/test/helpers/pages/special/new-property.page.ts index b47af07c0..63ddf58b9 100644 --- a/test/helpers/pages/special/new-property.page.ts +++ b/test/helpers/pages/special/new-property.page.ts @@ -1,21 +1,27 @@ -import Page from '../page.js'; +import SubmittablePage from '../submittable.page.js'; -class SpecialNewProperty extends Page { - public get labelInput(): ChainablePromiseElement { return $( 'input[name="label"]' ); } - public get descriptionInput(): ChainablePromiseElement { return $( 'input[name="description"]' ); } - public get aliasesInput(): ChainablePromiseElement { return $( 'input[name="aliases"]' ); } - public get datatypeInput(): ChainablePromiseElement { return $( '#wb-newproperty-datatype' ); } - public get submitBtn(): ChainablePromiseElement { return $( 'button[type="submit"]' ); } +class SpecialNewProperty extends SubmittablePage { + public get labelInput(): ChainablePromiseElement { + return $( 'input[name="label"]' ); + } + public get descriptionInput(): ChainablePromiseElement { + return $( 'input[name="description"]' ); + } + public get aliasesInput(): ChainablePromiseElement { + return $( 'input[name="aliases"]' ); + } + public get datatypeInput(): ChainablePromiseElement { + return $( '#wb-newproperty-datatype' ); + } + public get submitBtn(): ChainablePromiseElement { + return $( 'button[type="submit"]' ); + } public async open( dataType?: string ): Promise { dataType = dataType ? '?datatype=' + dataType : ''; - await browser.url( process.env.MW_SERVER + '/wiki/Special:NewProperty' + dataType ); - } - - public async submit(): Promise { - const submitBtn = await this.submitBtn; - await submitBtn.waitForDisplayed(); - await submitBtn.click(); + await browser.url( + `${process.env.MW_SERVER}/wiki/Special:NewProperty${dataType}` + ); } } diff --git a/test/helpers/pages/submittable.page.ts b/test/helpers/pages/submittable.page.ts new file mode 100644 index 000000000..b5a096d3d --- /dev/null +++ b/test/helpers/pages/submittable.page.ts @@ -0,0 +1,15 @@ +import awaitDisplayed from '../await-displayed.js'; +import Page from './page.js'; + +class SubmittablePage extends Page { + public get submitBtn(): ChainablePromiseElement { + return $( 'button[type="submit"]' ); + } + + public async submit(): Promise { + const button = await awaitDisplayed( this.submitBtn ); + await button.click(); + } +} + +export default SubmittablePage; diff --git a/test/specs/elasticsearch/elasticsearch.ts b/test/specs/elasticsearch/elasticsearch.ts index 2e63ff7f2..5322978cc 100644 --- a/test/specs/elasticsearch/elasticsearch.ts +++ b/test/specs/elasticsearch/elasticsearch.ts @@ -2,6 +2,7 @@ import assert from 'assert'; import { getTestString } from 'wdio-mediawiki/Util.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import SearchResult from '../../helpers/types/search-result.js'; +import awaitDisplayed from '../../helpers/await-displayed.js'; const itemAlias: string = getTestString( 'alias' ); const itemLabel: string = getTestString( 'testItem' ); @@ -13,31 +14,29 @@ describe( 'ElasticSearch', function () { itemId = await WikibaseApi.createItem( itemLabel ); await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` ); - const addButtonEl = await $( + await awaitDisplayed( '.wikibase-toolbarbutton.wikibase-toolbar-item.wikibase-toolbar-button.wikibase-toolbar-button-add' ); - await addButtonEl.waitForDisplayed(); } ); it( 'Should be able to set alias', async () => { await browser.url( process.env.MW_SERVER + '/wiki/Special:SetAliases/' ); // input id - const inputIdEl = await $( '#wb-modifyentity-id input' ); - await inputIdEl.waitForDisplayed(); + const inputIdEl = await awaitDisplayed( '#wb-modifyentity-id input' ); await inputIdEl.setValue( itemId ); // input alias term and submit - const inputValueEl = await $( '#wb-modifyterm-value input' ); - await inputValueEl.waitForDisplayed(); + const inputValueEl = await awaitDisplayed( '#wb-modifyterm-value input' ); await inputValueEl.setValue( itemAlias ); const inputWidgetEl = await $( 'button.oo-ui-inputWidget-input' ); await inputWidgetEl.click(); // alias should be visible on item page - const aliasesViewEl = await $( '.wikibase-aliasesview-list-item' ); - await aliasesViewEl.waitForDisplayed(); + const aliasesViewEl = await awaitDisplayed( + '.wikibase-aliasesview-list-item' + ); const alias = await aliasesViewEl.getText(); assert.strictEqual( alias, itemAlias ); } ); diff --git a/test/specs/fedprops/item.ts b/test/specs/fedprops/item.ts index 05aca424e..28efb5659 100644 --- a/test/specs/fedprops/item.ts +++ b/test/specs/fedprops/item.ts @@ -4,6 +4,7 @@ import QueryServiceUI from '../../helpers/pages/queryservice-ui/queryservice-ui. import ItemPage from 'wdio-wikibase/pageobjects/item.page.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import { AxiosError } from 'axios'; +import awaitDisplayed from '../../helpers/await-displayed.js'; describe( 'Fed props Item', function () { const propertyId = 'P213'; @@ -40,13 +41,11 @@ describe( 'Fed props Item', function () { await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` ); - const actualPropertyEl = await $( '.wikibase-statementgroupview-property' ); - await actualPropertyEl.waitForDisplayed(); + const actualPropertyEl = await awaitDisplayed( '.wikibase-statementgroupview-property' ); const actualPropertyValue = await actualPropertyEl.getText(); assert( actualPropertyValue.includes( propertyValue ) ); // value is the label - const addStatementLink = await ItemPage.addStatementLink; - await addStatementLink.waitForDisplayed(); + await awaitDisplayed( ItemPage.addStatementLink ); } ); it( 'should NOT show up in Special:EntityData with ttl', async () => { @@ -93,8 +92,7 @@ describe( 'Fed props Item', function () { await browser.pause( 11 * 1000 ); await QueryServiceUI.submit(); - const resultTable = await QueryServiceUI.resultTable; - await resultTable.waitForDisplayed(); + await awaitDisplayed( QueryServiceUI.resultTable ); // Item should never have made its way into the query service, as TTL doesnt work assert( @@ -110,8 +108,7 @@ describe( 'Fed props Item', function () { await QueryServiceUI.open( `SELECT * WHERE{ wd:${itemId} ?p ?o }` ); await QueryServiceUI.submit(); - const resultTable = await QueryServiceUI.resultTable; - await resultTable.waitForDisplayed(); + await awaitDisplayed( QueryServiceUI.resultTable ); // Item should never have made its way into the query service, as TTL doesnt work assert( !( await QueryServiceUI.resultIncludes( 'schema:version' ) ) ); diff --git a/test/specs/fedprops/prefetching.ts b/test/specs/fedprops/prefetching.ts index 939a1077b..2a81fa05c 100644 --- a/test/specs/fedprops/prefetching.ts +++ b/test/specs/fedprops/prefetching.ts @@ -1,6 +1,7 @@ import { getTestString } from 'wdio-mediawiki/Util.js'; import assert from 'assert'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; +import awaitDisplayed from '../../helpers/await-displayed.js'; describe( 'Property Prefetching', function () { let itemId: string; @@ -11,8 +12,7 @@ describe( 'Property Prefetching', function () { await browser.url( 'https://www.wikidata.org/wiki/Special:ListProperties?datatype=string' ); - const specialLiEl = await $( 'ol.special li a' ); - await specialLiEl.waitForDisplayed(); + await awaitDisplayed( 'ol.special li a' ); const links = ( await $$( 'ol.special li a' ) ).slice( 0, NUM_PROPERTIES ); @@ -40,10 +40,9 @@ describe( 'Property Prefetching', function () { itemId = await WikibaseApi.createItem( getTestString( itemLabel ), data ); await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` ); - const toolbarButtonEl = await $( + await awaitDisplayed( '.wikibase-toolbarbutton.wikibase-toolbar-item.wikibase-toolbar-button.wikibase-toolbar-button-add' ); - await toolbarButtonEl.waitForDisplayed(); } ); it( 'should delete all statements and generate individual changes', async () => { @@ -67,8 +66,7 @@ describe( 'Property Prefetching', function () { await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}?action=history` ); - const historyEl = await $( '#pagehistory' ); - await historyEl.waitForDisplayed( { timeout: 2000 } ); + await awaitDisplayed( '#pagehistory', { timeout: 2000 } ); // +1 for the initial item creation assert.strictEqual( @@ -81,8 +79,7 @@ describe( 'Property Prefetching', function () { await browser.url( `${process.env.MW_SERVER}/wiki/Special:RecentChanges?limit=50&days=7&urlversion=2&enhanced=0` ); - const specialEl = await $( 'ul.special' ); - await specialEl.waitForDisplayed( { timeout: 2000 } ); + await awaitDisplayed( 'ul.special', { timeout: 2000 } ); // +1 for the initial item creation // +1 for the Main Page creation? diff --git a/test/specs/quickstatements/quickstatements.ts b/test/specs/quickstatements/quickstatements.ts index 9e0ff440e..2469bb51c 100644 --- a/test/specs/quickstatements/quickstatements.ts +++ b/test/specs/quickstatements/quickstatements.ts @@ -2,6 +2,7 @@ import assert from 'assert'; import lodash from 'lodash'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import { AxiosResponse } from 'axios'; +import awaitDisplayed from '../../helpers/await-displayed.js'; type ReferenceValue = { id: string; @@ -37,35 +38,28 @@ describe( 'QuickStatements Service', function () { it( 'Should be able to load the start page', async () => { await browser.url( process.env.QS_SERVER ); - const navbar = await $( 'nav.navbar' ); - await navbar.waitForDisplayed(); + await awaitDisplayed( 'nav.navbar' ); } ); it( 'Should be able to log in', async () => { await browser.url( process.env.QS_SERVER + '/api.php?action=oauth_redirect' ); // login after redirect - const wpNameEl = await $( '#wpName1' ); - await wpNameEl.waitForDisplayed(); - const wpPasswordEl = await $( '#wpPassword1' ); - await wpPasswordEl.waitForDisplayed(); - const wpLoginButtonEl = await $( '#wpLoginAttempt' ); - await wpLoginButtonEl.waitForDisplayed(); + const wpNameEl = await awaitDisplayed( '#wpName1' ); + const wpPasswordEl = await awaitDisplayed( '#wpPassword1' ); + const wpLoginButtonEl = await awaitDisplayed( '#wpLoginAttempt' ); await wpNameEl.setValue( process.env.MW_ADMIN_NAME ); await wpPasswordEl.setValue( process.env.MW_ADMIN_PASS ); await wpLoginButtonEl.click(); // oauth dialog - const authFormEl = await $( '#mw-mwoauth-authorize-form' ); - await authFormEl.waitForDisplayed(); - const authFormAcceptEl = await $( '#mw-mwoauth-accept' ); - await authFormAcceptEl.waitForDisplayed(); + await awaitDisplayed( '#mw-mwoauth-authorize-form' ); + const authFormAcceptEl = await awaitDisplayed( '#mw-mwoauth-accept' ); await authFormAcceptEl.click(); // redirect back to app - const navbarEl = await $( 'nav.navbar' ); - await navbarEl.waitForDisplayed(); + const navbarEl = await awaitDisplayed( 'nav.navbar' ); const navbarText = await navbarEl.getText(); assert( navbarText.includes( 'QuickStatements' ) ); } ); diff --git a/test/specs/repo/extensions/entityschema.ts b/test/specs/repo/extensions/entityschema.ts index a913c1e4d..1388d3ecd 100644 --- a/test/specs/repo/extensions/entityschema.ts +++ b/test/specs/repo/extensions/entityschema.ts @@ -2,6 +2,7 @@ import assert from 'assert'; import { readFile } from 'fs/promises'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; import { utf8 } from '../../../helpers/readFileEncoding.js'; +import awaitDisplayed from '../../../helpers/await-displayed.js'; describe( 'EntitySchema', function () { const testLabel = 'A label'; @@ -15,32 +16,32 @@ describe( 'EntitySchema', function () { await browser.url( process.env.MW_SERVER + '/wiki/EntitySchema:test' ); // gives the link to Special:NewEntitySchema - const noarticletextEl = await $( '.noarticletext a' ); - await noarticletextEl.waitForDisplayed(); + const noarticletextEl = await awaitDisplayed( '.noarticletext a' ); await noarticletextEl.click(); // set label and description - const labelInputEl = await $( 'input[name ="label"]' ); - await labelInputEl.waitForDisplayed(); + const labelInputEl = await awaitDisplayed( 'input[name ="label"]' ); await labelInputEl.setValue( testLabel ); - const descriptionInputEl = await $( 'input[name ="description"]' ); - await labelInputEl.waitForDisplayed(); + const descriptionInputEl = await awaitDisplayed( + 'input[name ="description"]' + ); await descriptionInputEl.setValue( testDescription ); // set template const shexTemplate = ( await readFile( new URL( 'entityschema.sx', import.meta.url ), utf8 ) - ).toString().trim(); - const schemaTextInputEl = await $( 'textarea[name ="schema-text"]' ); - await schemaTextInputEl.waitForDisplayed(); + ) + .toString() + .trim(); + const schemaTextInputEl = await awaitDisplayed( + 'textarea[name ="schema-text"]' + ); await schemaTextInputEl.setValue( shexTemplate ); - const submitButtonEl = await $( 'button[name ="submit"]' ); - await submitButtonEl.waitForDisplayed(); + const submitButtonEl = await awaitDisplayed( 'button[name ="submit"]' ); await submitButtonEl.click(); - const schemaTextEl = await $( '#entityschema-schema-text' ); - await schemaTextEl.waitForDisplayed(); + await awaitDisplayed( '#entityschema-schema-text' ); const entitySchemaEl = await $( '#entityschema-schema-text' ); const actualTemplate = ( await entitySchemaEl.getText() ).trim(); diff --git a/test/specs/repo/extensions/nuke.ts b/test/specs/repo/extensions/nuke.ts index 94bd35754..a960689f4 100644 --- a/test/specs/repo/extensions/nuke.ts +++ b/test/specs/repo/extensions/nuke.ts @@ -1,6 +1,7 @@ import assert from 'assert'; import SuiteLoginPage from '../../../helpers/pages/SuiteLoginPage.js'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; +import awaitDisplayed from '../../../helpers/await-displayed.js'; describe( 'Nuke', function () { beforeEach( async function () { @@ -26,26 +27,24 @@ describe( 'Nuke', function () { await SuiteLoginPage.loginAdmin(); await browser.url( process.env.MW_SERVER + '/wiki/Special:Nuke' ); - const buttonEl = await $( 'button.oo-ui-inputWidget-input' ); - await buttonEl.waitForDisplayed(); + const buttonEl = await awaitDisplayed( 'button.oo-ui-inputWidget-input' ); await buttonEl.click(); - const formEl = await $( 'form li' ); - await formEl.waitForDisplayed(); + await awaitDisplayed( 'form li' ); - const checkboxEl = await $( '.mw-checkbox-none' ); - await checkboxEl.waitForDisplayed(); + const checkboxEl = await awaitDisplayed( '.mw-checkbox-none' ); await checkboxEl.click(); - const vandalismCheckEl = await $( 'input[value="Vandalism"]' ); - await vandalismCheckEl.waitForDisplayed(); + + const vandalismCheckEl = await awaitDisplayed( 'input[value="Vandalism"]' ); await vandalismCheckEl.click(); - const submitButtonEl = await $( 'input[type="submit"]' ); - await submitButtonEl.waitForDisplayed(); + + const submitButtonEl = await awaitDisplayed( 'input[type="submit"]' ); await submitButtonEl.click(); + await browser.acceptAlert(); - const resultPageText = $( 'li*=has been queued for deletion' ); - await resultPageText.waitForDisplayed(); + await awaitDisplayed( 'li*=has been queued for deletion' ); + await browser.waitForJobs(); const pageIsGoneResult = await browser.makeRequest( diff --git a/test/specs/repo/extensions/syntax-highlight.ts b/test/specs/repo/extensions/syntax-highlight.ts index ef5ac3eff..b716265fa 100644 --- a/test/specs/repo/extensions/syntax-highlight.ts +++ b/test/specs/repo/extensions/syntax-highlight.ts @@ -1,6 +1,7 @@ import { readFile } from 'fs/promises'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; import { utf8 } from '../../../helpers/readFileEncoding.js'; +import awaitDisplayed from '../../../helpers/await-displayed.js'; describe( 'SyntaxHighlight', function () { beforeEach( async function () { @@ -20,7 +21,6 @@ describe( 'SyntaxHighlight', function () { await browser.url( process.env.MW_SERVER + '/wiki/Module:Olives' ); // should come with highlighted lua script - const highlightEl = await $( '.mw-highlight' ); - await highlightEl.waitForDisplayed(); + await awaitDisplayed( '.mw-highlight' ); } ); } ); diff --git a/test/specs/repo/extensions/universal-language-selector.ts b/test/specs/repo/extensions/universal-language-selector.ts index e2ac4bcbb..81e47f515 100644 --- a/test/specs/repo/extensions/universal-language-selector.ts +++ b/test/specs/repo/extensions/universal-language-selector.ts @@ -1,5 +1,6 @@ import assert from 'assert'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; +import awaitDisplayed from '../../../helpers/await-displayed.js'; describe( 'UniversalLanguageSelector', function () { beforeEach( async function () { @@ -8,16 +9,13 @@ describe( 'UniversalLanguageSelector', function () { it( 'Should be able to see the language selector menu', async () => { await browser.url( process.env.MW_SERVER ); - const searchInputEl = await $( '#searchInput' ); - await searchInputEl.waitForDisplayed(); + const searchInputEl = await awaitDisplayed( '#searchInput' ); await searchInputEl.click(); - const selectorEl = await $( '.imeselector' ); - await selectorEl.waitForDisplayed(); + const selectorEl = await awaitDisplayed( '.imeselector' ); await selectorEl.click(); - const firstLangEl = await $( '.imeselector-menu h3' ); - await firstLangEl.waitForDisplayed(); + const firstLangEl = await awaitDisplayed( '.imeselector-menu h3' ); const firstLang = await firstLangEl.getText(); assert.strictEqual( firstLang, 'English' ); diff --git a/test/specs/repo/extensions/visual-editor.ts b/test/specs/repo/extensions/visual-editor.ts index f36277dda..498a00622 100644 --- a/test/specs/repo/extensions/visual-editor.ts +++ b/test/specs/repo/extensions/visual-editor.ts @@ -1,5 +1,6 @@ import assert from 'assert'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; +import awaitDisplayed from '../../../helpers/await-displayed.js'; describe( 'VisualEditor', function () { beforeEach( async function () { @@ -12,42 +13,38 @@ describe( 'VisualEditor', function () { ); // start editing - const messageDialogEl = await $( '.oo-ui-messageDialog-actions' ); - await messageDialogEl.waitForDisplayed(); + await awaitDisplayed( '.oo-ui-messageDialog-actions' ); const messageDialogAEl = await $$( '.oo-ui-messageDialog-actions a' ); - const startEditbutton = messageDialogAEl[ 1 ]; - await startEditbutton.waitForDisplayed(); + const startEditbutton = await awaitDisplayed( messageDialogAEl[ 1 ] ); await startEditbutton.click(); await browser.pause( 5 * 1000 ); // disable notice popup and focus on editor - const toolLinkEl = await $( '.oo-ui-tool-name-notices .oo-ui-tool-link' ); - await toolLinkEl.waitForDisplayed(); + const toolLinkEl = await awaitDisplayed( + '.oo-ui-tool-name-notices .oo-ui-tool-link' + ); await toolLinkEl.click(); - const surfaceEl = await $( '.ve-ce-surface' ); - await surfaceEl.waitForDisplayed(); + const surfaceEl = await awaitDisplayed( '.ve-ce-surface' ); await surfaceEl.click(); await browser.keys( [ 'T', 'E', 'S', 'T' ] ); // save changes - const saveButtonEl = await $( 'a.ve-ui-toolbar-saveButton' ); - await saveButtonEl.waitForDisplayed(); + const saveButtonEl = await awaitDisplayed( 'a.ve-ui-toolbar-saveButton' ); await saveButtonEl.click(); // fill-out for summary popup and submit - const inputEl = await $( '.oo-ui-inputWidget-input' ); - await inputEl.waitForDisplayed(); + await awaitDisplayed( '.oo-ui-inputWidget-input' ); await browser.keys( 'X' ); - const primaryAEl = await $( '.oo-ui-processDialog-actions-primary a' ); - await primaryAEl.waitForDisplayed(); + const primaryAEl = await awaitDisplayed( + '.oo-ui-processDialog-actions-primary a' + ); await primaryAEl.click(); - const outputEl = await $( '.mw-parser-output' ); - await outputEl.waitForDisplayed(); + const outputEl = await awaitDisplayed( '.mw-parser-output' ); const contentBody = await outputEl.getText(); assert.strictEqual( contentBody, 'TEST' ); diff --git a/test/specs/repo/extensions/wikibase-local-media.ts b/test/specs/repo/extensions/wikibase-local-media.ts index ece309728..bfd11bebf 100644 --- a/test/specs/repo/extensions/wikibase-local-media.ts +++ b/test/specs/repo/extensions/wikibase-local-media.ts @@ -2,6 +2,7 @@ import assert from 'assert'; import SuiteLoginPage from '../../../helpers/pages/SuiteLoginPage.js'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; +import awaitDisplayed from '../../../helpers/await-displayed.js'; describe( 'WikibaseLocalMedia', function () { let propertyId: string; @@ -15,18 +16,14 @@ describe( 'WikibaseLocalMedia', function () { await browser.url( process.env.MW_SERVER + '/wiki/Special:Upload/' ); - const fileUpload = await $( '#wpUploadFile' ); - await fileUpload.waitForDisplayed(); - + const fileUpload = await awaitDisplayed( '#wpUploadFile' ); const filePath = new URL( 'image.png', import.meta.url ); await fileUpload.setValue( filePath.pathname ); - const submitButtonEl = await $( 'input.mw-htmlform-submit' ); - await submitButtonEl.waitForDisplayed(); + const submitButtonEl = await awaitDisplayed( 'input.mw-htmlform-submit' ); await submitButtonEl.click(); - const firstHeadingEl = await $( '#firstHeading' ); - await firstHeadingEl.waitForDisplayed(); + const firstHeadingEl = await awaitDisplayed( '#firstHeading' ); const title = await firstHeadingEl.getText(); assert.strictEqual( title, 'File:Image.png' ); @@ -38,8 +35,7 @@ describe( 'WikibaseLocalMedia', function () { await browser.url( `${process.env.MW_SERVER}/wiki/Property:${propertyId}` ); - const firstHeadingEl = await $( '#firstHeading' ); - await firstHeadingEl.waitForDisplayed(); + const firstHeadingEl = await awaitDisplayed( '#firstHeading' ); const title = await firstHeadingEl.getText(); assert.strictEqual( title.includes( propertyId ), true ); @@ -63,10 +59,8 @@ describe( 'WikibaseLocalMedia', function () { const itemId = await WikibaseApi.createItem( 'image-test', data ); await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` ); - const snakviewEl = await $( '.wikibase-snakview-value img' ); - await snakviewEl.waitForDisplayed(); - const imageSourceEl = await $( '.wikibase-snakview-value img' ); - await imageSourceEl.waitForDisplayed(); + await awaitDisplayed( '.wikibase-snakview-value img' ); + const imageSourceEl = await awaitDisplayed( '.wikibase-snakview-value img' ); const imageSource = await imageSourceEl.getAttribute( 'src' ); assert.strictEqual( imageSource.includes( 'Image.png' ), true ); diff --git a/test/specs/repo/property.ts b/test/specs/repo/property.ts index 9f60ffe72..cf6475229 100644 --- a/test/specs/repo/property.ts +++ b/test/specs/repo/property.ts @@ -1,6 +1,7 @@ import assert from 'assert'; import Property from '../../helpers/pages/entity/property.page.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; +import awaitDisplayed from '../../helpers/await-displayed.js'; describe( 'Property', function () { let propertyId = null; @@ -11,14 +12,12 @@ describe( 'Property', function () { const propertyIdSelector = `=${propertyId} (${propertyId})`; // =P1 (P1) await Property.open( propertyId ); - const addStatementEl = await Property.addStatement; - await addStatementEl.waitForDisplayed(); + const addStatementEl = await awaitDisplayed( Property.addStatement ); await addStatementEl.click(); // fill out property id for statement await browser.keys( propertyId.split( '' ) ); - const propertyIdEl = await $( propertyIdSelector ); - await propertyIdEl.waitForDisplayed(); + const propertyIdEl = await awaitDisplayed( propertyIdSelector ); await propertyIdEl.click(); await browser.keys( [ 'S', 'T', 'A', 'T', 'E', 'M', 'E', 'N', 'T' ] ); @@ -28,16 +27,13 @@ describe( 'Property', function () { await saveEl.click(); await browser.pause( 1000 * 2 ); - const referenceEl = await Property.addReference; - await referenceEl.waitForDisplayed(); + const referenceEl = await awaitDisplayed( Property.addReference ); await referenceEl.click(); // fill out property id for reference - const entitySelectorEl = await $( '.ui-entityselector-input' ); - await entitySelectorEl.waitForDisplayed(); + await awaitDisplayed( '.ui-entityselector-input' ); await browser.pause( 1000 * 1 ); await browser.keys( propertyId.split( '' ) ); - // await $( propertyIdSelector ).waitForDisplayed(); // await $( propertyIdSelector ).click(); await propertyIdEl.waitForDisplayed(); await propertyIdEl.click(); diff --git a/test/specs/repo/queryservice.ts b/test/specs/repo/queryservice.ts index 6ac4191a5..c99408913 100644 --- a/test/specs/repo/queryservice.ts +++ b/test/specs/repo/queryservice.ts @@ -4,6 +4,7 @@ import QueryServiceUI from '../../helpers/pages/queryservice-ui/queryservice-ui. import SuiteLoginPage from '../../helpers/pages/SuiteLoginPage.js'; import { stringify } from 'querystring'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; +import awaitDisplayed from '../../helpers/await-displayed.js'; describe( 'QueryService', () => { it( 'Should not be able to post to sparql endpoint', async () => { @@ -74,7 +75,7 @@ describe( 'QueryService', () => { await browser.pause( 20 * 1000 ); await QueryServiceUI.submit(); - await ( await QueryServiceUI.resultTable ).waitForDisplayed(); + await awaitDisplayed( QueryServiceUI.resultTable ); assert( await QueryServiceUI.resultIncludes( 'schema:version' ) ); assert( await QueryServiceUI.resultIncludes( 'schema:dateModified' ) ); @@ -101,7 +102,7 @@ describe( 'QueryService', () => { await QueryServiceUI.open( `SELECT * WHERE{ ?s wdt:${propertyId} ?o }` ); await QueryServiceUI.submit(); - await ( await QueryServiceUI.resultTable ).waitForDisplayed(); + await awaitDisplayed( QueryServiceUI.resultTable ); // should be set only to the item assert( @@ -123,10 +124,9 @@ describe( 'QueryService', () => { await browser.url( browser.options.baseUrl + '/index.php?' + stringify( query ) ); - const destructiveButtonEl = await $( + const destructiveButtonEl = await awaitDisplayed( '.oo-ui-flaggedElement-destructive button' ); - await destructiveButtonEl.waitForDisplayed(); await destructiveButtonEl.click(); await QueryServiceUI.open( `SELECT * WHERE{ wd:${itemId} ?p ?o }` ); @@ -136,8 +136,7 @@ describe( 'QueryService', () => { await QueryServiceUI.submit(); - const resultTable = await QueryServiceUI.resultTable; - await resultTable.waitForDisplayed(); + const resultTable = await awaitDisplayed( QueryServiceUI.resultTable ); const resultText = await resultTable.getText(); // item should not be included diff --git a/test/specs/repo/special-item.ts b/test/specs/repo/special-item.ts index b3a10fe32..465596bf9 100644 --- a/test/specs/repo/special-item.ts +++ b/test/specs/repo/special-item.ts @@ -1,3 +1,4 @@ +import awaitDisplayed from '../../helpers/await-displayed.js'; import SpecialNewItem from '../../helpers/pages/special/new-item.page.js'; import ItemPage from 'wdio-wikibase/pageobjects/item.page.js'; @@ -5,21 +6,17 @@ describe( 'Special:NewItem', function () { it( 'Should be able to create a new item', async () => { await SpecialNewItem.open(); - const labelInput = await SpecialNewItem.labelInput; - await labelInput.waitForDisplayed(); + const labelInput = await awaitDisplayed( SpecialNewItem.labelInput ); await labelInput.setValue( 'Cool label' ); - const descriptionInput = await SpecialNewItem.descriptionInput; - await SpecialNewItem.descriptionInput.waitForDisplayed(); + const descriptionInput = await awaitDisplayed( SpecialNewItem.descriptionInput ); await descriptionInput.setValue( 'Cool description' ); - const aliasesInput = await SpecialNewItem.aliasesInput; - await aliasesInput.waitForDisplayed(); + const aliasesInput = await awaitDisplayed( SpecialNewItem.aliasesInput ); await aliasesInput.setValue( 'Great job!|Bra Jobbat' ); await SpecialNewItem.submit(); - const addStatementLink = await ItemPage.addStatementLink; - await addStatementLink.waitForDisplayed(); + await awaitDisplayed( ItemPage.addStatementLink ); } ); } ); diff --git a/test/specs/repo/special-property.ts b/test/specs/repo/special-property.ts index aec23de7b..74d1807ef 100644 --- a/test/specs/repo/special-property.ts +++ b/test/specs/repo/special-property.ts @@ -1,28 +1,25 @@ import assert from 'assert'; import SpecialNewProperty from '../../helpers/pages/special/new-property.page.js'; +import awaitDisplayed from '../../helpers/await-displayed.js'; describe( 'Special:NewProperty', function () { it( 'Should be able to create a new property', async () => { await SpecialNewProperty.open( 'string' ); - const labelInput = await SpecialNewProperty.labelInput; - await labelInput.waitForDisplayed(); + const labelInput = await awaitDisplayed( SpecialNewProperty.labelInput ); await labelInput.setValue( 'Cool label' ); - const descriptionInput = await SpecialNewProperty.descriptionInput; - await descriptionInput.waitForDisplayed(); + const descriptionInput = await awaitDisplayed( SpecialNewProperty.descriptionInput ); await descriptionInput.setValue( 'Cool description' ); - const aliasesInput = await SpecialNewProperty.aliasesInput; - await aliasesInput.waitForDisplayed(); + const aliasesInput = await awaitDisplayed( SpecialNewProperty.aliasesInput ); await aliasesInput.setValue( 'Great job!|Bra Jobbat' ); await SpecialNewProperty.submit(); - const propertyviewDatatypeValueEl = await $( + const propertyviewDatatypeValueEl = await awaitDisplayed( '.wikibase-propertyview-datatype-value' ); - await propertyviewDatatypeValueEl.waitForDisplayed(); const dataTypeText = await propertyviewDatatypeValueEl.getText(); assert.strictEqual( dataTypeText, 'String' ); diff --git a/test/specs/repo/special-version.ts b/test/specs/repo/special-version.ts index 60f361b91..b2b145b1d 100644 --- a/test/specs/repo/special-version.ts +++ b/test/specs/repo/special-version.ts @@ -1,5 +1,6 @@ import assert from 'assert'; import { skipIfExtensionNotPresent } from '../../helpers/default-functions.js'; +import awaitDisplayed from '../../helpers/await-displayed.js'; describe( 'Special:Version', function () { it( 'Should contain the correct MediaWiki version', async function () { @@ -8,8 +9,7 @@ describe( 'Special:Version', function () { } await browser.url( `${process.env.MW_SERVER}/wiki/Special:Version` ); - const softwareEl = await $( '#sv-software' ); - await softwareEl.waitForDisplayed(); + const softwareEl = await awaitDisplayed( '#sv-software' ); const text = await softwareEl.getText(); assert.strictEqual( text.includes( `MediaWiki\t${process.env.MEDIAWIKI_VERSION}` ), @@ -53,10 +53,9 @@ describe( 'Special:Version', function () { await browser.url( `${process.env.MW_SERVER}/wiki/Special:Version` ); // /wiki/Special:Version generate these for each installed extension - const elementSelector = await $( + const elementSelector = await awaitDisplayed( `#mw-version-ext-${extensionPackage}-${extension.replace( / /g, '_' )}` ); - await elementSelector.waitForDisplayed(); await elementSelector.scrollIntoView(); assert( elementSelector.getText() !== null ); diff --git a/test/specs/repo_client/extensions/scribunto-item.ts b/test/specs/repo_client/extensions/scribunto-item.ts index b2bbbf84b..5d310a950 100644 --- a/test/specs/repo_client/extensions/scribunto-item.ts +++ b/test/specs/repo_client/extensions/scribunto-item.ts @@ -7,6 +7,7 @@ import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js import { utf8 } from '../../../helpers/readFileEncoding.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import ExternalChange from '../../../helpers/types/external-change.js'; +import awaitDisplayed from '../../../helpers/await-displayed.js'; const itemLabel = getTestString( 'The Item' ); @@ -38,14 +39,16 @@ describe( 'Scribunto Item', function () { itemId = await WikibaseApi.createItem( itemLabel, data ); await browser.url( process.env.MW_SERVER + '/wiki/Item:' + itemId ); - const addButtonEl = await $( + await awaitDisplayed( '.wikibase-toolbarbutton.wikibase-toolbar-item.wikibase-toolbar-button.wikibase-toolbar-button-add' ); - await addButtonEl.waitForDisplayed(); } ); it( 'Should be able to reference an item on client using Lua', async () => { - const template = await readFile( new URL( 'repo-client.lua', import.meta.url ), utf8 ); + const template = await readFile( + new URL( 'repo-client.lua', import.meta.url ), + utf8 + ); const luaScript = template .toString() .replace( '', itemId ) @@ -77,10 +80,9 @@ describe( 'Scribunto Item', function () { browser.options.baseUrl + '/index.php?' + stringify( query ) ); - const destructiveButtonEl = await $( + const destructiveButtonEl = await awaitDisplayed( '.oo-ui-flaggedElement-destructive button' ); - await destructiveButtonEl.waitForDisplayed(); await destructiveButtonEl.click(); await browser.url( process.env.MW_SERVER + '/wiki/Item:' + itemId ); diff --git a/test/specs/repo_client/item.ts b/test/specs/repo_client/item.ts index b9a867879..762c85063 100644 --- a/test/specs/repo_client/item.ts +++ b/test/specs/repo_client/item.ts @@ -4,6 +4,7 @@ import SuiteLoginPage from '../../helpers/pages/SuiteLoginPage.js'; import { stringify } from 'querystring'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import ExternalChange from '../../helpers/types/external-change.js'; +import awaitDisplayed from '../../helpers/await-displayed.js'; const itemLabel = getTestString( 'The Item' ); @@ -22,8 +23,7 @@ describe( 'Item', function () { await browser.url( process.env.MW_CLIENT_SERVER + '/wiki/Special:NewItem?uselang=qqx' ); - const heading = await $( 'h1#firstHeading' ); - await heading.waitForDisplayed(); + const heading = await awaitDisplayed( 'h1#firstHeading' ); const notFoundText = await heading.getText(); assert.strictEqual( notFoundText, '(nosuchspecialpage)' ); } ); @@ -32,8 +32,7 @@ describe( 'Item', function () { await browser.url( process.env.MW_SERVER + '/wiki/Special:NewItem?uselang=qqx' ); - const heading = await $( 'h1#firstHeading' ); - await heading.waitForDisplayed(); + const heading = await awaitDisplayed( 'h1#firstHeading' ); const createNewItem = await heading.getText(); assert.strictEqual( createNewItem, '(special-newitem)' ); } ); @@ -57,10 +56,9 @@ describe( 'Item', function () { itemId = await WikibaseApi.createItem( itemLabel, data ); await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` ); - const button = await $( + await awaitDisplayed( '.wikibase-toolbarbutton.wikibase-toolbar-item.wikibase-toolbar-button.wikibase-toolbar-button-add' ); - await button.waitForDisplayed(); } ); // creates usage @@ -81,19 +79,19 @@ describe( 'Item', function () { await browser.url( `${process.env.MW_SERVER}/wiki/Special:SetSiteLink/Q1?site=client_wiki&page=${pageTitle}` ); - const submitButtonEl = await $( '#wb-setsitelink-submit button' ); - await submitButtonEl.waitForDisplayed(); + const submitButtonEl = await awaitDisplayed( + '#wb-setsitelink-submit button' + ); await submitButtonEl.click(); - const siteLinkEl = await $( '.wikibase-sitelinklistview-listview li' ); - await siteLinkEl.waitForDisplayed(); + const siteLinkEl = await awaitDisplayed( + '.wikibase-sitelinklistview-listview li' + ); const siteLinkValue = await siteLinkEl.getText(); // label should come from repo property - assert( - siteLinkValue.includes( 'client_wiki' ) && - siteLinkValue.includes( pageTitle ) - ); + assert( siteLinkValue.includes( 'client_wiki' ) ); + assert( siteLinkValue.includes( pageTitle ) ); } ); it( 'Should be able to see site-link change is dispatched to client', async () => { @@ -122,10 +120,9 @@ describe( 'Item', function () { `${browser.options.baseUrl}/index.php?${stringify( query )}` ); - const destructiveButtonEl = await $( + const destructiveButtonEl = await awaitDisplayed( '.oo-ui-flaggedElement-destructive button' ); - await destructiveButtonEl.waitForDisplayed(); await destructiveButtonEl.click(); await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` );