From 239cb079f4e3ceeeec876969724e80d24915b6b0 Mon Sep 17 00:00:00 2001 From: Erwin Heitzman <15839059+erwinheitzman@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:13:48 +0100 Subject: [PATCH 1/2] removal of the chainable promise types --- .../wdio-browser-runner/src/browser/expect.ts | 3 +- .../webdriverio/src/commands/browser/$$.ts | 2 +- .../webdriverio/src/commands/element/$$.ts | 2 +- packages/webdriverio/src/types.ts | 63 +------------------ .../webdriverio/src/utils/actions/pointer.ts | 3 +- .../webdriverio/src/utils/actions/wheel.ts | 3 +- 6 files changed, 7 insertions(+), 69 deletions(-) diff --git a/packages/wdio-browser-runner/src/browser/expect.ts b/packages/wdio-browser-runner/src/browser/expect.ts index 96d7b62682b..f16daccbf22 100644 --- a/packages/wdio-browser-runner/src/browser/expect.ts +++ b/packages/wdio-browser-runner/src/browser/expect.ts @@ -1,7 +1,6 @@ import { expect, type MatcherContext, type ExpectationResult, type SyncExpectationResult } from 'expect' import { MESSAGE_TYPES, type Workers } from '@wdio/types' import { $ } from '@wdio/globals' -import type { ChainablePromiseElement } from 'webdriverio' import { getCID } from './utils.js' import { WDIO_EVENT_NAME } from '../constants.js' @@ -31,7 +30,7 @@ const COMMAND_TIMEOUT = 30 * 1000 // 30s * @returns a matcher result computed in the Node.js environment */ function createMatcher (matcherName: string) { - return async function (this: MatcherContext, context: WebdriverIO.Browser | WebdriverIO.Element | ChainablePromiseElement | ChainablePromiseArray, ...args: any[]) { + return async function (this: MatcherContext, context: WebdriverIO.Browser | Awaited | Awaited, ...args: any[]) { const cid = getCID() if (!import.meta.hot || !cid) { return { diff --git a/packages/webdriverio/src/commands/browser/$$.ts b/packages/webdriverio/src/commands/browser/$$.ts index d781bf032ac..14aba149eba 100644 --- a/packages/webdriverio/src/commands/browser/$$.ts +++ b/packages/webdriverio/src/commands/browser/$$.ts @@ -6,7 +6,7 @@ import type { Selector } from '../../types.js' /** * The `$$` command is a short and handy way in order to fetch multiple elements on the page. - * It returns a `ChainablePromiseArray` containing a set of WebdriverIO elements. + * It returns an array containing a set of WebdriverIO elements. * * Using the wdio testrunner this command is a global variable, see [Globals](https://webdriver.io/docs/api/globals) * for more information. Using WebdriverIO within a [standalone](https://webdriver.io/docs/setuptypes#standalone-mode) diff --git a/packages/webdriverio/src/commands/element/$$.ts b/packages/webdriverio/src/commands/element/$$.ts index 2e02193f4d2..4508a4157a6 100644 --- a/packages/webdriverio/src/commands/element/$$.ts +++ b/packages/webdriverio/src/commands/element/$$.ts @@ -1,6 +1,6 @@ /** * The `$$` command is a short and handy way in order to fetch multiple elements on the page. - * It returns a `ChainablePromiseArray` containing a set of WebdriverIO elements. + * It returns an array containing a set of WebdriverIO elements. * * :::info * diff --git a/packages/webdriverio/src/types.ts b/packages/webdriverio/src/types.ts index 857f990f211..16d5f991823 100644 --- a/packages/webdriverio/src/types.ts +++ b/packages/webdriverio/src/types.ts @@ -18,46 +18,11 @@ type $ElementCommands = typeof ElementCommands type ElementQueryCommands = '$' | 'custom$' | 'shadow$' | 'react$' type ElementsQueryCommands = '$$' | 'custom$$' | 'shadow$$' | 'react$$' type ChainablePrototype = { - [K in ElementQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => ChainablePromiseElement>> + [K in ElementQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => Awaited>> } & { - [K in ElementsQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => ChainablePromiseArray>> + [K in ElementsQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => Awaited>> } -type AsyncElementProto = { - [K in keyof Omit<$ElementCommands, keyof ChainablePrototype>]: OmitThisParameter<$ElementCommands[K]> -} & ChainablePrototype - -interface ChainablePromiseBaseElement { - /** - * WebDriver element reference - */ - elementId: Promise - /** - * parent of the element if fetched via `$(parent).$(child)` - */ - parent: Promise - /** - * selector used to fetch this element, can be - * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })` - * - a string if `findElement` was used and a reference was found - * - or a functin if element was found via e.g. `$(() => document.body)` - */ - selector: Promise - /** - * Error message in case element fetch was not successful - */ - error?: Promise - /** - * index of the element if fetched with `$$` - */ - index?: Promise -} -export interface ChainablePromiseElement extends - ChainablePromiseBaseElement, - AsyncElementProto, - Promise, - Omit {} - interface AsyncIterators { /** * Unwrap the nth element of the element list. @@ -79,30 +44,6 @@ interface AsyncIterators { reduce: (callback: (accumulator: U, currentValue: WebdriverIO.Element, currentIndex: number, array: T[]) => U | Promise, initialValue?: U) => Promise; } -export interface ChainablePromiseArray extends Promise, AsyncIterators { - [Symbol.asyncIterator](): AsyncIterableIterator - - /** - * Amount of element fetched. - */ - length: Promise - /** - * selector used to fetch this element, can be - * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })` - * - a string if `findElement` was used and a reference was found - * - or a function if element was found via e.g. `$(() => document.body)` - */ - selector: Promise - /** - * parent of the element if fetched via `$(parent).$(child)` - */ - parent: Promise - /** - * allow to access a specific index of the element set - */ - [n: number]: ChainablePromiseElement -} - export type BrowserCommandsType = Omit<$BrowserCommands, keyof ChainablePrototype> & ChainablePrototype export type ElementCommandsType = Omit<$ElementCommands, keyof ChainablePrototype> & ChainablePrototype diff --git a/packages/webdriverio/src/utils/actions/pointer.ts b/packages/webdriverio/src/utils/actions/pointer.ts index 6c5777e9fd4..f809112a497 100644 --- a/packages/webdriverio/src/utils/actions/pointer.ts +++ b/packages/webdriverio/src/utils/actions/pointer.ts @@ -2,7 +2,6 @@ import type { ElementReference } from '@wdio/protocols' import type { BaseActionParams, KeyActionType } from './base.js' import BaseAction from './base.js' -import type { ChainablePromiseElement } from '../../types.js' export type ButtonNames = 'left' | 'middle' | 'right' export type Button = 0 | 1 | 2 @@ -39,7 +38,7 @@ const MOVE_PARAM_DEFAULTS = { x: 0, y: 0, duration: 100, - origin: ORIGIN_DEFAULT as (Origin | ElementReference | ChainablePromiseElement | WebdriverIO.Element) + origin: ORIGIN_DEFAULT as (Origin | ElementReference | Awaited) } type PointerActionParams = Partial & Partial diff --git a/packages/webdriverio/src/utils/actions/wheel.ts b/packages/webdriverio/src/utils/actions/wheel.ts index 99761146037..88b3a87fcc0 100644 --- a/packages/webdriverio/src/utils/actions/wheel.ts +++ b/packages/webdriverio/src/utils/actions/wheel.ts @@ -1,6 +1,5 @@ import type { BaseActionParams } from './base.js' import BaseAction from './base.js' -import type { ChainablePromiseElement } from '../../types.js' export interface ScrollParams { /** @@ -22,7 +21,7 @@ export interface ScrollParams { /** * element origin */ - origin?: WebdriverIO.Element | ChainablePromiseElement + origin?: Awaited /** * duration ratio be the ratio of time delta and duration */ From 07656b0d7177ccbfe0444a2b07a719d99c168414 Mon Sep 17 00:00:00 2001 From: Erwin Heitzman <15839059+erwinheitzman@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:50:37 +0100 Subject: [PATCH 2/2] (webdriverio): merge types --- packages/webdriverio/src/commands/element/isExisting.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webdriverio/src/commands/element/isExisting.ts b/packages/webdriverio/src/commands/element/isExisting.ts index bc7fc4dbcca..ea4242d871b 100644 --- a/packages/webdriverio/src/commands/element/isExisting.ts +++ b/packages/webdriverio/src/commands/element/isExisting.ts @@ -66,5 +66,5 @@ export async function isExisting (this: WebdriverIO.Element) { : this.isShadowElement ? this.shadow$$.bind(this.parent) : this.parent.$$.bind(this.parent) - return command(this.selector as string).then((res) => res.length > 0) + return (command(this.selector as string) as WebdriverIO.ElementArray & Promise).then((res) => res.length > 0) }