0

My selenium tests run fine with local webdriver but fail when running against remote webdriver i.e. running against selenium grid built from SeleniumHQ docker images

The tests are written in python and the selenium pip package I'm using is selenium==3.3.1

try:
  driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    desired_capabilities=DesiredCapabilities.CHROME, #TODO also support windowSize, implicitWait - how?
  )
  #some other test logic goes here

finally:
  driver.quit() #this command raises error

The question is why the .quit() gets error (sometimes it passes, sometimes it fails), and especially when running multiple asynchronous tests? And how we work around with it?

p.s.

The full exception trace

Traceback (most recent call last):   File "/usr/local/lib/python2.7/dist-packages/proboscis/case.py", line 296, in testng_method_mistake_capture_func
    compatability.capture_type_error(s_func)   File "/usr/local/lib/python2.7/dist-packages/proboscis/compatability/exceptions_2_6.py", line 27, in capture_type_error
    func()   File "/home/namgivu/NN/code/automation_testing/test_vault/aos_web/test990101c_checkOrder.py", line 15, in test_orderStatus
    pom.testOrderStatus()   File "/home/namgivu/NN/code/automation_testing/pom/aos_web/chrome.py", line 759, in testOrderStatus
    driver.quit()   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 522, in quit
    self.execute(Command.QUIT)   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
    self.error_handler.check_response(response)   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace) WebDriverException: Message: Session [686d6045-541d-41f4-b0e2-d23f64d285e1] was terminated due to TIMEOUT Stacktrace:
    at org.openqa.grid.internal.ActiveTestSessions.getExistingSession (ActiveTestSessions.java:105)
    at org.openqa.grid.internal.Registry.getExistingSession (Registry.java:404)
    at org.openqa.grid.web.servlet.handler.RequestHandler.getSession (RequestHandler.java:232)
    at org.openqa.grid.web.servlet.handler.RequestHandler.process (RequestHandler.java:117)
    at org.openqa.grid.web.servlet.DriverServlet.process (DriverServlet.java:83)
    at org.openqa.grid.web.servlet.DriverServlet.doDelete (DriverServlet.java:73)
    at javax.servlet.http.HttpServlet.service (HttpServlet.java:713)
    at javax.servlet.http.HttpServlet.service (HttpServlet.java:790)
    at org.seleniumhq.jetty9.servlet.ServletHolder.handle (ServletHolder.java:841)
    at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle (ServletHandler.java:543)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:188)
    at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle (SessionHandler.java:1584)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:188)
    at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle (ContextHandler.java:1228)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope (ScopedHandler.java:168)
    at org.seleniumhq.jetty9.servlet.ServletHandler.doScope (ServletHandler.java:481)
    at org.seleniumhq.jetty9.server.session.SessionHandler.doScope (SessionHandler.java:1553)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope (ScopedHandler.java:166)
    at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope (ContextHandler.java:1130)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
    at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle (HandlerWrapper.java:132)
    at org.seleniumhq.jetty9.server.Server.handle (Server.java:564)
    at org.seleniumhq.jetty9.server.HttpChannel.handle (HttpChannel.java:320)
    at org.seleniumhq.jetty9.server.HttpConnection.onFillable (HttpConnection.java:251)
    at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:279)
    at org.seleniumhq.jetty9.io.FillInterest.fillable (FillInterest.java:112)
    at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run (ChannelEndPoint.java:124)
    at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:672)
    at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:590)
    at java.lang.Thread.run (Thread.java:748)
-------------------- >> begin captured logging << -------------------- selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session {"requiredCapabilities": {}, "desiredCapabilities": {"platform": "ANY", "browserName": "chrome", "version": "", "javascriptEnabled": true}} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session {"requiredCapabilities": {}, "desiredCapabilities": {"platform": "ANY", "browserName": "chrome", "version": "", "javascriptEnabled": true}} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/url {"url": "http://ec2-54-208-76-28.compute-1.amazonaws.com/smartdesk-sit-to-stand-height-adjustable-standing-desk", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/screenshot {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "css selector", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "button.buy-now.normal"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element/0/displayed {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "id": "0"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element/0/click {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "id": "0"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/screenshot {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h2[text()='Checkout as Guest']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element/1/displayed {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "id": "1"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/screenshot {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "css selector", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": ".checkout-signin > div:nth-of-type(2) input[name=\"email\"]"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element/2/displayed {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "id": "2"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element/2/value {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "id": "2", "value": ["a", "o", "s", ".", "a", "u", "t", "o", "t", "e", "s", "t", ".", "t", "e", "a", "m", "@", "g", "m", "a", "i", "l", ".", "c", "o", "m"]} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/screenshot {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "css selector", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "#guest_submit"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element/3/displayed {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "id": "3"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element/3/click {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "id": "3"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287/element {"using": "xpath", "sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287", "value": "//h4[text()='PAYMENT METHOD']"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: DELETE http://127.0.0.1:4444/wd/hub/session/f56a773d-8069-4f4e-a926-f4ffa127c287 {"sessionId": "f56a773d-8069-4f4e-a926-f4ffa127c287"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session/686d6045-541d-41f4-b0e2-d23f64d285e1/url {"url": "http://ec2-54-208-76-28.compute-1.amazonaws.com/order/status", "sessionId": "686d6045-541d-41f4-b0e2-d23f64d285e1"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: DELETE http://127.0.0.1:4444/wd/hub/session/686d6045-541d-41f4-b0e2-d23f64d285e1 {"sessionId": "686d6045-541d-41f4-b0e2-d23f64d285e1"} selenium.webdriver.remote.remote_connection: DEBUG: Finished Request
--------------------- >> end captured logging << ---------------------
Nam G VU
  • 33,193
  • 69
  • 233
  • 372

1 Answers1

1

This happens when you open leave a WebDriver instance idle without any activity till timeout (The default timeout value is 1800 seconds but I am guessing that you perhaps have altered this) occurs.

So you might want to check your test code to see if there are any long running NON UI operations that are being executed amidst your UI actions and also check what is the time it takes for the Non UI operation to complete.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • Thanks for the suggestion I will check on that - may I stress on the fact that *the error only occurs with remote webdriver* – Nam G VU Jul 26 '17 at 01:46
  • Yes, I understand that. This would occur only when you use the Grid, because this cleanup mechanism only resides in the Grid and not in the regular webdriver modes. – Krishnan Mahadevan Jul 26 '17 at 01:48
  • I have checked and it turns out no non-UI operations exists - except the snapshot call – Nam G VU Jul 26 '17 at 04:37
  • I have updated my OP to stress the fact about "especially when running multiple asynchronous tests" - I doubt this is the main cause @Krishnan – Nam G VU Jul 26 '17 at 04:41
  • @NamGVU - I doubt if this has got anything to do with how your Grid setup is done (Is it a plain vanilla setup or the one that uses `docker`). But still for the sake of completeness, can you please try running your test against a plain vanilla grid setup and see if the problem shows up ? Would it be possible for you to post a simple standalone test in python which can be executed to reproduce your problem? That way I can also see the issue. From the stacktrace the only time when this can happen is when there's inactivity in the Grid side for your session. – Krishnan Mahadevan Jul 26 '17 at 05:26
  • I will setup a scenario to reproceduce it on my public github. Will ping you when it is done – Nam G VU Jul 26 '17 at 05:34
  • By the way, may you clarify what you mean by plain vanilla grid? – Nam G VU Jul 26 '17 at 05:35
  • @NamGVU - When I say `plain vanilla` I am referring to this [link](http://www.seleniumhq.org/docs/07_selenium_grid.jsp#starting-selenium-grid) – Krishnan Mahadevan Jul 26 '17 at 05:39