playwright/packages/playwright-android
Dmitry Gozman 99f8e1cf63
docs: document Android and friends (#5415)
These are experimental, currently available through `_android`.
2021-02-11 10:31:57 -08:00
..
index.d.ts docs: document Android and friends (#5415) 2021-02-11 10:31:57 -08:00
index.js feat(cli): first few cli commands (#4773) 2020-12-22 14:54:13 -08:00
index.mjs chore: expose adb devices and actions (#4647) 2020-12-09 15:06:57 -08:00
install.js chore: expose adb devices and actions (#4647) 2020-12-09 15:06:57 -08:00
README.md fix(adb): minor fixes (#4678) 2020-12-10 16:37:18 -08:00

playwright-android

This package contains the Android flavor of Playwright.

Requirements

  • Android device or AVD Emulator.
  • ADB daemon running and authenticated with your device. Typically running adb devices is all you need to do.
  • Chrome 87 or newer installed on the device
  • "Enable command line on non-rooted devices" enabled in chrome://flags.

How to demo

const { android } = require('playwright-android');

(async () => {
  const [device] = await android.devices();
  console.log(`Model: ${device.model()}`);
  console.log(`Serial: ${device.serial()}`);

  await device.shell('am force-stop org.chromium.webview_shell');
  await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');

  const webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
  const page = await webview.page();

  await device.fill({ res: 'org.chromium.webview_shell:id/url_field' }, 'github.com/microsoft/playwright');
  await Promise.all([
    page.waitForNavigation(),
    device.press({ res: 'org.chromium.webview_shell:id/url_field' }, 'Enter')
  ]);
  console.log(await page.title());

  {
    const context = await device.launchBrowser();
    const [page] = context.pages();
    await page.goto('https://webkit.org/');
    console.log(await page.evaluate(() => window.location.href));
    await context.close();
  }

  await device.close();
})();