Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T350363 - Remove unnecessary waitForDisplayed() #506

Merged
merged 26 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions test/helpers/await-displayed.ts

This file was deleted.

41 changes: 13 additions & 28 deletions test/helpers/default-functions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import axios, { AxiosResponse } from 'axios';
import assert from 'assert';
import axios, { AxiosResponse } from 'axios';
import { exec } from 'child_process';
import lodash from 'lodash';
import { Context } from 'mocha';
import WikibaseApi from 'wdio-wikibase/wikibase.api.js';
import Binding from './types/binding.js';
import BotResponse from './types/bot-response.js';
import DatabaseConfig from './types/database-config.js';
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';
import LuaCPUValue from './types/lua-cpu-value.js';

export function defaultFunctions(): void {
/**
Expand Down Expand Up @@ -140,32 +139,25 @@ export function defaultFunctions(): void {
'.oo-ui-messageDialog-actions .oo-ui-flaggedElement-progressive'
);
if ( startEditbutton.elementId ) {
await startEditbutton.waitForDisplayed();
await startEditbutton.click();

// wait for fade out animation to finish
await browser.pause( 2 * 1000 );
}

// fill out form
const textBoxEl = await awaitDisplayed( '#wpTextbox1' );
await textBoxEl.setValue( content.toString() );
await $( '#wpTextbox1' ).setValue( content.toString() );

if ( captcha ) {
const captchaEl = await awaitDisplayed( '#wpCaptchaWord' );
await captchaEl.setValue( captcha );
await $( '#wpCaptchaWord' ).setValue( captcha );
}

// save page
await browser.execute( async () => {
const editFormEl = await $( '#editform.mw-editform' );
await editFormEl.submit();
} );
await browser.execute( async () => $( '#editform.mw-editform' ).submit() );

await browser.pause( 2 * 1000 );

const contentTextEl = await awaitDisplayed( '#mw-content-text' );
return await contentTextEl.getText();
return await $( '#mw-content-text' ).getText();
}
);

Expand Down Expand Up @@ -229,20 +221,17 @@ export function defaultFunctions(): void {
await browser.url( `${process.env.QS_SERVER}/#/batch` );

// create a batch
const createBatchBoxTextareaEl = await awaitDisplayed( '.create_batch_box textarea' );
await createBatchBoxTextareaEl.setValue( theQuery );
await $( '.create_batch_box textarea' ).setValue( theQuery );

await browser.pause( 1000 );

// click import
const importButtonEl = await awaitDisplayed( "button[tt='dialog_import_v1']" );
await importButtonEl.click();
await $( "button[tt='dialog_import_v1']" ).click();

await browser.pause( 1000 );

// click run
const runButtonEl = await awaitDisplayed( "button[tt='run']" );
await runButtonEl.click();
await $( "button[tt='run']" ).click();

const commands = await $$( '.command_status' );

Expand Down Expand Up @@ -293,7 +282,7 @@ export function defaultFunctions(): void {
serverURL: string = process.env.MW_SERVER,
// default timeout is 1 second less than default Mocha test timeout
timeout: number = ( Number.parseInt( process.env.MOCHA_OPTS_TIMEOUT ) ||
90 * 1000 ) - 1000,
90 * 1000 ) - 1000,
timeoutMsg: string = null
): Promise<boolean> => {
let jobsInQueue: number;
Expand All @@ -313,11 +302,7 @@ export function defaultFunctions(): void {
timeout,
timeoutMsg:
timeoutMsg ||
`Timeout: Job queue on "${
serverURL
}" still contains ${
jobsInQueue
} jobs after waiting ${
`Timeout: Job queue on "${serverURL}" still contains ${jobsInQueue} jobs after waiting ${
timeout / 1000
} seconds.`
}
Expand Down
3 changes: 1 addition & 2 deletions test/helpers/pages/queryservice-ui/queryservice-ui.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class QueryServiceUI extends SubmittablePage {
}

public async resultIncludes( prop: string, value?: string ): Promise<boolean> {
const resultTable = await this.resultTable;
const text = await resultTable.getText();
const text = await this.resultTable.getText();
if ( !value ) {
return text.includes( prop );
}
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/pages/special/list-properties.page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Page from '../page.js';
import awaitDisplayed from '../../await-displayed.js';
import { ChainablePromiseArray } from 'webdriverio';

class SpecialListProperties extends Page {
public get content(): ChainablePromiseElement {
return $( '.mw-spcontent' );
}
public get properties(): ChainablePromiseArray {
public get properties(): ChainablePromiseArray<WebdriverIO.ElementArray> {
return $$( '.mw-spcontent ol li' );
}

Expand All @@ -22,7 +22,7 @@ class SpecialListProperties extends Page {
`${process.env.MW_SERVER}/wiki/Special:ListProperties?${dataType}&${limit}&${offset}`
);

await awaitDisplayed( this.content );
await this.content;
}
}

Expand Down
11 changes: 5 additions & 6 deletions test/helpers/pages/special/new-property.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SubmittablePage from '../submittable.page.js';
import awaitDisplayed from '../../await-displayed.js';

class SpecialNewProperty extends SubmittablePage {
public get labelInput(): ChainablePromiseElement {
Expand All @@ -23,11 +22,11 @@ class SpecialNewProperty extends SubmittablePage {
await browser.url(
`${process.env.MW_SERVER}/wiki/Special:NewProperty${dataType}`
);
await awaitDisplayed( this.labelInput );
await awaitDisplayed( this.descriptionInput );
await awaitDisplayed( this.aliasesInput );
await awaitDisplayed( this.datatypeInput );
await awaitDisplayed( this.submitBtn );
await this.labelInput;
await this.descriptionInput;
await this.aliasesInput;
await this.datatypeInput;
await this.submitBtn;
}
}

Expand Down
4 changes: 1 addition & 3 deletions test/helpers/pages/submittable.page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import awaitDisplayed from '../await-displayed.js';
import Page from './page.js';

class SubmittablePage extends Page {
Expand All @@ -7,8 +6,7 @@ class SubmittablePage extends Page {
}

public async submit(): Promise<void> {
const button = await awaitDisplayed( this.submitBtn );
await button.click();
await this.submitBtn.click();
}
}

Expand Down
29 changes: 11 additions & 18 deletions test/specs/elasticsearch/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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' );
Expand All @@ -14,7 +13,7 @@ describe( 'ElasticSearch', function () {
itemId = await WikibaseApi.createItem( itemLabel );

await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` );
await awaitDisplayed(
await $(
'.wikibase-toolbarbutton.wikibase-toolbar-item.wikibase-toolbar-button.wikibase-toolbar-button-add'
);
} );
Expand All @@ -23,21 +22,15 @@ describe( 'ElasticSearch', function () {
await browser.url( process.env.MW_SERVER + '/wiki/Special:SetAliases/' );

// input id
const inputIdEl = await awaitDisplayed( '#wb-modifyentity-id input' );
await inputIdEl.setValue( itemId );
await $( '#wb-modifyentity-id input' ).setValue( itemId );

// input alias term and submit
const inputValueEl = await awaitDisplayed( '#wb-modifyterm-value input' );
await inputValueEl.setValue( itemAlias );
await $( '#wb-modifyterm-value input' ).setValue( itemAlias );

const inputWidgetEl = await $( 'button.oo-ui-inputWidget-input' );
await inputWidgetEl.click();
await $( 'button.oo-ui-inputWidget-input' ).click();

// alias should be visible on item page
const aliasesViewEl = await awaitDisplayed(
'.wikibase-aliasesview-list-item'
);
const alias = await aliasesViewEl.getText();
const alias = await $( '.wikibase-aliasesview-list-item' ).getText();
assert.strictEqual( alias, itemAlias );
} );

Expand Down Expand Up @@ -65,9 +58,9 @@ describe( 'ElasticSearch', function () {
);
assert(
searchResult.length === 1 &&
searchResult[ 0 ].id === itemId &&
searchResult[ 0 ].match.type === 'label' &&
searchResult[ 0 ].match.text === itemLabel
searchResult[ 0 ].id === itemId &&
searchResult[ 0 ].match.type === 'label' &&
searchResult[ 0 ].match.text === itemLabel
);
} );

Expand Down Expand Up @@ -96,9 +89,9 @@ describe( 'ElasticSearch', function () {

assert(
searchResult.length === 1 &&
searchResult[ 0 ].id === itemId &&
searchResult[ 0 ].match.type === 'alias' &&
searchResult[ 0 ].match.text === itemAlias
searchResult[ 0 ].id === itemId &&
searchResult[ 0 ].match.type === 'alias' &&
searchResult[ 0 ].match.text === itemAlias
);
} );
} );
18 changes: 9 additions & 9 deletions test/specs/fedprops/item.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { getTestString } from 'wdio-mediawiki/Util.js';
import assert from 'assert';
import QueryServiceUI from '../../helpers/pages/queryservice-ui/queryservice-ui.page.js';
import { AxiosError } from 'axios';
import { getTestString } from 'wdio-mediawiki/Util.js';
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';
import QueryServiceUI from '../../helpers/pages/queryservice-ui/queryservice-ui.page.js';

describe( 'Fed props Item', function () {
const propertyId = 'P213';
Expand Down Expand Up @@ -41,11 +40,12 @@ describe( 'Fed props Item', function () {

await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` );

const actualPropertyEl = await awaitDisplayed( '.wikibase-statementgroupview-property' );
const actualPropertyValue = await actualPropertyEl.getText();
const actualPropertyValue = await $(
'.wikibase-statementgroupview-property'
).getText();
assert( actualPropertyValue.includes( propertyValue ) ); // value is the label

await awaitDisplayed( ItemPage.addStatementLink );
await ItemPage.addStatementLink;
} );

it( 'should NOT show up in Special:EntityData with ttl', async () => {
Expand Down Expand Up @@ -92,7 +92,7 @@ describe( 'Fed props Item', function () {
await browser.pause( 11 * 1000 );

await QueryServiceUI.submit();
await awaitDisplayed( QueryServiceUI.resultTable );
await QueryServiceUI.resultTable;

// Item should never have made its way into the query service, as TTL doesnt work
assert(
Expand All @@ -108,7 +108,7 @@ describe( 'Fed props Item', function () {
await QueryServiceUI.open( `SELECT * WHERE{ wd:${itemId} ?p ?o }` );

await QueryServiceUI.submit();
await awaitDisplayed( QueryServiceUI.resultTable );
await QueryServiceUI.resultTable;

// Item should never have made its way into the query service, as TTL doesnt work
assert( !( await QueryServiceUI.resultIncludes( 'schema:version' ) ) );
Expand Down
11 changes: 5 additions & 6 deletions test/specs/fedprops/prefetching.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getTestString } from 'wdio-mediawiki/Util.js';
import assert from 'assert';
import { getTestString } from 'wdio-mediawiki/Util.js';
import WikibaseApi from 'wdio-wikibase/wikibase.api.js';
import awaitDisplayed from '../../helpers/await-displayed.js';

describe( 'Property Prefetching', function () {
let itemId: string;
Expand All @@ -12,7 +11,7 @@ describe( 'Property Prefetching', function () {
await browser.url(
'https://www.wikidata.org/wiki/Special:ListProperties?datatype=string'
);
await awaitDisplayed( 'ol.special li a' );
await $( 'ol.special li a' );

const links = ( await $$( 'ol.special li a' ) ).slice( 0, NUM_PROPERTIES );

Expand Down Expand Up @@ -40,7 +39,7 @@ describe( 'Property Prefetching', function () {
itemId = await WikibaseApi.createItem( getTestString( itemLabel ), data );

await browser.url( `${process.env.MW_SERVER}/wiki/Item:${itemId}` );
await awaitDisplayed(
await $(
'.wikibase-toolbarbutton.wikibase-toolbar-item.wikibase-toolbar-button.wikibase-toolbar-button-add'
);
} );
Expand All @@ -66,7 +65,7 @@ describe( 'Property Prefetching', function () {
await browser.url(
`${process.env.MW_SERVER}/wiki/Item:${itemId}?action=history`
);
await awaitDisplayed( '#pagehistory', { timeout: 2000 } );
await $( '#pagehistory' );

// +1 for the initial item creation
assert.strictEqual(
Expand All @@ -79,7 +78,7 @@ describe( 'Property Prefetching', function () {
await browser.url(
`${process.env.MW_SERVER}/wiki/Special:RecentChanges?limit=50&days=7&urlversion=2&enhanced=0`
);
await awaitDisplayed( 'ul.special', { timeout: 2000 } );
await $( 'ul.special' );

// +1 for the initial item creation
// +1 for the Main Page creation?
Expand Down
Loading
Loading