Skip to content

Commit

Permalink
T346214 await displayed (#490)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RickiJay-WMDE authored Oct 24, 2023
1 parent 12ab4bc commit 86c994a
Show file tree
Hide file tree
Showing 24 changed files with 215 additions and 211 deletions.
15 changes: 15 additions & 0 deletions test/helpers/await-displayed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type WaitForOptions = {
timeout?: number;
};

const awaitDisplayed = async (
identifier: string | ChainablePromiseElement | WebdriverIO.Element,
options?: WaitForOptions
): Promise<WebdriverIO.Element> => {
const resultElement =
typeof identifier === 'string' ? await $( identifier ) : await identifier;
await resultElement.waitForDisplayed( options );
return resultElement;
};

export default awaitDisplayed;
19 changes: 7 additions & 12 deletions test/helpers/default-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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 );
}

Expand All @@ -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();
}
);
Expand Down Expand Up @@ -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' );
Expand Down
14 changes: 10 additions & 4 deletions test/helpers/pages/entity/property.page.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await browser.url( process.env.MW_SERVER + '/wiki/Property:' + id );
await browser.url( `${process.env.MW_SERVER}/wiki/Property:${id}` );
}
}

Expand Down
26 changes: 14 additions & 12 deletions test/helpers/pages/queryservice-ui/queryservice-ui.page.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
if ( prefixes ) {
Expand All @@ -13,12 +21,6 @@ class QueryServiceUI extends Page {
return super.open( '/#' + encodeURI( query ) );
}

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

public async resultIncludes( prop: string, value?: string ): Promise<boolean> {
const resultTable = await this.resultTable;
const text = await resultTable.getText();
Expand Down
28 changes: 15 additions & 13 deletions test/helpers/pages/special/new-item.page.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
const button = await this.submitBtn;
await this.submitBtn.waitForDisplayed();
await button.click();
public async open(): Promise<void> {
await browser.url( `${process.env.MW_SERVER}/wiki/Special:NewItem` );
}
}

Expand Down
34 changes: 20 additions & 14 deletions test/helpers/pages/special/new-property.page.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
dataType = dataType ? '?datatype=' + dataType : '';
await browser.url( process.env.MW_SERVER + '/wiki/Special:NewProperty' + dataType );
}

public async submit(): Promise<void> {
const submitBtn = await this.submitBtn;
await submitBtn.waitForDisplayed();
await submitBtn.click();
await browser.url(
`${process.env.MW_SERVER}/wiki/Special:NewProperty${dataType}`
);
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/helpers/pages/submittable.page.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const button = await awaitDisplayed( this.submitBtn );
await button.click();
}
}

export default SubmittablePage;
15 changes: 7 additions & 8 deletions test/specs/elasticsearch/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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 );
} );
Expand Down
13 changes: 5 additions & 8 deletions test/specs/fedprops/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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(
Expand All @@ -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' ) ) );
Expand Down
13 changes: 5 additions & 8 deletions test/specs/fedprops/prefetching.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 );

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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(
Expand All @@ -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?
Expand Down
Loading

0 comments on commit 86c994a

Please sign in to comment.