MicrosoftWebDriver在启动后不久就停止工作

时间:2017-09-22 11:35:33

标签: ruby selenium-webdriver microsoft-edge browser-automation microsoft-webdriver

我有一个非常简单的脚本作为冒烟测试。

该脚本执行以下操作:

  1. 注册驱动程序
  2. 驱动程序导航至“https://www.google.co.uk/
  3. 驱动程序退出
  4. 脚本:

    require 'selenium-webdriver'
    driver = Selenium::WebDriver.for(:edge)
    driver.navigate.to("https://www.google.co.uk/")
    driver.quit
    

    当我运行此程序时,驱动程序打开Edge,导航到google并且MicrosoftWebDriver在'quit'方法之前停止,导致ruby引发错误。

    Bellow是控制台的输出:

    PS C:\projects\sandbox> ruby test.rb
    2017-09-22 11:54:32 DEBUG Selenium Executing Process ["C:/WebDrivers/MicrosoftWebDriver.exe", "--port=17556"]
    Listening on http://localhost:17556/
    2017-09-22 11:54:32 INFO Selenium -> POST session
    2017-09-22 11:54:32 INFO Selenium    >>> http://localhost:17556/session | {"desiredCapabilities":{"browserName":"MicrosoftEdge","platform":"WINDOWS"},"capabilities":{"firstMatch":[{"browserName":"MicrosoftEdge"}]}}
    2017-09-22 11:54:32 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"140"}
    2017-09-22 11:54:33 INFO Selenium <- {"sessionId":"EAB1B8C2-DF58-4DED-BD52-8386F1FC9B0A","status":0,"value":{"browserName":"MicrosoftEdge","browserVersion":"25.10586.672.0","platformName":"windows","platformVersion":
    "10","takesElementScreenshot":true,"takesScreenshot":true,"acceptSslCerts":true,"pageLoadStrategy":"normal"}}
    2017-09-22 11:54:33 INFO Selenium Detected OSS dialect.
    2017-09-22 11:54:33 INFO Selenium Forcing W3C dialect.
    2017-09-22 11:54:33 INFO Selenium -> POST session/EAB1B8C2-DF58-4DED-BD52-8386F1FC9B0A/url
    2017-09-22 11:54:33 INFO Selenium    >>> http://localhost:17556/session/EAB1B8C2-DF58-4DED-BD52-8386F1FC9B0A/url | {"url":"https://www.google.co.uk/"}
    2017-09-22 11:54:33 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"35"}
    2017-09-22 11:54:33 INFO Selenium <- {"sessionId":"EAB1B8C2-DF58-4DED-BD52-8386F1FC9B0A","status":0,"value":null}
    2017-09-22 11:54:34 INFO Selenium -> DELETE session/EAB1B8C2-DF58-4DED-BD52-8386F1FC9B0A
    2017-09-22 11:54:35 INFO Selenium <- {"sessionId":"EAB1B8C2-DF58-4DED-BD52-8386F1FC9B0A","status":0,"value":null}
    Stopping server.
    C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect': Failed to open TCP connection to localhost:17556 (No connection could be made because the target machine actively refused it. - connect(2)
     for "localhost" port 17556) (Errno::ECONNREFUSED)
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
            from C:/Ruby23-x64/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
            from C:/Ruby23-x64/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:878:in `connect'
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:1476:in `begin_transport'
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:1433:in `transport_request'
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:1407:in `request'
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:1156:in `get'
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.5.2/lib/selenium/webdriver/common/service.rb:130:in `block in stop_server'
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.5.2/lib/selenium/webdriver/common/service.rb:110:in `block in connect_to_server'
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:853:in `start'
            from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:584:in `start'
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.5.2/lib/selenium/webdriver/common/service.rb:106:in `connect_to_server'
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.5.2/lib/selenium/webdriver/common/service.rb:130:in `stop_server'
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.5.2/lib/selenium/webdriver/common/service.rb:79:in `stop'
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.5.2/lib/selenium/webdriver/edge/driver.rb:74:in `quit'
            from test.rb:29:in `<main>'
    

    我已经尝试解决此问题:

    • 我已禁用防火墙并关闭了防病毒软件
    • 尝试了不同版本的MicrosoftWebDriver
    • 尝试了不同版本的SeleniumDriver

1 个答案:

答案 0 :(得分:0)

对我而言,这看起来像MS特定的问题,因为它之前有效(我现在遇到同样的问题),但是在Windows更新后突然出现了这条消息。 According to MS一个可能的解决方案是使用Fiddler4(http://fiddler2.com/r/?GetFiddler4Beta)内置的WinConfig工具或CheckNetIsolation工具来免除Edge

要为Edge启用环回,请使用以下命令:

CheckNetIsolation LoopbackExempt -a -n="Microsoft.MicrosoftEdge_8wekyb3d8bbwe"

要禁用Edge的环回,请使用此命令:

CheckNetIsolation.exe LoopbackExempt –d –n="Microsoft.MicrosoftEdge_8wekyb3d8bbwe"

出于某些原因,我的本地机器尚未解决问题。 然后经过一些调试帮助,他们给了我一个提示,它可能与防火墙有关。所以我关闭了Windows防火墙并再次尝试。问题解决了。我重新打开了Windows防火墙,奇怪的是问题没有恢复。