Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 973
slovvic Avatar asked Aug 09 '17 13:08

slovvic


People also ask

How do I stop Selenium grid node?

Your Grid server will up and running till the time command prompt window is opened, if you close it, that will also stop the selenium server. Selenium Grid, by default uses port 4444 for its web interface. To start the same on other port, use this command: java -jar selenium-server-standalone-3.3.

What is Selenium Grid extras?

Selenium Grid Extras is a project that helps you set up and manage your local Selenium Grid. Typical instances of the Grid consists of the HUB and Nodes. The HUB is responsible for managing test sessions and assigning new session idle nodes.

What is timeout in Selenium grid?

-timeout 30 (300 is default) The timeout in seconds before the hub automatically releases a node that hasn't received any requests for more than the specified number of seconds. After this time, the node will be released for another test in the queue. This helps to clear client crashes without manual intervention.

How do I disable Selenium server on localhost 4444?

According to this answer you can also hit a URL ( http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer ) at the end of your test to shutdown the Selenium server.


1 Answers

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.

  • -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.

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

like image 110
Krishnan Mahadevan Avatar answered Sep 21 '22 10:09

Krishnan Mahadevan