Class: Playwright::Android
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Android
- Defined in:
- lib/playwright_api/android.rb
Overview
Playwright has experimental support for Android automation. You can access android namespace via:
“‘js const { _android } = require(’playwright’); “‘
An example of the Android automation script would be:
“‘js const { _android } = require(’playwright’);
(async () =>
// Connect to the device.
const [device] = await playwright._android.devices();
console.log(`Model: ${device.model()`);
console.log(`Serial: $devicedevice.serial()`);
// Take screenshot of the whole device.
await device.screenshot({ path: 'device.png' });
{
// --------------------- WebView -----------------------
// Launch an application with WebView.
await device.shell('am force-stop org.chromium.webview_shell');
await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
// Get the WebView.
const webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
// Fill the input box.
await device.fill({ res: 'org.chromium.webview_shell:id/url_field' }, 'github.com/microsoft/playwright');
await device.press({ res: 'org.chromium.webview_shell:id/url_field' }, 'Enter');
// Work with WebView's page as usual.
const page = await webview.page();
await page.page.waitForNavigation({ url: /.*microsoft\/playwright.*/ });
console.log(await page.title());
}
{
// --------------------- Browser -----------------------
// Launch Chrome browser.
await device.shell('am force-stop com.android.chrome');
const context = await device.launchBrowser();
// Use BrowserContext as usual.
const page = await context.newPage();
await page.goto('https://webkit.org/');
console.log(await page.evaluate(() => window.location.href));
await page.screenshot({ path: 'page.png' });
await context.close();
}
// Close the device.
await device.close();
})(); “‘
Note that since you don’t need Playwright to install web browsers when testing Android, you can omit browser download via setting the following environment variable when installing Playwright:
“‘sh js $ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright “`
Instance Method Summary collapse
-
#devices ⇒ Object
Returns the list of detected Android devices.
-
#off(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#on(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#once(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#set_default_timeout(timeout) ⇒ Object
(also: #default_timeout=)
This setting will change the default maximum time for all the methods accepting ‘timeout` option.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#devices ⇒ Object
Returns the list of detected Android devices.
72 73 74 |
# File 'lib/playwright_api/android.rb', line 72 def devices wrap_impl(@impl.devices) end |
#off(event, callback) ⇒ Object
– inherited from EventEmitter –
84 85 86 |
# File 'lib/playwright_api/android.rb', line 84 def off(event, callback) event_emitter_proxy.off(event, callback) end |
#on(event, callback) ⇒ Object
– inherited from EventEmitter –
96 97 98 |
# File 'lib/playwright_api/android.rb', line 96 def on(event, callback) event_emitter_proxy.on(event, callback) end |
#once(event, callback) ⇒ Object
– inherited from EventEmitter –
90 91 92 |
# File 'lib/playwright_api/android.rb', line 90 def once(event, callback) event_emitter_proxy.once(event, callback) end |
#set_default_timeout(timeout) ⇒ Object Also known as: default_timeout=
This setting will change the default maximum time for all the methods accepting ‘timeout` option.
77 78 79 |
# File 'lib/playwright_api/android.rb', line 77 def set_default_timeout(timeout) raise NotImplementedError.new('set_default_timeout is not implemented yet.') end |