AndroidDevice
Added in: v1.9AndroidDevice represents a connected device, either real hardware or emulated. Devices can be obtained using android.devices().
Methods
androidDevice.close()
Added in: v1.9 asyncDisconnects from the device.
androidDevice.drag()
Added in: v1.9 asyncDrags the widget defined by selector towards dest point.
Arguments
Selector to drag.
Point to drag to.
xfloatyfloat
Optional speed of the drag in pixels per second.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.fill()
Added in: v1.9 asyncFills the specific selector input box with text.
Arguments
Selector to fill.
Text to be filled in the input box.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.fling()
Added in: v1.9 asyncFlings the widget defined by selector in the specified direction.
Arguments
Selector to fling.
direction"down" | "up" | "left" | "right"Fling direction.
Optional speed of the fling in pixels per second.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.info()
Added in: v1.9 asyncReturns information about a widget defined by selector.
Arguments
Returns
Promise<AndroidElementInfo>
androidDevice.installApk()
Added in: v1.9 asyncInstalls an apk on the device.
Arguments
Either a path to the apk file, or apk file content.
androidDevice.launchBrowser()
Added in: v1.9 asyncLaunches Chrome browser on the device, and returns its persistent context.
Arguments
acceptDownloadsboolean(optional)Whether to automatically download all the attachments. Defaults to
truewhere all the downloads are accepted.argsArray<string>(optional) Added in: v1.29WARNING
Use custom browser args at your own risk, as some of them may break Playwright functionality.
Additional arguments to pass to the browser instance. The list of Chromium flags can be found here.
When using
page.goto(),page.route(),page.waitForURL(),page.waitForRequest(), orpage.waitForResponse()it takes the base URL in consideration by using theURL()constructor for building the corresponding URL. Unset by default. Examples:- baseURL:
http://localhost:3000and navigating to/bar.htmlresults inhttp://localhost:3000/bar.html - baseURL:
http://localhost:3000/foo/and navigating to./bar.htmlresults inhttp://localhost:3000/foo/bar.html - baseURL:
http://localhost:3000/foo(without trailing slash) and navigating to./bar.htmlresults inhttp://localhost:3000/bar.html
- baseURL:
Toggles bypassing page's Content-Security-Policy. Defaults to
false.colorSchemenull | "light" | "dark" | "no-preference"(optional)Emulates prefers-colors-scheme media feature, supported values are
'light'and'dark'. Seepage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to'light'.contrastnull | "no-preference" | "more"(optional)Emulates
'prefers-contrast'media feature, supported values are'no-preference','more'. Seepage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to'no-preference'.deviceScaleFactorfloat(optional)Specify device scale factor (can be thought of as dpr). Defaults to
1. Learn more about emulating devices with device scale factor.extraHTTPHeadersObject<string, string>(optional)An object containing additional HTTP headers to be sent with every request. Defaults to none.
forcedColorsnull | "active" | "none"(optional)Emulates
'forced-colors'media feature, supported values are'active','none'. Seepage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to'none'.latitudefloatLatitude between -90 and 90.
longitudefloatLongitude between -180 and 180.
accuracyfloat(optional)Non-negative accuracy value. Defaults to
0.
Specifies if viewport supports touch events. Defaults to false. Learn more about mobile emulation.
httpCredentialsObject | Array<Object>(optional)Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.
Pass an array to use different credentials for different origins. The first entry that matches the request origin is used, and entries with no origin match any request.
usernamestringpasswordstringoriginstring(optional)Restrain sending http credentials on specific origin (scheme://host:port).
send"unauthorized" | "always"(optional)This option only applies to the requests sent from corresponding APIRequestContext and does not affect requests sent from the browser.
'always'-Authorizationheader with basic authentication credentials will be sent with the each API request.'unauthorized- the credentials are only sent when 401 (Unauthorized) response withWWW-Authenticateheader is received. Defaults to'unauthorized'.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.Whether the
meta viewporttag is taken into account and touch events are enabled. isMobile is a part of device, so you don't actually need to set it manually. Defaults tofalse. Learn more about mobile emulation.javaScriptEnabledboolean(optional)Whether or not to enable JavaScript in the context. Defaults to
true. Learn more about disabling JavaScript.Specify user locale, for example
en-GB,de-DE, etc. Locale will affectnavigator.languagevalue,Accept-Languagerequest header value as well as number and date formatting rules. Defaults to the system default locale. Learn more about emulation in our emulation guide.locateOnlyVisibleboolean(optional)Whether locators in this context find only visible elements. Defaults to
false.When enabled, Playwright applies two rules:
- The element that a locator finds must be visible. Actions, assertions and queries behave as if
locator.visible()was called at the end of the locator chain. locator.first(),locator.last()andlocator.nth()select among visible elements. They behave as iflocator.visible()was called immediately before them.
js// <div hidden>One</div> <div>Two</div> <div>Three</div> await expect(page.locator('div')).toHaveCount(2); await expect(page.locator('div').first()).toHaveText('Two'); await expect(page.locator('div').last()).toHaveText('Three');An explicit visibility filter always has priority. Playwright does not add its own filter in a position that already has one. For example,
page.locator('div').filter({ visible: false }).first()finds the first hidden element.All other parts of the locator chain are not filtered. In
page.locator('section').getByRole('button'), the button must be visible, but the section can be hidden by the visibility rules, for example because it has zero size. The same applies to the inner locators oflocator.filter(),locator.and()andlocator.or(): only the second rule applies to them.This option does not change the accessibility rules of
page.getByRole()or the behavior of selector-based methods such aspage.$().- The element that a locator finds must be visible. Actions, assertions and queries behave as if
Logger sink for Playwright logging.
Whether to emulate network being offline. Defaults to
false. Learn more about network emulation.permissionsArray<string>(optional)A list of permissions to grant to all pages in this context. See
browserContext.grantPermissions()for more details. Defaults to none.Optional package name to launch instead of default Chrome for Android.
proxyObject(optional) Added in: v1.29Network proxy settings.
serverstringAdded in: v1.29Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example
http://myproxy.com:3128orsocks5://myproxy.com:3128. Short formmyproxy.com:3128is considered an HTTP proxy.bypassstring(optional) Added in: v1.29Optional comma-separated domains to bypass proxy, for example
".com, chromium.org, .domain.com".usernamestring(optional) Added in: v1.29Optional username to use if HTTP proxy requires authentication.
passwordstring(optional) Added in: v1.29Optional password to use if HTTP proxy requires authentication.
Enables HAR recording for all pages into
recordHar.pathfile. If not specified, the HAR is not recorded. Make sure to awaitbrowserContext.close()for the HAR to be saved.omitContentboolean(optional)Optional setting to control whether to omit request content from the HAR. Defaults to
false. Deprecated, usecontentpolicy instead.content"omit" | "embed" | "attach"(optional)Optional setting to control resource content management. If
omitis specified, content is not persisted. Ifattachis specified, resources are persisted as separate files or entries in the ZIP archive. Ifembedis specified, content is stored inline the HAR file as per HAR specification. Defaults toattachfor.zipoutput files and toembedfor all other file extensions.pathpathPath 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"(optional)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 tofull.urlFilterstring | RegExp(optional)A glob or regex pattern to filter requests that are stored in the HAR. When a
baseURLvia the context options was provided and the passed URL is a path, it gets merged via thenew URL()constructor. Defaults to none.
Enables video recording for all pages into
recordVideo.dirdirectory. If not specified videos are not recorded. Make sure to awaitbrowserContext.close()for videos to be saved.dirpath(optional)Path to the directory to put videos into. If not specified, the videos will be stored in
artifactsDir(seebrowserType.launch()options).sizeObject(optional)Optional dimensions of the recorded videos. If not specified the size will be equal to
viewportscaled down to fit into 800x800. Ifviewportis 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.widthintVideo frame width.
heightintVideo frame height.
fpsint(optional)Frame rate of the recorded videos in frames per second. Defaults to
25. Firefox and WebKit currently capture up to 25 frames per second.showActionsObject(optional)If specified, enables visual annotations on interacted elements during video recording.
durationfloat(optional)How long each annotation is displayed in milliseconds. Defaults to
500.position"top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right"(optional)Position of the action title overlay. Defaults to
"top-right".fontSizeint(optional)Font size of the action title in pixels. Defaults to
24. Deprecated, usestyle.titleinstead.cursor"none" | "pointer"(optional)Cursor decoration shown for pointer actions.
"pointer"(the default) renders a mouse pointer that animates from the previous action point to the next one."none"disables the cursor decoration.styleObject(optional)Styles of the action decorations.
pointstring(optional)CSS declarations for the zero-sized marker centered on the action point. Not shown when omitted.
highlightstring(optional)CSS declarations for the box that covers the target element. Not shown when omitted.
titlestring(optional)CSS declarations for the action title.
reducedMotionnull | "reduce" | "no-preference"(optional)Emulates
'prefers-reduced-motion'media feature, supported values are'reduce','no-preference'. Seepage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to'no-preference'.Emulates consistent window screen size available inside web page via
window.screen. Is only used when theviewportis set.widthintpage width in pixels.
heightintpage height in pixels.
serviceWorkers"allow" | "block"(optional)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.
strictSelectorsboolean(optional)If set to true, 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. This option does not affect any Locator APIs (Locators are always strict). Defaults to
false. See Locator to learn more about the strict mode.Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs. Defaults to the system timezone.
Specific user agent to use in this context.
viewportnull | Object(optional)Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use
nullto disable the consistent viewport emulation. Learn more about viewport emulation.INFO
The
nullvalue opts out from the default presets, makes viewport depend on the host window size defined by the operating system. It makes the execution of the tests non-deterministic.widthintpage width in pixels.
heightintpage height in pixels.
Returns
Promise<BrowserContext>
androidDevice.longTap()
Added in: v1.9 asyncPerforms a long tap on the widget defined by selector.
Arguments
Selector to tap on.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.model()
Added in: v1.9Device model.
Returns
string
androidDevice.open()
Added in: v1.9 asyncLaunches a process in the shell on the device and returns a socket to communicate with the launched process.
Arguments
Returns
Promise<AndroidSocket>
androidDevice.pinchClose()
Added in: v1.9 asyncPinches the widget defined by selector in the closing direction.
Arguments
Selector to pinch close.
The size of the pinch as a percentage of the widget's size.
Optional speed of the pinch in pixels per second.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.pinchOpen()
Added in: v1.9 asyncPinches the widget defined by selector in the open direction.
Arguments
Selector to pinch open.
The size of the pinch as a percentage of the widget's size.
Optional speed of the pinch in pixels per second.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.press()
Added in: v1.9 asyncPresses the specific key in the widget defined by selector.
Arguments
Selector to press the key in.
The key to press.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.push()
Added in: v1.9 asyncCopies a file to the device.
Arguments
Either a path to the file, or file content.
Path to the file on the device.
androidDevice.screenshot()
Added in: v1.9 asyncReturns the buffer with the captured screenshot of the device.
Arguments
The file path to save the image to. If
pathis 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>
androidDevice.scroll()
Added in: v1.9 asyncScrolls the widget defined by selector in the specified direction.
Arguments
Selector to scroll.
direction"down" | "up" | "left" | "right"Scroll direction.
Distance to scroll as a percentage of the widget's size.
Optional speed of the scroll in pixels per second.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.serial()
Added in: v1.9Device serial number.
Returns
string
androidDevice.setDefaultTimeout()
Added in: v1.9This setting will change the default maximum time for all the methods accepting timeout option.
Arguments
androidDevice.shell()
Added in: v1.9 asyncExecutes a shell command on the device and returns its output.
Arguments
Returns
Promise<Buffer>
androidDevice.swipe()
Added in: v1.9 asyncSwipes the widget defined by selector in the specified direction.
Arguments
Selector to swipe.
direction"down" | "up" | "left" | "right"Swipe direction.
Distance to swipe as a percentage of the widget's size.
Optional speed of the swipe in pixels per second.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.tap()
Added in: v1.9 asyncTaps on the widget defined by selector.
Arguments
Selector to tap on.
Optional duration of the tap in milliseconds.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.wait()
Added in: v1.9 asyncWaits for the specific selector to either appear or disappear, depending on the state.
Arguments
Selector to wait for.
Optional state. Can be either:
- default - wait for element to be present.
'gone'- wait for element to not be present.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
androidDevice.waitForEvent()
Added in: v1.9 asyncWaits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value.
Arguments
Event name, same one typically passed into
*.on(event).optionsOrPredicatefunction() | Object(optional)Either a predicate that receives an event or an options object. Optional.
predicatefunction()receives the event data and resolves to truthy value when the waiting should resolve.
timeoutfloat(optional)maximum time to wait for in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout().
Returns
Promise<any>
androidDevice.webView()
Added in: v1.9 asyncThis method waits until AndroidWebView matching the selector is opened and returns it. If there is already an open AndroidWebView matching the selector, returns immediately.
Arguments
pkgstring(optional)Optional Package identifier.
socketNamestring(optional)Optional webview socket name.
Maximum time in milliseconds, defaults to 30 seconds, pass
0to disable timeout. The default value can be changed by using theandroidDevice.setDefaultTimeout()method.
Returns
Promise<AndroidWebView>
androidDevice.webViews()
Added in: v1.9Currently open WebViews.
Returns
Array<AndroidWebView>
Properties
androidDevice.input
Added in: v1.9Type
AndroidInput
Events
androidDevice.on('close')
Added in: v1.28Emitted when the device connection gets closed.
Event data
AndroidDevice
androidDevice.on('webView')
Added in: v1.9Emitted when a new WebView instance is detected.
Event data
AndroidWebView