Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way too prevent selenium automatically terminating idle sessions?

I am using selenium for automating some interactions with websites. This process involves opening several browsers and having them perform actions intermittently. However, occasionally there are long (> 1 hour) periods of inaction, and selenium seems to automatically kill browser sessions after ~30 minutes of not being called.

I would like to set this timeout to 7 hours or so, but I cannot find any way of doing this.

This is the message selenium sends as it helpfully closes an idle browser.

13:06:35.277 INFO [ActiveSessions$1.onStop] - Removing session 70a1b8cbae6876cde7e66df13b3942d1 (org.openqa.selenium.chrome.ChromeDriverService)

If Anyone has any leads I would be super grateful. At the moment I'm just auto-refreshing browsers every 15 minutes to prevent timeouts but it feels gross.

like image 306
Lewington Avatar asked Mar 31 '19 07:03

Lewington


People also ask

How does Selenium Webdriver handle session timeout?

If Current time - Test start time >= 30 minute s then check if system logout and if yes then login again. but for this question is same like I have to call it in either every method or in some specific methods to check every time if logout or not.

What is the default timeout for 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.

Can we use Selenium to work with an already open browser session?

To start the selenium test on the existing or already opened window we need to use Chrome DevTools Protocol.


1 Answers

This error message...

INFO [ActiveSessions$1.onStop] - Removing session 70a1b8cbae6876cde7e66df13b3942d1 (org.openqa.selenium.chrome.ChromeDriverService)

...implies that the already initiated/spawned a new Chrome Browser Session was terminated.

This issue is observed with Selenium Grid Hub/Node configuration and/or RemoteWebdriver implementation.

If you observe the -help of selenium-server-standalone-x.y.z.jar the default -timeout / -sessionTimeout is set to 1800 seconds.

  • CLI Command:

    $>java -jar selenium-server-standalone-3.14.0.jar -help
    
  • Output:

-timeout, -sessionTimeout: <Integer> 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 value: 1800

  • Snapshot:

timeout

Hence, you see the time out and it appears selenium automatically kills the browser session after ~30 minutes of not being called.


Solution

You can increase the -timeout / -sessionTimeout as follows:

$>java -jar /path/to/selenium-server-standalone-3.14.0.jar -sessionTimeout 57868143
like image 175
undetected Selenium Avatar answered Oct 22 '22 13:10

undetected Selenium