Ok, so I am wondering how I can get my driver/browser sessions to properly exit if a test is aborted via jenkins. Locally, if I run my tests and abort them, the browser will quit properly. Via jenkins however, this does not happen. If I abort the job during the test phase where my tests are running on the selenium grid, the browser stays open - causing the node to still show up as being used because it did not pick up that the aborted job should have killed its browser session.
I have been messing around with cucumber hooks, but the more I think about it I am not sure if I can handle this with a hook since when ran locally this behavior does not happen. I am now thinking this needs to be either a setting on the selenium grid or jenkins.
My most optimal solution would be to use a hook like the one below that could tell if it was being run remotely and kill the session if aborted/passed/failed. But if there is any solution via jenkins or the selenium grid settings that would be great too! Thank you!
this.registerHandler('After', function (event, done) {
// Some code to clear browser session
done();
});
I dont think you need to do anything extra here at your client code.
The selenium Grid specifically has three parameters that are meant for these sort of cleanups.
-browserTimeout
in seconds : number of seconds a browser session is allowed to hang while a WebDriver command is running (example: driver.get(url)). If the timeout is reached while a WebDriver command is still processing, the session will quit. Minimum value is 60. An unspecified, zero, or negative value means wait indefinitely. Default: 0
-cleanUpCycle
in milliseconds : specifies how often the hub will poll running proxies for timed-out (i.e. hung) threads. Must also specify timeout
option.Default: 5000
(5 seconds)
-timeout
, -sessionTimeout
in seconds : Specifies the timeout before the server automatically kills a session that hasn't had any activity in the last X seconds. The test slot will then be released for another test to use. This is typically used to take care of client crashes. For grid hub/node roles, cleanUpCycle must also be set. Default: 1800
Using a combination of all the above 3 parameters, you can configure your node to automatically close orphaned browser instances and sessions.
This documentation is available within the selenium uber jar itself as command line documentation. You can refer to this SO answer to learn how to get it and see what other options are available.
There's some additional documentation related to timeouts
on the Grid'2 wiki page here.
Hope that helps!
That is basically the same as wanting to do something after your abort execution locally, jenkins knows nothing about your grid it only builds code.
Consider having separate job that would be executed based on the results of execution of previous one, in it you could clean your env by killing stucked processes and maybe re-launching grid itself.