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

1

7

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.

Mer answered 31/3, 2019 at 7:59 Comment(4)
What is the usecase for timeout to be of 7 hrs?Leatherleaf
hey @demouser123, the browsers have to be ready to respond to notifications from another part of the system and sometimes notifications don't happen for a while. Do you know how to modify the timeout or were you just curious?Mer
Why not just create a script that opens the browser, checks for something to do, and closes. Then just launch that script every 15 mins (or whatever) indefinitely. That way you don't have to leave a browser open for an extended period of time and refresh the page repeatedly.Scoria
The browsers have to act on notifications very quickly, spinning up a browser whenever there is a notification would sadly take too much time to be feasible. I'm really just looking for a way to increase selenium's timeout time, cheers for the suggestion though.Mer
J
9

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
Jampan answered 3/4, 2019 at 13:24 Comment(2)
DebianJanB you beautiful beautiful man thank you so much, this solves my problem.Mer
I have run into the same issue, I am running my application on docker is there a way to set the sessionTimeout via docker-compose?Litton

© 2022 - 2024 — McMap. All rights reserved.