selenium-gridselenium-grid2

How to terminate session in Selenium Grid(Extras)


How to terminate session in Selenium Grid? My problem is that if my test fail hub still keep session for this test and I can't run another test (it run but fail because can't get free node, because it is registered in hub). I have found this How to kill thread in a Selenium Grid node and there is an answer to use DELETE /session/:sessionId but it didn't work for me. Documentation on Selenium Grid or Extras is very pure, maybe some one have similar issue and know how to resole it?


Solution

  • The hub never denies a new session request because a slot is not available. The new session ends up in the Grid's queue.

    You would need to take a look at your code to check why is driver.quit() not being called all the time (irrespective of why a test fails).

    Sometimes your client may crash (For e.g., the JVM where your test cases run may crash, or you may hit the stop button in your IDE to kill your tests. In those circumstances, you end up creating orphaned sessions.

    But the Grid has mechanisms for clearing them up as well via properties that you can specify to the Grid when bringing it up.

    The selenium Grid specifically has three parameters that are meant for these sort of cleanups.

    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.

    For more information refer to my comments in the stackoverflow post : Selenium driver instance persists if test is aborted on Jenkins