2

I used selenium RemoteWebdriver to connection to remote hubs.

options = webdriver.ChromeOptions()
options.add_argument("window-size=1920,1080")
options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36")
driver = webdriver.Remote('http://127.0.0.1:4444/wh/hub', desired_capabilities=options.to_capabilities())
driver.get('https://example.com')

If there are no activities for some times, the session would be auto closed.

>>> driver.title
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 342, in title
    resp = self.execute(Command.GET_TITLE)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: No active session with ID 227c970ff0d633fce0e68c57c40e70b7

Here is the log in container of selenium/standalone-chrome-debug:3.141.59-mercury:

chrome_1_9da7c6574f3b | 04:27:09.199 INFO [ActiveSessionFactory.apply] - Capabilities are: {
chrome_1_9da7c6574f3b |   "browserName": "chrome",
chrome_1_9da7c6574f3b |   "goog:chromeOptions": {
chrome_1_9da7c6574f3b |     "extensions": [
chrome_1_9da7c6574f3b |     ],
chrome_1_9da7c6574f3b |     "args": [
chrome_1_9da7c6574f3b |       "window-size=1920,1080",
chrome_1_9da7c6574f3b |       "user-agent=Mozilla\u002f5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit\u002f537.36 (KHTML, like Gecko) Chrome\u002f73.0.3683.86 Safari\u002f537.36"
chrome_1_9da7c6574f3b |     ]
chrome_1_9da7c6574f3b |   },
chrome_1_9da7c6574f3b |   "version": ""
chrome_1_9da7c6574f3b | }
chrome_1_9da7c6574f3b | 04:27:09.200 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
chrome_1_9da7c6574f3b | Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 15565
chrome_1_9da7c6574f3b | Only local connections are allowed.
chrome_1_9da7c6574f3b | Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
chrome_1_9da7c6574f3b | 04:27:09.809 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
chrome_1_9da7c6574f3b | 04:27:09.822 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 227c970ff0d633fce0e68c57c40e70b7 (org.openqa.selenium.chrome.ChromeDriverService)

----: No activities here:-----


chrome_1_9da7c6574f3b | 04:59:04.125 INFO [ActiveSessions$1.onStop] - Removing session 227c970ff0d633fce0e68c57c40e70b7 (org.openqa.selenium.chrome.ChromeDriverService)

So I guess the chrome driver will auto closed the no-activity session in 30 minutes. I want to know how I can disable the auto-closed action with no activity?

michael
  • 744
  • 7
  • 15

1 Answers1

2

I have found the clue from code here

-sessionTimeout

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. If a node does not specify it, the hub value will be used.

The timeout is indeed 1800s, it is the same the log expected.

And then I found another question about this.

java -jar /opt/selenium/selenium-server-standalone.jar -sessionTimeout 31536000

I am not familiar with java. I used selenium/standalone-chrome-debug:3.141.59-mercury docker image to run the chromdriver. So if you also use docker, you can set env when running docker.

This is my docker-compose file:

chrome:
  image: selenium/standalone-chrome-debug:3.141.59-mercury
  volumes:
    - /dev/shm:/dev/shm
  ports:
    - 127.0.0.1:4444:4444
    - 127.0.0.1:5900:5900
  environment:
     - SE_OPTS=-sessionTimeout 31536000

It is about one year timeout.

Community
  • 1
  • 1
michael
  • 744
  • 7
  • 15