VariabledomConst

dom: {
    byId: ((elementId: string) => null | HTMLElement);
    click: ((selector: string | Element) => Promise<void>);
    event: ((event: string | Event | CustomEvent<any>, element?: null | Element | Window) => void);
    getComputedStyle: ((element: HTMLElement | Element) => CSSStyleDeclaration);
    isElementVisible: ((element: Element, previousElement?: Element) => boolean);
    qs: {
        <K>(selectors: K): null | HTMLElementTagNameMap[K];
        <K>(selectors: K): null | SVGElementTagNameMap[K];
        <K>(selectors: K): null | MathMLElementTagNameMap[K];
        <K>(selectors: K): null | HTMLElementDeprecatedTagNameMap[K];
        <E>(selectors: string): null | E;
    };
    qsa: {
        <K>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
        <K>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
        <K>(selectors: K): NodeListOf<MathMLElementTagNameMap[K]>;
        <K>(selectors: K): NodeListOf<HTMLElementDeprecatedTagNameMap[K]>;
        <E>(selectors: string): NodeListOf<E>;
    };
    sleep: ((ms: number) => Promise<void>);
    waitFor: ((selector?: null | string, args?: null | {
        timeout?: number;
        visible?: boolean;
    }, lambda?: (() => null | Element)) => Promise<Element | null>);
    waitForText: ((args: string | Partial<{
        multipleTags: boolean;
        regex: RegExp;
        text: string;
        timeout: number;
    }>, parentElement?: Element) => Promise<Element | null>);
} = ...

Type declaration

  • byId: ((elementId: string) => null | HTMLElement)
      • (elementId): null | HTMLElement
      • Returns a reference to the first object with the specified value of the ID attribute.

        Parameters

        • elementId: string

          String that specifies the ID value.

        Returns null | HTMLElement

  • click: ((selector: string | Element) => Promise<void>)
      • (selector): Promise<void>
      • Dispatch the `click`` method on an element specified by selector.

        Parameters

        • selector: string | Element

          A CSS selector string, or an instance of an HTMLElement.

        Returns Promise<void>

        await click('.class button', 'Click a button')
        
  • event: ((event: string | Event | CustomEvent<any>, element?: null | Element | Window) => void)
      • (event, element?): void
      • Parameters

        • event: string | Event | CustomEvent<any>

          The event to dispatch

        • Optionalelement: null | Element | Window

          The element to dispatch from, or will use window if none given.

        Returns void

        Throws an error if the event is not a string that can be converted to a CustomEvent or not an instance of Event.

  • getComputedStyle: ((element: HTMLElement | Element) => CSSStyleDeclaration)
  • isElementVisible: ((element: Element, previousElement?: Element) => boolean)
  • qs: {
        <K>(selectors: K): null | HTMLElementTagNameMap[K];
        <K>(selectors: K): null | SVGElementTagNameMap[K];
        <K>(selectors: K): null | MathMLElementTagNameMap[K];
        <K>(selectors: K): null | HTMLElementDeprecatedTagNameMap[K];
        <E>(selectors: string): null | E;
    }
      • <K>(selectors): null | HTMLElementTagNameMap[K]
      • Returns the first element that is a descendant of node that matches selectors.

        MDN Reference

        Type Parameters

        • K extends keyof HTMLElementTagNameMap

        Parameters

        • selectors: K

        Returns null | HTMLElementTagNameMap[K]

      • <K>(selectors): null | SVGElementTagNameMap[K]
      • Type Parameters

        • K extends keyof SVGElementTagNameMap

        Parameters

        • selectors: K

        Returns null | SVGElementTagNameMap[K]

      • <K>(selectors): null | MathMLElementTagNameMap[K]
      • Type Parameters

        • K extends keyof MathMLElementTagNameMap

        Parameters

        • selectors: K

        Returns null | MathMLElementTagNameMap[K]

      • <K>(selectors): null | HTMLElementDeprecatedTagNameMap[K]
      • Type Parameters

        • K extends keyof HTMLElementDeprecatedTagNameMap

        Parameters

        • selectors: K

        Returns null | HTMLElementDeprecatedTagNameMap[K]

      • <E>(selectors): null | E
      • Type Parameters

        • E extends Element = Element

        Parameters

        • selectors: string

        Returns null | E

  • qsa: {
        <K>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
        <K>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
        <K>(selectors: K): NodeListOf<MathMLElementTagNameMap[K]>;
        <K>(selectors: K): NodeListOf<HTMLElementDeprecatedTagNameMap[K]>;
        <E>(selectors: string): NodeListOf<E>;
    }
      • <K>(selectors): NodeListOf<HTMLElementTagNameMap[K]>
      • Returns all element descendants of node that match selectors.

        MDN Reference

        Type Parameters

        • K extends keyof HTMLElementTagNameMap

        Parameters

        • selectors: K

        Returns NodeListOf<HTMLElementTagNameMap[K]>

      • <K>(selectors): NodeListOf<SVGElementTagNameMap[K]>
      • Type Parameters

        • K extends keyof SVGElementTagNameMap

        Parameters

        • selectors: K

        Returns NodeListOf<SVGElementTagNameMap[K]>

      • <K>(selectors): NodeListOf<MathMLElementTagNameMap[K]>
      • Type Parameters

        • K extends keyof MathMLElementTagNameMap

        Parameters

        • selectors: K

        Returns NodeListOf<MathMLElementTagNameMap[K]>

      • <K>(selectors): NodeListOf<HTMLElementDeprecatedTagNameMap[K]>
      • Type Parameters

        • K extends keyof HTMLElementDeprecatedTagNameMap

        Parameters

        • selectors: K

        Returns NodeListOf<HTMLElementDeprecatedTagNameMap[K]>

      • <E>(selectors): NodeListOf<E>
      • Type Parameters

        • E extends Element = Element

        Parameters

        • selectors: string

        Returns NodeListOf<E>

  • sleep: ((ms: number) => Promise<void>)
      • (ms): Promise<void>
      • Sleeps for ms milliseconds.

        Parameters

        • ms: number

        Returns Promise<void>

  • waitFor: ((selector?: null | string, args?: null | {
        timeout?: number;
        visible?: boolean;
    }, lambda?: (() => null | Element)) => Promise<Element | null>)
      • (selector?, args?, lambda?): Promise<Element | null>
      • Wait for an element to appear in the DOM, then resolve the promise. Either a query selector or lambda function must be provided.

        Parameters

        • Optionalselector: null | string

          The CSS selector to use

        • Optionalargs: null | {
              timeout?: number;
              visible?: boolean;
          }

          Configuration args

        • Optionallambda: (() => null | Element)

          An optional function that returns the element. Used if the selector is not provided.

            • (): null | Element
            • Returns null | Element

        Returns Promise<Element | null>

        A promise that resolves to the found element.

        • Throws if neither lambda nor selector is provided.
        • Throws if the element is not found within the timeout.
        waitFor({ selector: '#my-element', visible: true, timeout: 5000 })
        .then(el => console.log('Element found:', el))
        .catch(err => console.log('Element not found:', err));
  • waitForText: ((args: string | Partial<{
        multipleTags: boolean;
        regex: RegExp;
        text: string;
        timeout: number;
    }>, parentElement?: Element) => Promise<Element | null>)
      • (args, parentElement?): Promise<Element | null>
      • Look for the given text within the given parent element. Return the element containing the text.

        Parameters

        • args: string | Partial<{
              multipleTags: boolean;
              regex: RegExp;
              text: string;
              timeout: number;
          }>
        • parentElement: Element = document.body

        Returns Promise<Element | null>