Python WebDriver .quit()获取错误

时间:2017-07-25 08:10:15

标签: python selenium webdriver selenium-grid

我的selenium测试与本地webdriver运行良好但在针对远程webdriver运行时失败,即针对从SeleniumHQ docker images构建的selenium网格运行

测试是用python编写的,而我正在使用的selenium pip包是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

问题是为什么.quit()会收到错误(有时会通过,有时会失败),特别是当运行多个异步测试时?我们如何解决它?

P.S。

完整的异常跟踪

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

1 个答案:

答案 0 :(得分:1)

当你打开WebDriver实例空闲而没有任何活动直到超时(默认超时值为1800 seconds但我猜你可能已经改变了这种情况)时会发生这种情况。

因此,您可能需要检查测试代码,看看是否在 UI操作中执行了长时间运行的NON UI操作,并检查了什么是非UI操作完成所需的时间。