seleniumselenium-webdriverwebdriverselenium-gridselenium-remotedriver

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.


Solution

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

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

    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