Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app not launching when starting testcafe #25

Closed
euZebe opened this issue Jul 19, 2018 · 6 comments
Closed

app not launching when starting testcafe #25

euZebe opened this issue Jul 19, 2018 · 6 comments

Comments

@euZebe
Copy link
Contributor

euZebe commented Jul 19, 2018

I'm not sure where the problem comes from (well, rather from my own code, ok...).
I am trying to add e2e tests to an existing electron app. I followed the steps:

  • install testcafe-browser-provider-electron
  • create a .testcafe-electron-rc
    (electron is already installed. I guess I don't have to use the latest version)
  • launch testcafe "electron:/absolute/path/to/projet/root" "<tests_directory>/**/*.js"

doing so, electron starts but I get the following message:

To run a local app, execute the following on the command line:
node_modules/electron/dist/electron path-to-app

in the console, once testcafe ends, I get

ERROR Was unable to open the browser "electron:/absolute/path/to/projet/root" due to error.
Error: The main window page at file:///absolute/path/to/projet/root/index.html was not loaded.
Use the mainWindowUrl option to specify one of the following pages as the main window page:
file:///absolute/path/to/projet/root/node_modules/electron/dist/resources/default_app.asar/index.html

I checked ; the file defined at /absolute/path/to/projet/root/index.html exists. Any idea what I did wrong ?

@AndreyBelym
Copy link
Contributor

AndreyBelym commented Jul 20, 2018

Hi @euZebe! The appPath option description in the Getting Started section is quite misleading. You should use it because otherwise you will have to copy your project into the $ELECTRON_PATH/resources/app directory.

appPath
Alters path to the application, which, by default, must be located at the default Electron app directory.
You can use the appPath option to override the default path by specifying a new absolute path. Alternatively, you can append a relative path to the path specified after the "electron:" prefix.

If you've placed your .testcafe-electron-rc in the same directory with your package.json, it's enough to use './' as a value for the appPath.

{
    "mainWindowUrl": "...",
    "appPath": "./"
}

@euZebe
Copy link
Contributor Author

euZebe commented Jul 26, 2018

@AndreyBelym So the path behind electron: in the command is the path to the .testcafe-electron-rc file (which could be '.'), and appPath is the path of the electron app (which could also be '.').

Why am I wrong when launching testcafe with $(npm bin)/testcafe "electron:." "test/**/*.spec.js"?

ERROR Was unable to open the browser "electron:" due to error.
Error: Cannot find module '/absolute/path/to/projet/root'

@sijosyn
Copy link

sijosyn commented Nov 4, 2018

@euZebe Check this stackoverflow answer - https://stackoverflow.com/a/44723909/6353963 . If you add main field in package.json file, it will not throw the module not found error.

This error can be encountered if you are requireing a module that has a missing or incorrect main field in its package.json. Though the module itself is installed, npm/node has to use a single .js file as an entrypoint to your module. If the main field is not there, it defaults to looking for index.js in your module's folder. If your module's main file is not called index.js, it won't be able to require it.

@DanKaplanSES
Copy link

DanKaplanSES commented Mar 11, 2020

If you've placed your .testcafe-electron-rc in the same directory with your package.json, it's enough to use './' as a value for the appPath.

I was having the same issue as the original post, but after following this advice, electron starts up with a blank page. This seems like a step in the right direction.

What is mainWindowUrl supposed to refer to? I've pointed it at an index.html file pre-and post web pack, but either way, a blank page is loaded.

Here is my error:

Using locally installed version of TestCafe.
ERROR Was unable to open the browser "electron:" due to error.

Error: The main window page at file:///C:/IdeaProjects/project/.webpack/renderer/main_window/index.html was not loaded.
Use the mainWindowUrl option to specify one of the following pages as the main window page:

http://localhost:3000/main_window

@miherlosev
Copy link
Contributor

Hi @tieTYT

The mainWindowUrl parameter should contains a URL that was specified for the Window.openURL
method in your application. According to the error message, you need to specify the http://localhost:3000/main_window value for the mainWindowURL parameter.

@no-response
Copy link

no-response bot commented Jun 5, 2020

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.

@no-response no-response bot closed this as completed Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants