AndroidDevice
AndroidDevice represents a connected device, either real hardware or emulated. Devices can be obtained using android.devices().
- androidDevice.on('webview')
- androidDevice.close()
- androidDevice.drag(selector, dest[, options])
- androidDevice.fill(selector, text[, options])
- androidDevice.fling(selector, direction[, options])
- androidDevice.info(selector)
- androidDevice.installApk(file[, options])
- androidDevice.launchBrowser([options])
- androidDevice.longTap(selector[, options])
- androidDevice.model()
- androidDevice.open(command)
- androidDevice.pinchClose(selector, percent[, options])
- androidDevice.pinchOpen(selector, percent[, options])
- androidDevice.press(selector, key[, options])
- androidDevice.push(file, path[, options])
- androidDevice.screenshot([options])
- androidDevice.scroll(selector, direction, percent[, options])
- androidDevice.serial()
- androidDevice.setDefaultTimeout(timeout)
- androidDevice.shell(command)
- androidDevice.swipe(selector, direction, percent[, options])
- androidDevice.tap(selector[, options])
- androidDevice.wait(selector[, options])
- androidDevice.waitForEvent(event[, optionsOrPredicate])
- androidDevice.webView(selector[, options])
- androidDevice.webViews()
- androidDevice.input
#
androidDevice.on('webview')- type: <AndroidWebView>
Emitted when a new WebView instance is detected.
#
androidDevice.close()Disconnects from the device.
#
androidDevice.drag(selector, dest[, options])selector
<[AndroidSelector]> Selector to drag.#dest
<Object> Point to drag to.#options
<Object>speed
<number> Optional speed of the drag in pixels per second.#timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Drags the widget defined by selector
towards dest
point.
#
androidDevice.fill(selector, text[, options])selector
<[AndroidSelector]> Selector to fill.#text
<string> Text to be filled in the input box.#options
<Object>timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Fills the specific selector
input box with text
.
#
androidDevice.fling(selector, direction[, options])selector
<[AndroidSelector]> Selector to fling.#direction
<"down"|"up"|"left"|"right"> Fling direction.#options
<Object>speed
<number> Optional speed of the fling in pixels per second.#timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Flings the widget defined by selector
in the specified direction
.
#
androidDevice.info(selector)selector
<[AndroidSelector]> Selector to return information about.#- returns:Promise<[AndroidElementInfo]>># <
Returns information about a widget defined by selector
.
#
androidDevice.installApk(file[, options])file
<string|Buffer> Either a path to the apk file, or apk file content.#options
<Object>- returns:Promise<void>># <
Installs an apk on the device.
#
androidDevice.launchBrowser([options])options
<Object>acceptDownloads
<boolean> Whether to automatically download all the attachments. Defaults tofalse
where all the downloads are canceled.#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 theURL()
constructor for building the corresponding URL. Examples:#- baseURL:
http://localhost:3000
and navigating to/bar.html
results inhttp://localhost:3000/bar.html
- baseURL:
http://localhost:3000/foo/
and navigating to./bar.html
results inhttp://localhost:3000/foo/bar.html
- baseURL:
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 to1
.#extraHTTPHeaders
<Object<string, string>> An object containing additional HTTP headers to be sent with every request. All header values must be strings.#forcedColors
<"active"|"none"> Emulates'forced-colors'
media feature, supported values are'active'
,'none'
. See page.emulateMedia([options]) for more details. Defaults to'none'
.#note
It's not supported in WebKit, see here in their issue tracker.
hasTouch
<boolean> Specifies if viewport supports touch events. Defaults to false.#httpCredentials
<Object> Credentials for HTTP authentication.#ignoreHTTPSErrors
<boolean> Whether to ignore HTTPS errors during navigation. Defaults tofalse
.#isMobile
<boolean> Whether themeta viewport
tag is taken into account and touch events are enabled. Defaults tofalse
. Not supported in Firefox.#javaScriptEnabled
<boolean> Whether or not to enable JavaScript in the context. Defaults totrue
.#locale
<string> Specify user locale, for exampleen-GB
,de-DE
, etc. Locale will affectnavigator.language
value,Accept-Language
request header value as well as number and date formatting rules.#offline
<boolean> Whether to emulate network being offline. Defaults tofalse
.#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 intorecordHar.path
file. If not specified, the HAR is not recorded. Make sure to await browserContext.close() for the HAR to be saved.#recordVideo
<Object> Enables video recording for all pages intorecordVideo.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 toviewport
scaled down to fit into 800x800. Ifviewport
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.
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 viawindow.screen
. Is only used when theviewport
is set.#strictSelectors
<boolean> It 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.#viewport
<null|Object> Emulates consistent viewport for each page. Defaults to an 1280x720 viewport.null
disables the default viewport.#
returns:Promise<BrowserContext>>#
<
Launches Chrome browser on the device, and returns its persistent context.
#
androidDevice.longTap(selector[, options])selector
<[AndroidSelector]> Selector to tap on.#options
<Object>timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Performs a long tap on the widget defined by selector
.
#
androidDevice.model()Device model.
#
androidDevice.open(command)command
<string>#- returns:Promise<AndroidSocket>># <
Launches a process in the shell on the device and returns a socket to communicate with the launched process.
#
androidDevice.pinchClose(selector, percent[, options])selector
<[AndroidSelector]> Selector to pinch close.#percent
<number> The size of the pinch as a percentage of the widget's size.#options
<Object>speed
<number> Optional speed of the pinch in pixels per second.#timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Pinches the widget defined by selector
in the closing direction.
#
androidDevice.pinchOpen(selector, percent[, options])selector
<[AndroidSelector]> Selector to pinch open.#percent
<number> The size of the pinch as a percentage of the widget's size.#options
<Object>speed
<number> Optional speed of the pinch in pixels per second.#timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Pinches the widget defined by selector
in the open direction.
#
androidDevice.press(selector, key[, options])selector
<[AndroidSelector]> Selector to press the key in.#key
<[AndroidKey]> The key to press.#options
<Object>timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Presses the specific key
in the widget defined by selector
.
#
androidDevice.push(file, path[, options])file
<string|Buffer> Either a path to the file, or file content.#path
<string> Path to the file on the device.#options
<Object>- returns:Promise<void>># <
Copies a file to the device.
#
androidDevice.screenshot([options])Returns the buffer with the captured screenshot of the device.
#
androidDevice.scroll(selector, direction, percent[, options])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>speed
<number> Optional speed of the scroll in pixels per second.#timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Scrolls the widget defined by selector
in the specified direction
.
#
androidDevice.serial()Device serial number.
#
androidDevice.setDefaultTimeout(timeout)This setting will change the default maximum time for all the methods accepting timeout
option.
#
androidDevice.shell(command)Executes a shell command on the device and returns its output.
#
androidDevice.swipe(selector, direction, percent[, options])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>speed
<number> Optional speed of the swipe in pixels per second.#timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Swipes the widget defined by selector
in the specified direction
.
#
androidDevice.tap(selector[, options])selector
<[AndroidSelector]> Selector to tap on.#options
<Object>duration
<number> Optional duration of the tap in milliseconds.#timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<void>># <
Taps on the widget defined by selector
.
#
androidDevice.wait(selector[, options])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, pass0
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])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 to30000
(30 seconds). Pass0
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])selector
<Object>#pkg
<string> Package identifier.
options
<Object>timeout
<number> Maximum time in milliseconds, defaults to 30 seconds, pass0
to disable timeout. The default value can be changed by using the androidDevice.setDefaultTimeout(timeout) method.#
- returns:Promise<AndroidWebView>># <
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()- returns:Array<AndroidWebView>># <
Currently open WebViews.
#
androidDevice.input- type: <AndroidInput>