Application.InitalizeClient fails to complete
See original GitHub issueWhat I’m trying to do
I’m trying to run a basic test with Jest. I have two basic helpers that make the electron path and make the application:
function getElectronPath() {
let electronPath = path.join(
__dirname,
"..",
"node_modules",
".bin",
"electron"
);
if (process.platform === "win32") {
electronPath += ".cmd";
}
return electronPath;
}
function getApplication(buildPath) {
const options = {};
options.path = getElectronPath();
options.args = [buildPath];
if (process.env.CI) {
options.startTimeout = 30000;
}
return new Application(options);
}
Then, I have a really simple test that opens up the electron app then counts how many windows there are:
import { getApplication } from "./helper.js";
import path from "path";
describe("Aurora", () => {
let app;
beforeEach(() => {
const BUILD_PATH = path.resolve(__dirname, "..");
app = getApplication(BUILD_PATH);
return app.start();
});
afterEach(() => {
if (app && app.isRunning()) {
return app.stop();
}
});
test("It shows initial window", () => {
return app.client.waitUntilWindowLoaded().getWindowCount().then(count => {
expect(count).toBe(1);
});
});
});
The Problem
When I try to run this, I’ll get an error that says that the promise on app.start()
in the beforeEach()
call failed to complete:
Aurora › It shows initial window
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:523:19)
at ontimeout (timers.js:488:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:283:5)
What I’ve tried so far.
1. Logging Application.prototype.start()
Inside my node_modules/spectron/lib/application.js
file, I put a few console.log
’s in the Application.prototype.start
call like so:
Application.prototype.start = function () {
var self = this
return self.exists()
.then(function () { console.log("start chrome"); return self.startChromeDriver() })
.then(function () { console.log("create client"); return self.createClient() })
.then(function () { console.log("api init"); return self.api.initialize() })
.then(function () { console.log("timeouts"); return self.client.timeouts('script', self.waitTimeout) })
.then(function () { console.log("running"); self.running = true })
.then(function () { console.log("return'd"); return self })
}
That printed out only:
start chrome
create client
So I know that it’s never getting to the self.api.initialize()
call. Which means the problem is in createClient
2. Checking createClient
Since createClient
doesn’t seem to have any promise calls until the end, I figured most of that must be executing. So to prove that, I put a console.log
in the start of initializeClient
to prove that we were at least getting there:
Application.prototype.initializeClient = function(resolve, reject) {
console.log("initializeClient gets called");
var maxTries = 10;
var tries = 0;
// ...
};
Sure enough, I’ll get a message that says initializeClient gets called
.
3. Checking initializeClient
Inside of initializeClient
there’s an init
function that calls WebdriverIO’s client.init
function:
self.client.init().then(resolve, function(error)
To see where this was going, I checked to see if the function was being called and if it errorred:
var init = function() {
console.log("Starting an init function!");
tries++;
self.client.init().then(resolve, function(error) {
console.log("There is an error in init!!");
if (tries >= maxTries) {
error.message =
"Client initialization failed after " + tries + " attempts: ";
error.message += error.type + " " + error.message;
reject(error);
} else {
global.setTimeout(init, 250);
}
});
};
I got a Starting an init function
but no There is an error in init!!
so I can assume that client.init
got stuck somewhere.
4. Getting lost in WebdriverIO
So I went to go read webdriver’s client.init
code and I got a little lost here. It seems like /session
call must have gotten lost somewhere.
return this.requestHandler.create({
path: '/session',
method: 'POST'
}, {
desiredCapabilities: this.desiredCapabilities
})
But if it had some error, wouldn’t it log it or throw it somehow? Isn’t this supposed to be running locally too? So there shouldn’t be latency. I’m not completely sure what’s up.
Main Questions
Has anyone ever experienced anything like this? Does it have something to do with running on Jest? Have I made some simple mistake early on?
- Thanks in advance ❤️
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:10
Top GitHub Comments
@kontrollanten Thank you very much – I’ll try that out now.
I stumbled across this issue in my search for a solution to a similar problem. I’m unclear if other people on this issue were having their Electron app start up or not, but I was so none of the suggestions seemed applicable as Spectron clearly had the right Electron path and the app was not throwing an error during boot.
I eventually tracked the problem down to this issue in the Electron repository. All I needed to fix it was to pass the
--remote-debugging-port=12209
argument as part of thechromeDriverArgs
and it started working fine.Hope this saves someone else the day I lost hunting this down 😬