spectron icon indicating copy to clipboard operation
spectron copied to clipboard

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

Open remss opened this issue 9 years ago • 4 comments
trafficstars

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

remss avatar May 31 '16 08:05 remss

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();
  });

sroberts avatar Mar 18 '17 14:03 sroberts

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

mbaer3000 avatar May 29 '18 09:05 mbaer3000

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

mankeheaven avatar Apr 30 '19 02:04 mankeheaven

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());
    }
  });

snake-py avatar Jan 25 '21 20:01 snake-py