2021-02-11 10:31:57 -08:00
# class: AndroidDevice
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
* langs: js
[AndroidDevice] represents a connected device, either real hardware or emulated. Devices can be obtained using [`method: Android.devices` ].
2022-10-25 18:18:14 -07:00
## event: AndroidDevice.close
* since: v1.28
- argument: < [AndroidDevice]>
Emitted when the device connection gets closed.
2021-02-11 10:31:57 -08:00
## event: AndroidDevice.webView
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-25 22:22:47 -08:00
- argument: < [AndroidWebView]>
2021-02-11 10:31:57 -08:00
Emitted when a new WebView instance is detected.
## async method: AndroidDevice.close
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Disconnects from the device.
## async method: AndroidDevice.drag
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Drags the widget defined by [`param: selector` ] towards [`param: dest` ] point.
### param: AndroidDevice.drag.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to drag.
### param: AndroidDevice.drag.dest
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `dest` < [Object]>
- `x` < [float]>
- `y` < [float]>
Point to drag to.
### option: AndroidDevice.drag.speed
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `speed` < [float]>
Optional speed of the drag in pixels per second.
### option: AndroidDevice.drag.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.fill
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Fills the specific [`param: selector` ] input box with [`param: text` ].
### param: AndroidDevice.fill.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to fill.
### param: AndroidDevice.fill.text
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `text` < [string]>
Text to be filled in the input box.
### option: AndroidDevice.fill.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.fling
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Flings the widget defined by [`param: selector` ] in the specified [`param: direction` ].
### param: AndroidDevice.fling.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to fling.
### param: AndroidDevice.fling.direction
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `direction` < [AndroidFlingDirection]< "down"|"up"|"left"|"right">>
Fling direction.
### option: AndroidDevice.fling.speed
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `speed` < [float]>
Optional speed of the fling in pixels per second.
### option: AndroidDevice.fling.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.info
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [AndroidElementInfo]>
Returns information about a widget defined by [`param: selector` ].
### param: AndroidDevice.info.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to return information about.
## property: AndroidDevice.input
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- type: < [AndroidInput]>
## async method: AndroidDevice.installApk
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Installs an apk on the device.
### param: AndroidDevice.installApk.file
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `file` < [string]|[Buffer]>
Either a path to the apk file, or apk file content.
### option: AndroidDevice.installApk.args
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `args` < [Array]< [string]>>
Optional arguments to pass to the `shell:cmd package install` call. Defaults to `-r -t -S` .
## async method: AndroidDevice.launchBrowser
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-04-02 09:47:14 +08:00
- returns: < [BrowserContext]>
2021-02-11 10:31:57 -08:00
Launches Chrome browser on the device, and returns its persistent context.
### option: AndroidDevice.launchBrowser.pkg
2022-07-05 16:24:50 -08:00
* since: v1.9
2025-01-10 10:51:29 +01:00
- `pkg` < [string]>
2021-02-11 10:31:57 -08:00
Optional package name to launch instead of default Chrome for Android.
2022-07-05 16:24:50 -08:00
### option: AndroidDevice.launchBrowser.-inline- = %%-shared-context-params-list-v1.8-%%
* since: v1.9
2021-02-11 10:31:57 -08:00
2022-12-12 20:45:19 +05:30
### option: AndroidDevice.launchBrowser.proxy = %%-browser-option-proxy-%%
* since: v1.29
### option: AndroidDevice.launchBrowser.args = %%-browser-option-args-%%
* since: v1.29
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.longTap
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Performs a long tap on the widget defined by [`param: selector` ].
### param: AndroidDevice.longTap.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to tap on.
### option: AndroidDevice.longTap.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## method: AndroidDevice.model
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [string]>
Device model.
## async method: AndroidDevice.open
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [AndroidSocket]>
Launches a process in the shell on the device and returns a socket to communicate with the launched process.
### param: AndroidDevice.open.command
2022-07-05 16:24:50 -08:00
* since: v1.9
2024-09-26 06:31:42 -07:00
- `command` < [string]>
Shell command to execute.
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.pinchClose
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Pinches the widget defined by [`param: selector` ] in the closing direction.
### param: AndroidDevice.pinchClose.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to pinch close.
### param: AndroidDevice.pinchClose.percent
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `percent` < [float]>
The size of the pinch as a percentage of the widget's size.
### option: AndroidDevice.pinchClose.speed
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `speed` < [float]>
Optional speed of the pinch in pixels per second.
### option: AndroidDevice.pinchClose.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.pinchOpen
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Pinches the widget defined by [`param: selector` ] in the open direction.
### param: AndroidDevice.pinchOpen.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to pinch open.
### param: AndroidDevice.pinchOpen.percent
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `percent` < [float]>
The size of the pinch as a percentage of the widget's size.
### option: AndroidDevice.pinchOpen.speed
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `speed` < [float]>
Optional speed of the pinch in pixels per second.
### option: AndroidDevice.pinchOpen.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.press
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Presses the specific [`param: key` ] in the widget defined by [`param: selector` ].
### param: AndroidDevice.press.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to press the key in.
### param: AndroidDevice.press.key
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `key` < [AndroidKey]>
The key to press.
### option: AndroidDevice.press.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.push
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Copies a file to the device.
### param: AndroidDevice.push.file
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `file` < [string]|[Buffer]>
Either a path to the file, or file content.
### param: AndroidDevice.push.path
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `path` < [string]>
Path to the file on the device.
### option: AndroidDevice.push.mode
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `mode` < [int]>
Optional file mode, defaults to `644` (`rw-r--r--` ).
## async method: AndroidDevice.screenshot
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [Buffer]>
Returns the buffer with the captured screenshot of the device.
### option: AndroidDevice.screenshot.path
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `path` < [path]>
The file path to save the image to. If [`option: 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.
## async method: AndroidDevice.scroll
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Scrolls the widget defined by [`param: selector` ] in the specified [`param: direction` ].
### param: AndroidDevice.scroll.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to scroll.
### param: AndroidDevice.scroll.direction
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `direction` < [AndroidScrollDirection]< "down"|"up"|"left"|"right">>
Scroll direction.
### param: AndroidDevice.scroll.percent
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `percent` < [float]>
Distance to scroll as a percentage of the widget's size.
### option: AndroidDevice.scroll.speed
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `speed` < [float]>
Optional speed of the scroll in pixels per second.
### option: AndroidDevice.scroll.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## method: AndroidDevice.serial
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [string]>
Device serial number.
## method: AndroidDevice.setDefaultTimeout
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
This setting will change the default maximum time for all the methods accepting [`param: timeout` ] option.
### param: AndroidDevice.setDefaultTimeout.timeout
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `timeout` < [float]>
Maximum time in milliseconds
## async method: AndroidDevice.shell
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [Buffer]>
Executes a shell command on the device and returns its output.
### param: AndroidDevice.shell.command
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `command` < [string]>
Shell command to execute.
## async method: AndroidDevice.swipe
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Swipes the widget defined by [`param: selector` ] in the specified [`param: direction` ].
### param: AndroidDevice.swipe.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to swipe.
### param: AndroidDevice.swipe.direction
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `direction` < [AndroidSwipeDirection]< "down"|"up"|"left"|"right">>
Swipe direction.
### param: AndroidDevice.swipe.percent
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `percent` < [float]>
Distance to swipe as a percentage of the widget's size.
### option: AndroidDevice.swipe.speed
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `speed` < [float]>
Optional speed of the swipe in pixels per second.
### option: AndroidDevice.swipe.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.tap
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Taps on the widget defined by [`param: selector` ].
### param: AndroidDevice.tap.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to tap on.
### option: AndroidDevice.tap.duration
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `duration` < [float]>
Optional duration of the tap in milliseconds.
### option: AndroidDevice.tap.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.wait
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
Waits for the specific [`param: selector` ] to either appear or disappear, depending on the [`option: state` ].
### param: AndroidDevice.wait.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [AndroidSelector]>
Selector to wait for.
### option: AndroidDevice.wait.state
2022-07-05 16:24:50 -08:00
* since: v1.9
2022-03-08 16:02:31 -08:00
- `state` < [AndroidDeviceState]< "gone">>
2021-02-11 10:31:57 -08:00
Optional state. Can be either:
* default - wait for element to be present.
* `'gone'` - wait for element to not be present.
### option: AndroidDevice.wait.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## async method: AndroidDevice.waitForEvent
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [any]>
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value.
### param: AndroidDevice.waitForEvent.event = %%-wait-for-event-event-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
### param: AndroidDevice.waitForEvent.optionsOrPredicate
2022-07-05 16:24:50 -08:00
* since: v1.9
2022-04-06 19:02:10 -07:00
- `optionsOrPredicate` ?< [function]|[Object]>
2021-02-11 10:31:57 -08:00
- `predicate` < [function]> receives the event data and resolves to truthy value when the waiting should resolve.
2022-04-06 19:02:10 -07:00
- `timeout` ?< [float]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to
2021-02-11 10:31:57 -08:00
disable timeout. The default value can be changed by using the [`method: AndroidDevice.setDefaultTimeout` ].
Either a predicate that receives an event or an options object. Optional.
## async method: AndroidDevice.webView
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [AndroidWebView]>
2024-09-26 01:08:16 -07:00
This method waits until [AndroidWebView] matching the [`param: selector` ] is opened and returns it. If there is already an open [AndroidWebView] matching the [`param: selector` ], returns immediately.
2021-02-11 10:31:57 -08:00
### param: AndroidDevice.webView.selector
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- `selector` < [Object]>
2022-04-09 02:52:16 +08:00
- `pkg` ?< [string]> Optional Package identifier.
- `socketName` ?< [string]> Optional webview socket name.
2021-02-11 10:31:57 -08:00
### option: AndroidDevice.webView.timeout = %%-android-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
## method: AndroidDevice.webViews
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-11 10:31:57 -08:00
- returns: < [Array]< [AndroidWebView]>>
Currently open WebViews.