我正在使用Selenium Webdriver,Ruby 32位1.9.3,Chromedriver v2.9.248315,Chrome 38.0.2125.111 m和Jenkins 1.588的本地实例
Gems: cucumber (1.3.17),selenium-webdriver (2.43.0), watir-webdriver (0.6.11)(如果您认为有必要,可以提供所有其他文件的列表)
Windows 7 Professional 64位版本。
运行Jenkins作业时,该作业使用chromedriver启动Chrome,然后尝试与其进行交互,但出现超时错误。通过命令提示符窗口在桌面上执行相同操作时,它可以完美运行。运行相同的Jenkins作业,启动Firefox而不是Chrome,效果很好。
简单示例(C:\ test.rb):
require 'watir-webdriver' require 'selenium-webdriver' client = Selenium::WebDriver::Remote::Http::Default.new $browser = Watir::Browser.new :chrome, :http_client => client $browser.driver.manage.window.maximize $browser.close
配置为运行Windows批处理命令的Jenkins作业:
cd \ ruby test.rb
运行作业时的输出:
Started by user anonymous Building in workspace C:\Program Files (x86)\Jenkins\jobs\test chromedriver\workspace [workspace] $ cmd /c call C:\Windows\TEMP\hudson3963234995624341455.bat C:\Program Files (x86)\Jenkins\jobs\test chromedriver\workspace>cd \ C:\>ruby test.rb C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error) from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill' from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil' from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in `readline' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2563:in `read_status_line' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2552:in `read_new' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1320:in `block in transport_request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1317:in `catch' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1317:in `transport_request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1294:in `request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1287:in `block in request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:746:in `start' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1285:in `request' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:638:in `raw_execute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:616:in `execute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:236:in `maximizeWindow' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/window.rb:98:in `maximize' from test.rb:5:in `<main>' C:\>exit 1 Build step 'Execute Windows batch command' marked build as failure Finished: FAILURE
我尝试在Jenkins服务中启用“允许服务与桌面进行交互”,然后观察窗口(在更复杂的情况下),然后Chrome窗口打开,但是什么也不做。我最初遇到了“$browser.cookies.clear”问题,并且在注释掉该行之后,我现在在$browser.driver.manage.window.maximize行中也遇到了同样的问题
我正在运行复杂的黄瓜方案,而使用Chromedriver却没有问题。然后,我重建了PC,并安装了Jenkins,Ruby,Chromedriver(将它们都添加到PATH)并将旧作业复制到新的Jenkins安装中后,出现了上述问题。然后,我创建了上面的简单示例,对其进行了测试并创建了这篇文章。
如果有人对我如何使Chromedriver重新工作有任何想法,那就太好了。
在会话0中以系统用户身份运行时,Chrome38不起作用。通常是因为Chrome是由Windows服务(在您的情况下是作为服务运行的Jenkins)启动,因此会发生这种情况。这是一个已知的问题。请在此处和此处查看硒问题。
两种解决方案:
AlwaysUp解决方案绝对可以使用,但许可费用较低,如果您不担心Chrome版本,可以将其降级。