Yann Lelong Yann Lelong - 4 days ago 7
AngularJS Question

Using Protractor in Electron

I am trying to set up unit tests and e2e tests for an application I have running with Electron using Protractor. I've been refering to many different posts (this one did help), but I still get an error I don't understand :

Message:
Error while waiting for Protractor to sync with the page: "angular could not be found on the window"
Stacktrace:
undefined


My conf.js file looks like this:

exports.config = {
directConnect : true,
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl:"file://home/me/workspace/testing-project/main.js",
capabilities: {
browserName: "chrome",
chromeOptions: {
binary: "/home/me/.linuxbrew/lib/node_modules/electron-prebuilt/dist/electron",
args: ["--test-type=webdriver"]
}
},
specs: ['todo-specs.js'],
onPrepare: function(){
browser.resetUrl = "file://";
browser.driver.get("file://");
}
};


Considering the documentation given on the Protractor website, I am under the impression that I don't need to install anything else (Jasmine for example).

What surprises me is that even though the path to the main.js (that starts the application accordingly to Electron's specifications) is correct, I can't see anything in the Electron window that pops up.

Did any of you encountered this issue? Did you manage to resolve it?

Answer

Apparently, using the electron binary is not enough to actually launch your application. However, by building the binary for your application and linking it into your conf.js file works.
I have been able to reduce my file to this:
conf.js

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['test-spec.js'],
    capabilities: {
        browserName: "chrome",
        chromeOptions: {
            binary: "./dist/myAwesomeApp/myAwesomeAppBinary"
        }
    },
    onPrepare: function () {
        browser.resetUrl = "file://";
    }
};

By doing it this way, there is no need to describe a baseUrl or to use browser.get() nor browser.driver.get() to start the app in Electron.
However, I would have preferred not to have to build the app binary, but I don't think it is possible for now.

Comments