microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.73k stars 3.65k forks source link

androidWebView.page: Cannot read property 'mainFrame' of undefined #6640

Closed SirCameron closed 3 years ago

SirCameron commented 3 years ago

Hi

I'm using the playwright-android package on an emulator.

Running this returns the above error:

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

        {
            // 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' }, 'https://google.com')
            await device.press({ res: 'org.chromium.webview_shell:id/url_field' }, 'Enter')

            // Work with WebView's page as usual.
            await webview.page()

I have not been able to find anything about this around the web and the android-playwright package has no documentation of it's own. Would using webview.page() be the correct way to interact with elements in a webview?

Also, where can I find information/documentation on AndroidSelector?

Thanks in advance for any help.

mxschmitt commented 3 years ago

Hi, the playwright-android package is deprecated, see here for an up-to-date example: https://playwright.dev/docs/api/class-android

SirCameron commented 3 years ago

thanks @mxschmitt . I tried it using the android class from the playwright package and it simply hangs... no error, nothing. Running the webview example on the page you provided, it never logs out the page title. simply hangs on webview.page().

mxschmitt commented 3 years ago

where does it hang? Could you try setting the following environment variable, this should give you more debug logs: DEBUG=pw:android

SirCameron commented 3 years ago

Thanks, as I've said "simply hangs on webview.page()". Until it finally times out. I have been running it with the DEBUG=pw:android env variabled, but it hasn't given me anything valuable.

SirCameron commented 3 years ago

this is the output:

yarn run v1.22.10
$ DEBUG=pw:android jest
  console.log
    Model: AOSP on IA Emulator

      at src/e2e/android.test.ts:73:17

  console.log
    Serial: emulator-5554

      at src/e2e/android.test.ts:74:17

  pw:android Stopping the old driver +0ms
  pw:android Uninstalling the old driver +0ms
  pw:android Installing the new driver +0ms
  pw:android Opening install socket +0ms
  pw:android Writing driver bytes: 587818 +0ms
  pw:android Written driver bytes: Success
  pw:android  +0ms
  pw:android Opening install socket +0ms
  pw:android Writing driver bytes: 770013 +0ms
  pw:android Written driver bytes: Success
  pw:android  +0ms
  pw:android Starting the new driver +0ms
  pw:android Polling the socket localabstract:playwright_android_driver_socket +0ms
  pw:android Connected to localabstract:playwright_android_driver_socket +0ms
  pw:android Polling the socket localabstract:webview_devtools_remote_12888 +0ms
  pw:android Connected to localabstract:webview_devtools_remote_12888 +0ms
 FAIL   browser: chromium  src/e2e/android.test.ts (122.505 s)
  Android test
    ✕ should complete a paypal checkout (119996 ms)

  ● Android test › should complete a paypal checkout

    thrown: "Exceeded timeout of 120000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      69 |
      70 | describe('Android test', () => {
    > 71 |     it('should complete a paypal checkout', async () => {
         |     ^
      72 |         const [device] = await _android.devices()
      73 |         console.log(`Model: ${device.model()}`)
      74 |         console.log(`Serial: ${device.serial()}`)

      at src/e2e/android.test.ts:71:5
      at Object.<anonymous> (src/e2e/android.test.ts:70:1)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        123.472 s
mxschmitt commented 3 years ago

Which android sdk version are you using in your emulator? We use the following: create avd --force --name android30 --device "Nexus 5X" --package "system-images;android-30;google_apis;x86"

SirCameron commented 3 years ago

Thanks @mxschmitt I created a nexus 5x device with android 30 and it's working now.