我正在使用Selenium Webdriver,Ruby 32位1.9.3,Chromedriver v2.9.248315,Chrome 38.0.2125.111 m以及Jenkins 1.588的本地实例
宝石:黄瓜(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
Jenkins作业配置为运行Windows批处理命令:
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 :(得分:5)
在会话0中以系统用户身份运行时,Chrome 38无效。通常会发生这种情况,因为Chrome是由Windows服务启动的 - 在您的情况下,Jenkins是作为服务运行的。这是一个已知的问题。请参阅Selenium问题here和here。
两种解决方案:
AlwaysUp解决方案绝对有效,但许可成本很低,或者如果您对Chrome版本不感兴趣,可以降级它。
答案 1 :(得分:1)
Chrome无法在Windows中以无头模式运行。 你需要使用HTMLdriver。
如果您非常需要它,您需要尝试设置vnc服务器并在其中运行。 http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/
答案 2 :(得分:0)
SDET的答案帮助了我(upvoted),第0节是我的问题,但你不需要AlwaysUp,你可以通过以下方式从一些启动脚本启动jenkins slave:javaws http://<jenkins-master>/computer/<node-name>/slave-agent.jnlp