electron-userland / spectron

DEPRECATED: 🔎 Test Electron apps using ChromeDriver
http://electronjs.org/spectron
MIT License
1.68k stars 228 forks source link

The app.stop() do not fail when the electron app canceled the quit with a beforeunload #50

Open remss opened 8 years ago

remss commented 8 years ago

If the electron app has a beforeunload that cancel the app quit like this

// index.html
window.onbeforeunload = function(e) {
  console.log('app quit canceled')
  return false
};

Then try to close the spectron app

// test.js
if (this.app && this.app.isRunning()) {
    return this.app.stop().then(function() {
        console.log('stopped')
    })
}

The output is "stopped" even if app is still running. The expected behaviour is the this.app.stop() promise rejects

Electron 1.1.1 Spectron 3.1.1

sroberts commented 7 years ago

I'm running into this as well. Now I'm very very new to Spectron, but it's unexpected behavior.

  after(function (done) {
      done();
      console.log("Fin")
      return app.stop();
  });
mbaer3000 commented 6 years ago

I have the same problem. Resolved it by doing return app.client.url('about:blank').then(() => app.stop());

mankeheaven commented 5 years ago

thanks for @mbaer3000 .your solution works for me now I‘m looking for a headless solution that would not see a client

snake-py commented 3 years ago

I am still having this. My tests are passing and the window stays open. I tried the workaround this did not do the trick.

  afterEach(() => {
    if (app && app.isRunning()) {
      return app.client.url('about:blank').then(() => app.stop());
    }
  });