Class Device

Constructors

Properties

beta: {
    query: (<T>(prompt: string, options?: {
        model?: LLMModel;
        responseFormat?: T;
        screenshot?: string;
        telemetry?: {
            tags?: string[];
        };
    }) => Promise<ExtractType<T>>);
    tap: ((prompt: string, options?: {
        telemetry?: {
            tags?: string[];
        };
        useCache?: boolean;
    }) => Promise<{
        x: number;
        y: number;
    }>);
} = ...

Methods

  • Parameters

    • OptionalbundleId: string

    Returns Promise<void>

  • Closes the automation session. This is called automatically after each test.

    Usage:

    await device.close();
    

    Returns Promise<void>

  • Locate an element on the screen with accessibility identifier. This method defaults to a substring match, and this can be overridden by setting the exact option to true.

    Usage:

    const element = await device.getById("signup_button");
    

    Parameters

    • text: string

      string to search for

    • options: {
          exact?: boolean;
      } = {}
      • Optionalexact?: boolean

    Returns AppwrightLocator

  • Locate an element on the screen with text content. This method defaults to a substring match, and this be overridden by setting the exact option to true.

    Usage:

    // with string
    const submitButton = device.getByText("Submit");

    // with RegExp
    const counter = device.getByText(/^Counter: \d+/);

    Parameters

    • text: string | RegExp

      string or regular expression to search for

    • options: {
          exact?: boolean;
      } = {}
      • Optionalexact?: boolean

    Returns AppwrightLocator

  • Locate an element on the screen with xpath.

    Usage:

    const element = await device.getByXpath(`//android.widget.Button[@text="Confirm"]`);
    

    Parameters

    • xpath: string

      xpath to locate the element

    Returns AppwrightLocator

  • Retrieves text content from the clipboard of the mobile device. This is useful after a "copy to clipboard" action has been performed. This returns base64 encoded string.

    Usage:

    const clipboardText = await device.getClipboardText();
    

    Returns Promise<string>

    Returns the text content of the clipboard in base64 encoded string.

  • Helper method to detect the mobile OS running on the device.

    Usage:

    const platform = device.getPlatform();
    

    Returns Platform

    "android" or "ios"

  • Parameters

    • __namedParameters: {
          findStrategy: string;
          selector: string;
          textToMatch?: string | RegExp;
      }
      • findStrategy: string
      • selector: string
      • OptionaltextToMatch?: string | RegExp

    Returns AppwrightLocator

  • Get a screenshot of the current screen as a base64 encoded string.

    Returns Promise<string>

  • [iOS Only] Scroll the screen from 0.2 to 0.8 of the screen height. This can be used for controlled scroll, for auto scroll checkout scroll method from locator.

    Usage:

    await device.scroll();
    

    Returns Promise<void>

  • Send keys to already focused input field. To fill input fields using the selectors use sendKeyStrokes method from locator

    Parameters

    • value: string

    Returns Promise<void>

  • Sets a mock camera view using the specified image. This injects a mock image into the camera view. Currently, this functionality is supported only for BrowserStack.

    Usage:

    await device.setMockCameraView(`screenshot.png`);
    

    Parameters

    • imagePath: string

      path to the image file that will be used as the mock camera view.

    Returns Promise<void>

  • Tap on the screen at the given coordinates, specified as x and y. The top left corner of the screen is { x: 0, y: 0 }.

    Usage:

    await device.tap({ x: 100, y: 100 });
    

    Parameters

    • coordinates: {
          x: number;
          y: number;
      }

      to tap on

      • x: number
      • y: number

    Returns Promise<void>

  • Parameters

    • OptionalbundleId: string

    Returns Promise<void>

  • Parameters

    • timeout: number

    Returns Promise<void>