1

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

该脚本执行以下操作:

  1. 注册驱动程序
  2. 驱动程序导航到“ https://www.google.co.uk/
  3. 司机下车

脚本:

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

当我运行它时,驱动程序打开 Edge,导航到谷歌,MicrosoftWebDriver 在“退出”方法之前停止,导致 ruby​​ 引发错误。

下面是控制台的输出:

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
4

1 回答 1

0

对我来说,这看起来像是一个特定于 MS 的问题,因为它之前确实有效(我现在遇到了同样的问题),但是在 Windows 更新之后突然出现了这条消息。 根据 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 防火墙,但奇怪的是问题没有出现。

于 2017-11-27T11:11:20.793 回答