DevExpress / testcafe-browser-provider-electron

This is the Electron browser provider plugin for TestCafe.
https://testcafe.io
MIT License
49 stars 30 forks source link

Support electron v8 #64

Closed mrfelton closed 3 years ago

mrfelton commented 4 years ago

Doesn't seem to work with electron v8. It's not able to properly start the app.

ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.

Here is the full output of the test run. Note this same setup works under electron v7.

$ cross-env DEBUG=testcafe* DISABLE_INIT=1 ELECTRON_USER_DIR_TEMP=1 testcafe --selector-timeout 60000 --assertion-timeout 60000 --screenshots ./screenshots --screenshots-on-fails electron:'./' ./test/e2e
⠸
  testcafe:browser-provider-electron:spawn:stderr Debugger listening on ws://127.0.0.1:58717/d506d6be-ff37-4ce9-b458-d7b11a9f1b45
  testcafe:browser-provider-electron:spawn:stderr For help, see: https://nodejs.org/en/docs/inspector +0ms
⠼
  testcafe:browser-provider-electron:spawn:stderr Debugger listening on ws://127.0.0.1:58717/d506d6be-ff37-4ce9-b458-d7b11a9f1b45
⠏
  testcafe:browser-provider-electron:spawn:stderr (electron) The default value of app.allowRendererProcessReuse is deprecated, it is currently "false".  It will change to be "true" in Electron 9.  For more information please check https://github.com/electron/electron/issues/18397 +766ms
  testcafe:browser-provider-electron:spawn:stderr (node:40491) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emit' of null
  testcafe:browser-provider-electron:spawn:stderr     at Client.sendInjectingStatus (/Users/tom/workspace/zap-desktop/node_modules/testcafe-browser-provider-electron/lib/ipc.js:498:25)
  testcafe:browser-provider-electron:spawn:stderr     at WebContents.loadURL (/Users/tom/workspace/zap-desktop/node_modules/testcafe-browser-provider-electron/lib/injectable/electron-mocks.js:110:17)
  testcafe:browser-provider-electron:spawn:stderr     at BrowserWindow.loadURL (electron/js2c/browser_init.js:635:29)
  testcafe:browser-provider-electron:spawn:stderr     at ZapController.init (/Users/tom/workspace/zap-desktop/dist/main.js:5805:25)
  testcafe:browser-provider-electron:spawn:stderr     at App.<anonymous> (/Users/tom/workspace/zap-desktop/dist/main.js:9116:7)
  testcafe:browser-provider-electron:spawn:stderr     at App.emit (events.js:215:7) +33ms
  testcafe:browser-provider-electron:spawn:stderr (node:40491) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emit' of null
  testcafe:browser-provider-electron:spawn:stderr     at Client.sendInjectingStatus (/Users/tom/workspace/zap-desktop/node_modules/testcafe-browser-provider-electron/lib/ipc.js:498:25)
  testcafe:browser-provider-electron:spawn:stderr     at WebContents.loadURL (/Users/tom/workspace/zap-desktop/node_modules/testcafe-browser-provider-electron/lib/injectable/electron-mocks.js:110:17)
  testcafe:browser-provider-electron:spawn:stderr     at BrowserWindow.loadURL (electron/js2c/browser_init.js:635:29)
  testcafe:browser-provider-electron:spawn:stderr     at ZapController.init (/Users/tom/workspace/zap-desktop/dist/main.js:5805:25)
  testcafe:browser-provider-electron:spawn:stderr     at App.<anonymous> (/Users/tom/workspace/zap-desktop/dist/main.js:9116:7)
  testcafe:browser-provider-electron:spawn:stderr     at App.emit (events.js:215:7)
  testcafe:browser-provider-electron:spawn:stderr (node:40491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
  testcafe:browser-provider-electron:spawn:stderr (node:40491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
  testcafe:browser-provider-electron:spawn:stderr (node:40491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  testcafe:browser-provider-electron:spawn:stderr (node:40491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.

Type "testcafe -h" for help.
error Command failed with exit code 1.
Farfurix commented 4 years ago

@mrfelton

Hello,

Thank you for reaching us. We will examine the possibility of adding the latest Electron version.

mrfelton commented 4 years ago

The issue seems to be related to this code:

https://github.com/DevExpress/testcafe-browser-provider-electron/blob/f4d0074dba647e138ea91a721fc45eb2e580b0f1/src/ipc.js#L199-L201

When called from here:

https://github.com/DevExpress/testcafe-browser-provider-electron/blob/c2c074359c1a9b030fa39a3e9d5a9bfe40afa136/src/injectable/electron-mocks.js#L98

At the point this.client seems to be null.

LavrovArtem commented 4 years ago

Thank you for the research. This information was very helpful for us.

veado commented 4 years ago

@LavrovArtem May I ask you if there any updates to support Electron 8.x ?

LavrovArtem commented 4 years ago

We have not established any exact dates yet. Any personal estimate may be misleading, so I cannot currently tell you the precise date.

steveetm commented 4 years ago

@veado created a PR, you can check it with my fork if you clone it and build with gulp then yarn add PathToLocallyClonedFork

Dmitry-Ostashev commented 4 years ago

@steveetm Thank you for your PR, we'll review it soon.

lukechu10 commented 4 years ago

Hello, does this work with electron v9?

mrfelton commented 4 years ago

In my testing @lukechu10 it does work sometimes, but sometimes it leaves the window open indefinitely at the end of the test run which makes it impossible to use on a CI environment.

p.s. if you want a version of this that works with Electron 8.x you can use http://npmjs.com/@ln-zap/testcafe-browser-provider-electron which I created that includes the fix from https://github.com/DevExpress/testcafe-browser-provider-electron/pull/65 which has been merged here but not yet included in a new release.

Dmitry-Ostashev commented 4 years ago

@lukechu10 Currently, we don't have news about Electron v9 support.

jakerobb commented 4 years ago

I see that @steveetm's PR was merged back in May. Any plans to cut a release with that change?

I also see that @mrfelton made a fork with the fix, but I'm a bit of a Node noob, and I guess I don't know how to include it. I tried npm install @ln-zap/testcafe-browser-provider-electron. When that didn't work, I reverted my changes and tried changing my devDependencies in package.json from:

"testcafe-browser-provider-electron": "0.0.14",

to

"@ln-zap/testcafe-browser-provider-electron": "0.0.15-alpha.3",

and running npm install, which did pretty much the same thing. Same result in both cases: no complaints from npm, but now testcafe doesn't know about the "electron" browser at all:

$ testcafe                                        
ERROR Unable to find the browser. "electron:." is not a browser alias or path to an executable file.

Type "testcafe -h" for help.
$ testcafe -b electron
ERROR The specified "electron" browser provider was not found.

Type "testcafe -h" for help.
$

I got the same results against Electron v8.1.1 (the version I was already using), 8.2.3 (the version specified by package.json in #65), and 8.3.4 (latest 8.x).

Am I doing something wrong? Are there troubleshooting steps I can take? I'm currently scouring testcafe's source code, trying to learn how it discovers browser provider plugins.

jakerobb commented 4 years ago

I've now determined that the problem is the forked module name, combined with TestCafe's rigorous naming scheme for browser-provider plugins.

To load the plugin, TestCafe (browser/provider/pool.js::_getProviderModule) takes the passed-in module name electron and appends it to "testcafe-browser-provider-", then passes that to require(...). That attempts to load the regular, non-forked plugin, which I don't have installed.

I need it to call require("@ln-zap/testcafe-browser-provider-electron"). As such, I needed to specify that full string as the browser name in my .testcaferc.json file (or on the command line, if you're specifying the browser there). To anyone else trying to use @steveetm's fork, that's the trick!

Farfurix commented 4 years ago

@jakerobb

Hello,

I published a new version: v0.0.15.

In the case of any custom fork, you can use a specific scope of the installed electron provider module.

  "dependencies": {
    "@ln-zap/testcafe-browser-provider-electron": "0.0.15-alpha.3",

Command:

"test": "testcafe \"@ln-zap/electron:./\" ./test/test.js"

Test imports:

import { setElectronDialogHandler } from '@ln-zap/testcafe-browser-provider-electron';

Or, you can simply install the @ln-zap/testcafe-browser-provider-electron module under the testcafe-browser-provider-electron alias:

npm i testcafe-browser-provider-electron@npm:@ln-zap/testcafe-browser-provider-electron

In this case, you don't need to use any scope in your commands and imports.

tarjei commented 3 years ago

Any news on when the 0.0.15 release will be done?

Farfurix commented 3 years ago

@tarjei

Hello,

I fixed the GitHub Electron provider version. Anyway, you can install the testcafe-browser-provider-electron@0.0.15 version from npm.

trungutt commented 3 years ago

I have my app with electron@10.1.5 and testcafe-browser-provider-electron@0.0.15. I think we should close this issue

Farfurix commented 3 years ago

@trungutt

Hello,

Yes. Since we merged these changes, we can close it.

If anyone encounters issues with Electron 8, please feel free to open a new bug report.