question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Application.InitalizeClient fails to complete

See original GitHub issue

What 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:open
  • Created 6 years ago
  • Reactions:7
  • Comments:10

github_iconTop GitHub Comments

1reaction
ericyahhhcommented, Jun 7, 2019

@kontrollanten Thank you very much – I’ll try that out now.

0reactions
UberMousecommented, May 21, 2020

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 the chromeDriverArgs and it started working fine.

Hope this saves someone else the day I lost hunting this down 😬

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to initialize client contex… | Apple Developer Forums
This is preventing us from using 'axios' in order to sign into our application. Is there a solution to this issue? What are...
Read more >
Help Error: Application failed to initialize properly (0xc0150004)
You can try and uninstall the most current .Net Framework and then go to Windows Update and download the latest version and install...
Read more >
Application failed initialize properly - Intel
You may get this error message when launching the Quartus® II Programmer Only software ... To resolve this issue, perform one of the...
Read more >
Failure to Initialize Gateway Error 5279
This error indicates a communication failure between client and server. This article provides a general outline for addressing the potential ...
Read more >
Task Failed - Activating language client HtmlLanguageClient
[severity:It's more difficult to complete my work] Unhandled Exception: Microsoft.VisualStudio.Composition.CompositionFailedException: Expected 1 export(s) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found