import type * as Options from './options.js'; type StringValue = string | RegExp | ExpectWebdriverIO.PartialMatcher; /** One CSS value of `toHaveStyle`: a string value, as in `toHaveText` */ type StyleValue = MaybeOneOf; /** * A number of the number matchers: a number, a range (`NumberMatcher`), one of these numbers (`expect.oneOf(100, 200)`), or * an asymmetric matcher, e.g. `expect.closeTo(150, 0)`. `PartialMatcher` omits `sample`, so the types accept any * asymmetric matcher, as for the string matchers. */ type NumberValue = number | ExpectWebdriverIO.NumberMatcher | ExpectWebdriverIO.OneOfNumbersPartialMatcher | ExpectWebdriverIO.PartialMatcher; /** The size of `toHaveSize`: a number or a `NumberMatcher` for each field, or an asymmetric matcher, e.g. `expect.objectContaining()` */ type SizeValue = { height: NumberValue; width: NumberValue; } | ExpectWebdriverIO.PartialMatcher; /** A property value that is not a string: compared with `equals()`, deeply. An array means one value for each element of `$$()` */ type PropertyObject = { [key: string]: unknown; }; /** * The expected value of each value type. The public types of the matchers and the compare functions use the same types, * so that a matcher accepts what its compare function compares. */ export type ExpectedValues = { string: StringValue; number: NumberValue; style: StyleValue; size: SizeValue; }; export type ExpectedOf = ExpectedValues[V]; /** * An element matcher with one expected value: one signature for each of `$()`, `$$()`, multi-remote `$()` and multi-remote `$$()`. */ type ElementValueMatcher = FnWhenElementOrArrayLike, options?: Options) => Promise, /** Elements $$() API */ (expected: MaybeArrayOrOneOf, options?: Options) => Promise, /** Element MultiRemoteBrowser.$() API */ (expected: MultiRemoteValuesOrOneOf, options?: Options) => Promise, /** Elements MultiRemoteBrowser.$$() API */ (expected: MaybeArrayOrMultiRemoteWithArrayValuesOrOneOf, options?: Options) => Promise>; export type ServiceInstance = import('@wdio/types').Services.ServiceInstance; export type Test = import('@wdio/types').Frameworks.Test; export type TestResult = import('@wdio/types').Frameworks.TestResult; export type PickleStep = import('@wdio/types').Frameworks.PickleStep; export type Scenario = import('@wdio/types').Frameworks.Scenario; export type SnapshotResult = import('@vitest/snapshot').SnapshotResult; export type SnapshotUpdateState = import('@vitest/snapshot').SnapshotUpdateState; export type ExpectLibAsymmetricMatchers = import('expect').AsymmetricMatchers; export type ExpectLibAsymmetricMatcher = import('expect').AsymmetricMatcher; export type ExpectLibMatchers, T> = import('expect').Matchers; export type ExpectLibExpect = import('expect').Expect; export type ExpectLibInverse = import('expect').Inverse; export type ExpectLibExpectationResult = import('expect').ExpectationResult; export type ExpectLibMatcherContext = import('expect').MatcherContext; export type MatchersObject = Parameters[0]; export type ExpectLibAnything = ReturnType | ReturnType; export type RawMatcherFn = { (this: Context, actual: any, ...expected: Array): ExpectLibExpectationResult; }; export interface WdioSome { readonly elements: T; } /** * Indicates that a value can be either one T or an array of T. */ export type MaybeArray = T | T[]; export type MaybeSome = T | WdioSome; /** * Indicates that a value can be either one T, an array of T with oneOf of T, or a oneOf matcher of T. * For oneOf anything is excluded since it does not make any sense to have a oneOf with Anything matcher. * Numbers are excluded: a string value; `expect.oneOf()` with numbers is `OneOfNumbersPartialMatcher`, for the number matchers. */ export type MaybeArrayOrOneOf = T | (T | ExpectWebdriverIO.OneOfPartialMatcher>)[] | ExpectWebdriverIO.OneOfPartialMatcher>; /** * Indicates that a value can be either one T, or oneOf matchers of T. * For oneOf anything is excluded since it does not make any sense to have a oneOf with Anything matcher. */ export type MaybeOneOf = T | ExpectWebdriverIO.OneOfPartialMatcher>; export type MultiRemoteValues = Record; export type MultiRemoteValuesOrOneOf = T | ExpectWebdriverIO.OneOfPartialMatcher | MultiRemoteValues> | ExpectWebdriverIO.MultiRemotePartialMatcher>; export type MaybeArrayOrMultiRemoteValues = MaybeArray | MultiRemoteValues; export type MaybeArrayOrMultiRemoteValuesOrOneOf = MaybeArray> | MultiRemoteValues> | ExpectWebdriverIO.OneOfPartialMatcher; export type MaybeArrayOrMultiRemoteWithArrayValuesOrOneOf = MaybeArray> | MultiRemoteValues>> | ExpectWebdriverIO.OneOfPartialMatcher | ExpectWebdriverIO.MultiRemotePartialMatcher>>; export type ArrayOrMultiRemoteValues = T[] | MultiRemoteValues; /** Multi-remote $(): one expected value for every instance, or one per instance with `expect.multiRemote()` (e.g. numbers, styles) */ export type SingleOrMultiRemoteMatcher = T | ExpectWebdriverIO.MultiRemotePartialMatcher; /** Multi-remote $$(): one expected value (or one per element) for every instance, or the same per instance with `expect.multiRemote()` (e.g. numbers, styles) */ export type MaybeArrayOrMultiRemoteMatcher = MaybeArray | ExpectWebdriverIO.MultiRemotePartialMatcher>; /** * Real Promise and wdio chainable promise types. */ export type WdioPromiseLike = PromiseLike | ChainablePromiseElement | ChainablePromiseArray; export type WdioElementOrPromiseLike = WdioPromiseLike | WebdriverIO.Element; export type ElementPromise = Promise; export type ElementArrayPromise = Promise; export type ArrayOfElementsPromise = Promise; /** * Note we are defining types outside of the namespace as done in jest library until we can make every typing work correctly. * Once we have all types working, we could check to bring those back into the `ExpectWebdriverIO` namespace. */ /** * Type helpers to be able to targets specific types mostly used in conjunctions with the Type of the `actual` parameter of the `expect` */ export type ElementOrMaybeSomeArrayLike = ElementLike | MaybeSomeElementArrayLike; export type ElementLike = WebdriverIO.Element | ChainablePromiseElement; export type ElementArrayLike = WebdriverIO.ElementArray | ChainablePromiseArray | WebdriverIO.Element[] | ArrayOfElementsPromise | ElementArrayPromise | WebdriverIO.MultiRemoteElementArray; export type MaybeSomeElementArrayLike = MaybeSome; export type MultiRemoteElementOrElements = WebdriverIO.MultiRemoteElement | WebdriverIO.MultiRemoteElementArray; export type MockPromise = Promise; /** Multi-remote `mock()`, one mock per instance: every instance's mock must satisfy the network matcher */ export type MultiRemoteMocks = WebdriverIO.MultiRemoteMock | Promise; /** * Type helpers allowing to use the function when the expect(actual: T) is of the expected type T. */ export type FnWhenBrowser = ActualT extends WebdriverIO.Browser | WebdriverIO.BrowsingContext ? Fn : never; export type FnWhenBrowserOrMultiRemote = ActualT extends WebdriverIO.Browser | WebdriverIO.BrowsingContext ? FnBrowser : ActualT extends WebdriverIO.MultiRemoteBrowser ? FnMultiRemote : never; /** * Enables distinct function signatures for single elements versus arrays of elements. * * Note on Union Types: Passing a union type (e.g., `Element | Element[]`) may cause * overload resolution failures, preventing the IDE and compiler from inferring the correct signature. * * Fix: If type inference issues arise, split the implementation into separate interfaces */ export type FnWhenElementOrArrayLike = ActualT extends WebdriverIO.MultiRemoteElementArray ? FnMultiRemoteElements : ActualT extends WebdriverIO.MultiRemoteElement ? FnMultiRemoteElement : ActualT extends MaybeSomeElementArrayLike ? FnArray : ActualT extends ElementLike ? FnElement : never; export type FnWhenElementArrayLike = ActualT extends WebdriverIO.MultiRemoteElementArray ? FnMultiRemoteElements : ActualT extends MaybeSomeElementArrayLike ? Fn : never; /** * Same as the other but because of Jasmine and it's expectAsync typing which does not force T to be a promise, then we need to account for `WebdriverIO.Mock */ export type FnWhenMock = ActualT extends MultiRemoteMocks ? FnMultiRemote : ActualT extends MockPromise | WebdriverIO.Mock ? Fn : never; export interface WdioCustomAsymmetricMatchers { oneOf(...values: Array): ExpectWebdriverIO.OneOfPartialMatcher; /** * One of these numbers, in the number matchers, e.g. a width of 100 or 200 and nothing between, which a range cannot say. * * @example * await expect(element).toHaveWidth(expect.oneOf(100, 200)) */ oneOf(...values: number[]): ExpectWebdriverIO.OneOfNumbersPartialMatcher; /** * One expected value per multi-remote instance, keyed by instance name. Every instance must be listed. * Required for per-instance values of number matchers (`toHaveWidth`, `toHaveHeight`, `toHaveChildren`, `toBeElementsArrayOfSize`) * and of matchers whose expected value is itself an object (`toHaveStyle`, `toHaveSize`, `toHaveElementProperty`), * and the explicit form of the plain object shorthand for the other matchers. * * @example * await expect(multiRemoteBrowser).toHaveTitle(expect.multiRemote({ chrome: 'Title', firefox: 'Titre' })) * await expect(multiRemoteBrowser.$('h1')).toHaveStyle(expect.multiRemote({ chrome: { color: 'red' }, firefox: { color: 'blue' } })) */ multiRemote(values: MultiRemoteValues): ExpectWebdriverIO.MultiRemotePartialMatcher; } /** * Matchers dedicated to Wdio Browser or multi-remote Browser. * When asserting on a browser's properties requiring to be awaited, the return type is a Promise. * When actual is not a browser, the return type is never, so the function cannot be used. */ export interface WdioBrowserMatchers<_R, ActualT> { /** * Browser`s url */ toHaveUrl: FnWhenBrowserOrMultiRemote `getUrl` */ (url: StringValue, options?: ExpectWebdriverIO.StringOptions) => Promise, /** * `WebdriverIO.MultiRemoteBrowser` -> `getUrl` */ (url: MultiRemoteValuesOrOneOf, options?: ExpectWebdriverIO.StringOptions) => Promise>; /** * Browser`s title */ toHaveTitle: FnWhenBrowserOrMultiRemote `getTitle` */ (title: StringValue, options?: ExpectWebdriverIO.StringOptions) => Promise, /** * `WebdriverIO.MultiRemoteBrowser` -> `getTitle` */ (title: MultiRemoteValuesOrOneOf, options?: ExpectWebdriverIO.StringOptions) => Promise>; /** * `WebdriverIO.Browser` -> `execute` */ toHaveClipboardText: FnWhenBrowserOrMultiRemote `getClipboard` */ (clipboardText: MaybeOneOf, options?: ExpectWebdriverIO.StringOptions) => Promise, /** * `WebdriverIO.MultiRemoteBrowser` -> `getClipboard` */ (clipboardText: MultiRemoteValuesOrOneOf, options?: ExpectWebdriverIO.StringOptions) => Promise>; /** * `WebdriverIO.Browser` -> `execute` */ toHaveLocalStorageItem: FnWhenBrowserOrMultiRemote `getLocalStorageItem` */ { /** * Only check that the item exists. * Use `toHaveLocalStorageItem(key, expect.anything(), options)` to check it with options. */ (key: string): Promise; (key: string, expectedValue: MaybeOneOf, options?: ExpectWebdriverIO.StringOptions): Promise; }, /** * `WebdriverIO.MultiRemoteBrowser` -> `getLocalStorageItem` */ { /** * Only check that the item exists. * Use `toHaveLocalStorageItem(key, expect.anything(), options)` to check it with options. */ (key: string): Promise; (key: string, expectedValue: MultiRemoteValuesOrOneOf, options?: ExpectWebdriverIO.StringOptions): Promise; }>; /** * `WebdriverIO.Browser` -> `execute`: the item of `sessionStorage`, compared as a string value */ toHaveSessionStorageItem: FnWhenBrowserOrMultiRemote `execute` */ { /** * Only check that the item exists. * Use `toHaveSessionStorageItem(key, expect.anything(), options)` to check it with options. */ (key: string): Promise; (key: string, expectedValue: MaybeOneOf, options?: ExpectWebdriverIO.StringOptions): Promise; }, /** * `WebdriverIO.MultiRemoteBrowser` -> `execute` on each instance */ { /** * Only check that the item exists. * Use `toHaveSessionStorageItem(key, expect.anything(), options)` to check it with options. */ (key: string): Promise; (key: string, expectedValue: MultiRemoteValuesOrOneOf, options?: ExpectWebdriverIO.StringOptions): Promise; }>; /** * `WebdriverIO.Browser` -> `getCookies({ name })`: the value of the cookie, compared as a string value */ toHaveCookie: FnWhenBrowserOrMultiRemote `getCookies({ name })` */ { /** * Only check that the cookie exists. * Use `toHaveCookie(name, expect.anything(), options)` to check it with options. */ (name: string): Promise; (name: string, expectedValue: MaybeOneOf, options?: ExpectWebdriverIO.StringOptions): Promise; }, /** * `WebdriverIO.MultiRemoteBrowser` -> `getCookies({ name })` of each instance */ { /** * Only check that the cookie exists. * Use `toHaveCookie(name, expect.anything(), options)` to check it with options. */ (name: string): Promise; (name: string, expectedValue: MultiRemoteValuesOrOneOf, options?: ExpectWebdriverIO.StringOptions): Promise; }>; /** * `WebdriverIO.Browser` -> `getWindowHandles()`: the number of the windows and tabs of the session, e.g. `2` after a * link opens a new tab. On a browsing context, the count of its session. */ toHaveWindowCount: FnWhenBrowserOrMultiRemote Promise, /** * `WebdriverIO.MultiRemoteBrowser` -> `getWindowHandles()` of each instance */ (count: SingleOrMultiRemoteMatcher, options?: ExpectWebdriverIO.CommandOptions) => Promise>; } /** * Matchers dedicated to Network Mocking. * When asserting we wait for the result with `await waitUntil()`, therefore the return type needs to be a Promise. * When actual is not a WebdriverIO.Mock, the return type is never, so the function cannot be used. */ export interface WdioNetworkMatchers<_R, ActualT> { /** * Check that `WebdriverIO.Mock` was called. * With multi-remote mocks (`multiRemoteBrowser.mock()`), every instance's mock must be called. */ toBeRequested: FnWhenMock Promise>; /** * Check that `WebdriverIO.Mock` was called N times. * With multi-remote mocks (`multiRemoteBrowser.mock()`), every instance's mock must be called N times, * or its own number of times with `expect.multiRemote({ chrome: 1, firefox: 2 })`. */ toBeRequestedTimes: FnWhenMock Promise, (times: SingleOrMultiRemoteMatcher, options?: ExpectWebdriverIO.CommandOptions) => Promise>; /** * Check that `WebdriverIO.Mock` was called with the specific parameters. * With multi-remote mocks (`multiRemoteBrowser.mock()`), every instance's mock must have such a call, * or a call with its own parameters with `expect.multiRemote({ chrome: { ... }, firefox: { ... } })`. */ toBeRequestedWith: FnWhenMock Promise, (requestedWith: SingleOrMultiRemoteMatcher, options?: ExpectWebdriverIO.CommandOptions) => Promise>; } /** * Matchers dedicated to WebdriverIO Element or ElementArray (or chainable) on Browser * For Multi-Remote Browser, MultiRemoteElement or MultiRemoteElementArray * When asserting on an element or element array's properties requiring to be awaited, the return type is a Promise. * When actual is neither of WebdriverIO.Element, WebdriverIO.ElementArray, ChainableElement, ChainableElementArray, the return type is never, so the function cannot be used. */ export interface WdioElementOrArrayMatchers<_R, ActualT = unknown> { /** * `WebdriverIO.Element` -> `isDisplayed` */ toBeDisplayed: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isExisting` */ toExist: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isExisting` */ toBePresent: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isExisting` */ toBeExisting: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isClickable` */ toBeClickable: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `!isEnabled` */ toBeDisabled: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isDisplayedInViewport` */ toBeDisplayedInViewport: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isEnabled` */ toBeEnabled: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isFocused` */ toBeFocused: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `isStable` * The element is not moving, e.g. at the end of an animation */ toBeStable: FnWhenElementOrArrayLike Promise>; /** * `WebdriverIO.Element` -> `getProperty('required')` * The form field (``, `