AndroidDevice
AndroidDevice represents a connected device, either real hardware or emulated. Devices can be obtained using android.devices([options]).
- androidDevice.on('webview')
- androidDevice.close()
- androidDevice.drag(selector, dest[, options])
- androidDevice.fill(selector, text[, options])
- androidDevice.fling(selector, direction[, options])
- androidDevice.info(selector)
- androidDevice.input
- 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.on('webview')
Added in: v1.9- type: <AndroidWebView>
Emitted when a new WebView instance is detected.
androidDevice.close()
Added in: v1.9Disconnects from the device.
androidDevice.drag(selector, dest[, options])
Added in: v1.9selector
<[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])
Added in: v1.9selector
<[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])
Added in: v1.9selector
<[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)
Added in: v1.9selector
<[AndroidSelector]> Selector to return information about.#- returns:Promise<[AndroidElementInfo]>># <
Returns information about a widget defined by selector
.
androidDevice.installApk(file[, options])
Added in: v1.9file
<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])
Added in: v1.9options?
<Object>acceptDownloads?
<boolean> Whether to automatically download all the attachments. Defaults totrue
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 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:
http://localhost:3000/foo
(without trailing slash) and navigating to./bar.html
results inhttp://localhost:3000/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.#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>#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 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.#logger?
<Logger> Logger sink for Playwright logging.#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.#omitContent?
<boolean> Optional setting to control whether to omit request content from the HAR. Defaults tofalse
. Deprecated, usecontent
policy instead.content?
<"omit"|"embed"|"attach"> Optional setting to control resource content management. Ifomit
is specified, content is not persisted. Ifattach
is specified, resources are persisted as separate files or entries in the ZIP archive. Ifembed
is specified, content is stored inline the HAR file as per HAR specification. Defaults toattach
for.zip
output files and toembed
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 tominimal
, 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 tofull
.urlFilter?
<string|RegExp> A glob or regex pattern to filter requests that are stored in the HAR. When abaseURL
via the context options was provided and the passed URL is a path, it gets merged via thenew URL()
constructor.
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.#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 UserecordVideo
instead.#videosPath?
<string> DEPRECATED UserecordVideo
instead.#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])
Added in: v1.9selector
<[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()
Added in: v1.9Device model.
androidDevice.open(command)
Added in: v1.9command
<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])
Added in: v1.9selector
<[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])
Added in: v1.9selector
<[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])
Added in: v1.9selector
<[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])
Added in: v1.9file
<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])
Added in: v1.9Returns the buffer with the captured screenshot of the device.
androidDevice.scroll(selector, direction, percent[, options])
Added in: v1.9selector
<[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()
Added in: v1.9Device serial number.
androidDevice.setDefaultTimeout(timeout)
Added in: v1.9This setting will change the default maximum time for all the methods accepting timeout
option.
androidDevice.shell(command)
Added in: v1.9Executes a shell command on the device and returns its output.
androidDevice.swipe(selector, direction, percent[, options])
Added in: v1.9selector
<[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])
Added in: v1.9selector
<[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])
Added in: v1.9selector
<[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])
Added in: v1.9event
<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])
Added in: v1.9selector
<Object>#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()
Added in: v1.9- returns:Array<AndroidWebView>># <
Currently open WebViews.
androidDevice.input
Added in: v1.9- type: <AndroidInput>