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.5k stars 3.64k forks source link

[BUG] Playwright-Electron - app is closed prematurely (Cannot find parent object BrowserContext@..) #5130

Closed GozaRuu closed 11 months ago

GozaRuu commented 3 years ago

Context:

Error in closing the Electron App prematurely by Playwright:

Cannot find parent object BrowserContext@912bf0472762907aa3bd5b519c3d4926 to create Frame@4349c5b1c0893b0b3ba9ebd5177b7dc8

      at Connection._createRemoteObject (node_modules/playwright-electron/lib/client/connection.js:138:19)
      at Connection.dispatch (node_modules/playwright-electron/lib/client/connection.js:105:18)
      at Immediate.<anonymous> (node_modules/playwright-electron/lib/inprocess.js:42:85)
    Cannot find object to call "window": ElectronApplication@81ee6d8d22aa8f42ffc9db71acab8a47

      at Connection.dispatch (node_modules/playwright-electron/lib/client/connection.js:117:19)
      at Immediate.<anonymous> (node_modules/playwright-electron/lib/inprocess.js:42:85)

It happens randomly causing a lot of flakiness in the tests. As a workaround, I'm no longer closing the app in the after each hook. Instead I let all the tests run and close them in after all with a killall cmd which causes a range of other problems like bubbling errors of failed calls to non existing objects:

  console.error
    Error: Cannot find object to call "page": BrowserContext@13d28517196a0555b87a277f8c294aa2
        at Connection.dispatch (D:\a\1\s\node_modules\playwright-electron\lib\client\connection.js:117:19)
        at Immediate.<anonymous> (D:\a\1\s\node_modules\playwright-electron\lib\inprocess.js:42:85)
        at processImmediate (internal/timers.js:456:21)

      at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:249:21)
pavelfeldman commented 3 years ago

Any chance you can share a test script or a reduced test case?

GozaRuu commented 3 years ago

This is how we start it:

    this.app = await electron.launch(String(electronPath), {
      args: [
        join(__dirname, 'main.js'),
        `--user-data-dir=${tempDir.path}`,
        '--no-sandbox',
        '--whitelisted-ips',
        '--enable-logging',
        '--ignore-certificate-errors',
        '--ignore-ssl-errors',
        '--disable-dev-shm-usage',
      ],
      env: {
        ELECTRON_ENABLE_LOGGING: true,
        ELECTRON_ENABLE_STACK_DUMPING: true,
        NODE_ENV: 'test',
        IS_RELEASE: this.appParams.isRelease || '',
      },
    })

It happens randomly on almost any tests even simple ones like:

    const electronBrowser = await playwright.firstWindow().browserWindow
    const {
      isMinimized,
      isDevToolsOpened,
      isEnabled,
      height,
      width,
      isLoading,
      title,
    } = await electronBrowser.evaluate((browserWindow: BrowserWindow) => {
      return {
        isMinimized: browserWindow.isMinimized(),
        isDevToolsOpened: browserWindow.webContents.isDevToolsOpened(),
        isEnabled: browserWindow.isEnabled(),
        ...browserWindow.getBounds(),
        isLoading: browserWindow.webContents.isLoading(),
        title: browserWindow.title,
      }
    })

    expect(isMinimized).toBe(false)
    expect(isDevToolsOpened).toBe(false)
    expect(isEnabled).toBe(true)
    expect(width).toBeGreaterThan(0)
    expect(height).toBeGreaterThan(0)
    expect(isLoading).toBe(false)
    expect(title).toBe('Private App Name')

    const page = await playwright.getMainPage()
    expect(await page.title()).toBe('Private App Name')
    expect(await page.$('#app')).not.toBeNull()

Maybe the issue is solved in the browser playwright? if so maybe releasing a new version can solve the issue

Himani33 commented 2 years ago

I have this same issue in my Electron app tested with playwright. In our project when we have added native-dependency to register SIP services in the app before login the app started dying prematurely on Windows OS. I feel it's the same issue what's described above. Solution to this would be highly appreciated. Thanks

utf94 commented 2 years ago

is it resolved ?

amiralam0 commented 1 year ago

any fix?

pavelfeldman commented 11 months ago

Why was this issue closed?

Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.

Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.