electron-userland / spectron

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

app.quit() is not noticed #131

Open wojtkowiak opened 8 years ago

wojtkowiak commented 8 years ago

Testing if my app is quitting correctly :smile: After app.quit t.context.app.isRunning() still reports true. https://github.com/electron/spectron/blob/aaf7b6964ed32f43c0955b0cb1af5eeb99938db0/lib/application.js#L86 t.context.app.stop() will fail with Error: chrome not reachable. Manually doing t.context.app.running = false; fixes it. Not sure if this should be handled but maybe a note in the readme would be useful. I am leaving it to your judgment ;)

taboca commented 8 years ago

I noticed a quit trouble with my case of a browser-kyosk project. It happened after about 300 executions. I am using Linux, Ubuntu 14+ with:

"electron-prebuilt": "^1.3.8",
"spectron": "~3.4.0"

My case uses a a browser launcher script to launch and quit, first. When the script ends, an external (Forever daemon) system notices, and then it runs the node script again. Therefore, I have a sort of infinite testing cycle, which is by design. In this case it's a plain code (not using Mocha, etc) - the following source is the core of it aside from the external synchronous loop system.

From a visual perspective, it got stuck, with the browser window open. When I killed, then I noticed another was there. So prior to get stuck, I believe that a twice were shown somehow. Looking in logs, all of the iterations showed a proper "Quit" output. I would think that it was Forever that caused the trouble but since the browser is open, I then thought about this report here.


var app = new Application({
        path: electron, args:['.']
})

console.log('node version: ' + process.version);

app.start().then(function ok() {
                app.client.waitUntilTextExists('#message', 'success', 10000).then(
                        function success() {
                                console.log('Success, content loaded!!!');

                                app.stop().then(function ok() {
                                        console.log('Quit ')
                                }, function nok() {
                                        console.log('not quit properly!');
                                });

                        }, function nok() {
                                console.log("Not loaded...");

                                app.stop().then(function ok() {
                                        console.log('Quit ')
                                }, function nok() {
                                        console.log("not quit really");
                                });

                        });
}, function nok() {
        console.log('Start not ok!')
});
taboca commented 8 years ago

I wonder if the chromedriver could be a reason here - mainly because I found this http://stackoverflow.com/questions/34563724/how-to-make-sure-only-single-chromedriver-exe-instance-is-running-in-background. And then it would be interesting to know exactly if spectron truly have full control over the chromedriver instance.

zeke commented 8 years ago

It looks like there's a one-second delay before the value of this.running is changed:

https://github.com/electron/spectron/blob/aaf7b6964ed32f43c0955b0cb1af5eeb99938db0/lib/application.js#L60-L66

https://github.com/electron/spectron/blob/aaf7b6964ed32f43c0955b0cb1af5eeb99938db0/lib/application.js#L14

MoonTahoe commented 7 years ago

I am having the same problem. I have some tests that are checking to make sure the app quits when all windows have closed. app.isRunning() and app.running still remain true after the app quits.

I hacked out a work around by executing the pgrep command for the time being, but it will not work in windows, and it is not as nice as having app.isRunning() working:


    exec('pgrep <APPNAME>', (err, stdout) => {
        if (err) {
           // pgrep command did not work
           // electron app is not running
        } else {
          // pgrep found some processes associated with <APPNAME>
          // electron app is still running
       }
    })
alexan commented 3 years ago

is there any new solution for this problem. I can not get a test working, to check if the application has quit()

evertonlperes commented 3 years ago

Having the same issue and seems app.stop() or app.quit() does not close the app at all :(