Skip to main content

AndroidDevice

AndroidDevice represents a connected device, either real hardware or emulated. Devices can be obtained using android.devices([options]).

androidDevice.on('webview')

Added in: v1.9

Emitted when a new WebView instance is detected.

androidDevice.close()

Added in: v1.9

Disconnects from the device.

androidDevice.drag(selector, dest[, options])

Added in: v1.9

Drags the widget defined by selector towards dest point.

androidDevice.fill(selector, text[, options])

Added in: v1.9

Fills the specific selector input box with text.

androidDevice.fling(selector, direction[, options])

Added in: v1.9
  • selector <[AndroidSelector]> Selector to fling.#
  • direction <"down"|"up"|"left"|"right"> Fling direction.#
  • options? <Object>
  • returns: <Promise<void>>#

Flings the widget defined by selector in the specified direction.

androidDevice.info(selector)

Added in: v1.9
  • selector <[AndroidSelector]> Selector to return information about.#
  • returns: <Promise<[AndroidElementInfo]>>#

Returns information about a widget defined by selector.

androidDevice.installApk(file[, options])

Added in: v1.9
  • file <string|Buffer> Either a path to the apk file, or apk file content.#
  • options? <Object>
    • args? <Array<string>> Optional arguments to pass to the shell:cmd package install call. Defaults to -r -t -S.#
  • returns: <Promise<void>>#

Installs an apk on the device.

androidDevice.launchBrowser([options])

Added in: v1.9
  • options? <Object>
    • acceptDownloads? <boolean> Whether to automatically download all the attachments. Defaults to true where all the downloads are accepted.#
    • baseURL? <string> When using page.goto(url[, options]), page.route(url, handler[, options]), page.waitForURL(url[, options]), page.waitForRequest(urlOrPredicate[, options]), or page.waitForResponse(urlOrPredicate[, options]) it takes the base URL in consideration by using the URL() constructor for building the corresponding URL. Examples:#
      • baseURL: http://localhost:3000 and navigating to /bar.html results in http://localhost:3000/bar.html
      • baseURL: http://localhost:3000/foo/ and navigating to ./bar.html results in http://localhost:3000/foo/bar.html
      • baseURL: http://localhost:3000/foo (without trailing slash) and navigating to ./bar.html results in http://localhost:3000/bar.html
    • bypassCSP? <boolean> Toggles bypassing page's Content-Security-Policy.#
    • colorScheme? <"light"|"dark"|"no-preference"> Emulates 'prefers-colors-scheme' media feature, supported values are 'light', 'dark', 'no-preference'. See page.emulateMedia([options]) for more details. Defaults to 'light'.#
    • command? <string> Optional package name to launch instead of default Chrome for Android.#
    • deviceScaleFactor? <number> Specify device scale factor (can be thought of as dpr). Defaults to 1.#
    • extraHTTPHeaders? <Object<string, string>> An object containing additional HTTP headers to be sent with every request.#
    • forcedColors? <"active"|"none"> Emulates 'forced-colors' media feature, supported values are 'active', 'none'. See page.emulateMedia([options]) for more details. Defaults to 'none'.#
    • geolocation? <Object>#
      • latitude <number> Latitude between -90 and 90.
      • longitude <number> Longitude between -180 and 180.
      • accuracy? <number> Non-negative accuracy value. Defaults to 0.
    • hasTouch? <boolean> Specifies if viewport supports touch events. Defaults to false.#
    • httpCredentials? <Object> Credentials for HTTP authentication.#
    • ignoreHTTPSErrors? <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • isMobile? <boolean> Whether the meta viewport tag is taken into account and touch events are enabled. Defaults to false. Not supported in Firefox.#
    • javaScriptEnabled? <boolean> Whether or not to enable JavaScript in the context. Defaults to true.#
    • locale? <string> Specify user locale, for example en-GB, de-DE, etc. Locale will affect navigator.language value, Accept-Language request header value as well as number and date formatting rules.#
    • logger? <Logger> Logger sink for Playwright logging.#
    • offline? <boolean> Whether to emulate network being offline. Defaults to false.#
    • permissions? <Array<string>> A list of permissions to grant to all pages in this context. See browserContext.grantPermissions(permissions[, options]) for more details.#
    • recordHar? <Object> Enables HAR recording for all pages into recordHar.path file. If not specified, the HAR is not recorded. Make sure to await browserContext.close() for the HAR to be saved.#
      • omitContent? <boolean> Optional setting to control whether to omit request content from the HAR. Defaults to false. Deprecated, use content policy instead.
      • content? <"omit"|"embed"|"attach"> Optional setting to control resource content management. If omit is specified, content is not persisted. If attach is specified, resources are persisted as separate files or entries in the ZIP archive. If embed is specified, content is stored inline the HAR file as per HAR specification. Defaults to attach for .zip output files and to embed for all other file extensions.
      • path <string> Path on the filesystem to write the HAR file to. If the file name ends with .zip, content: 'attach' is used by default.
      • mode? <"full"|"minimal"> When set to minimal, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to full.
      • urlFilter? <string|RegExp> A glob or regex pattern to filter requests that are stored in the HAR. When a baseURL via the context options was provided and the passed URL is a path, it gets merged via the new URL() constructor.
    • recordVideo? <Object> Enables video recording for all pages into recordVideo.dir directory. If not specified videos are not recorded. Make sure to await browserContext.close() for videos to be saved.#
      • dir <string> Path to the directory to put videos into.
      • size? <Object> Optional dimensions of the recorded videos. If not specified the size will be equal to viewport scaled down to fit into 800x800. If viewport is not configured explicitly the video size defaults to 800x450. Actual picture of each page will be scaled down if necessary to fit the specified size.
        • width <number> Video frame width.
        • height <number> Video frame height.
    • reducedMotion? <"reduce"|"no-preference"> Emulates 'prefers-reduced-motion' media feature, supported values are 'reduce', 'no-preference'. See page.emulateMedia([options]) for more details. Defaults to 'no-preference'.#
    • screen? <Object> Emulates consistent window screen size available inside web page via window.screen. Is only used when the viewport is set.#
      • width <number> page width in pixels.
      • height <number> page height in pixels.
    • serviceWorkers? <"allow"|"block"> Whether to allow sites to register Service workers. Defaults to 'allow'.#
      • 'allow': Service Workers can be registered.
      • 'block': Playwright will block all registration of Service Workers.
    • strictSelectors? <boolean> If specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors that imply single target DOM element will throw when more than one element matches the selector. See Locator to learn more about the strict mode.#
    • timezoneId? <string> Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs.#
    • userAgent? <string> Specific user agent to use in this context.#
    • videoSize? <Object> DEPRECATED Use recordVideo instead.#
      • width <number> Video frame width.
      • height <number> Video frame height.
    • videosPath? <string> DEPRECATED Use recordVideo instead.#
    • viewport? <null|Object> Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. null disables the default viewport.#
      • width <number> page width in pixels.
      • height <number> page height in pixels.
  • returns: <Promise<BrowserContext>>#

Launches Chrome browser on the device, and returns its persistent context.

androidDevice.longTap(selector[, options])

Added in: v1.9

Performs a long tap on the widget defined by selector.

androidDevice.model()

Added in: v1.9

Device model.

androidDevice.open(command)

Added in: v1.9

Launches a process in the shell on the device and returns a socket to communicate with the launched process.

androidDevice.pinchClose(selector, percent[, options])

Added in: v1.9
  • selector <[AndroidSelector]> Selector to pinch close.#
  • percent <number> The size of the pinch as a percentage of the widget's size.#
  • options? <Object>
  • returns: <Promise<void>>#

Pinches the widget defined by selector in the closing direction.

androidDevice.pinchOpen(selector, percent[, options])

Added in: v1.9
  • selector <[AndroidSelector]> Selector to pinch open.#
  • percent <number> The size of the pinch as a percentage of the widget's size.#
  • options? <Object>
  • returns: <Promise<void>>#

Pinches the widget defined by selector in the open direction.

androidDevice.press(selector, key[, options])

Added in: v1.9

Presses the specific key in the widget defined by selector.

androidDevice.push(file, path[, options])

Added in: v1.9

Copies a file to the device.

androidDevice.screenshot([options])

Added in: v1.9
  • options? <Object>
    • path? <string> The file path to save the image to. If path is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk.#
  • returns: <Promise<Buffer>>#

Returns the buffer with the captured screenshot of the device.

androidDevice.scroll(selector, direction, percent[, options])

Added in: v1.9
  • selector <[AndroidSelector]> Selector to scroll.#
  • direction <"down"|"up"|"left"|"right"> Scroll direction.#
  • percent <number> Distance to scroll as a percentage of the widget's size.#
  • options? <Object>
  • returns: <Promise<void>>#

Scrolls the widget defined by selector in the specified direction.

androidDevice.serial()

Added in: v1.9

Device serial number.

androidDevice.setDefaultTimeout(timeout)

Added in: v1.9
  • timeout <number> Maximum time in milliseconds#
  • returns: <void>#

This setting will change the default maximum time for all the methods accepting timeout option.

androidDevice.shell(command)

Added in: v1.9

Executes a shell command on the device and returns its output.

androidDevice.swipe(selector, direction, percent[, options])

Added in: v1.9
  • selector <[AndroidSelector]> Selector to swipe.#
  • direction <"down"|"up"|"left"|"right"> Swipe direction.#
  • percent <number> Distance to swipe as a percentage of the widget's size.#
  • options? <Object>
  • returns: <Promise<void>>#

Swipes the widget defined by selector in the specified direction.

androidDevice.tap(selector[, options])

Added in: v1.9

Taps on the widget defined by selector.

androidDevice.wait(selector[, options])

Added in: v1.9
  • selector <[AndroidSelector]> Selector to wait for.#
  • options? <Object>
    • state? <"gone"> Optional state. Can be either:#
      • default - wait for element to be present.
      • 'gone' - wait for element to not be present.
    • timeout? <number> Maximum time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
  • returns: <Promise<void>>#

Waits for the specific selector to either appear or disappear, depending on the state.

androidDevice.waitForEvent(event[, optionsOrPredicate])

Added in: v1.9
  • event <string> Event name, same one typically passed into *.on(event).#
  • optionsOrPredicate? <function|Object> Either a predicate that receives an event or an options object. Optional.#
    • predicate <function> receives the event data and resolves to truthy value when the waiting should resolve.
    • timeout? <number> maximum time to wait for in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout).
  • returns: <Promise<Object>>#

Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value.

androidDevice.webView(selector[, options])

Added in: v1.9

This method waits until AndroidWebView matching the selector is opened and returns it. If there is already an open AndroidWebView matching the selector, returns immediately.

androidDevice.webViews()

Added in: v1.9

Currently open WebViews.

androidDevice.input

Added in: v1.9