Selenium Webdriver Chromedriver在无头模式下启动时超时 [英] Selenium Webdriver Chromedriver timeout on start in headless mode

查看:412
本文介绍了Selenium Webdriver Chromedriver在无头模式下启动时超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium Webdriver,以及Ruby 32位1.9.3,Chromedriver v2.9.248315,Chrome 38.0.2125.111 m和Jenkins 1.588的本地实例

I am using Selenium Webdriver, with Ruby 32-bit 1.9.3, Chromedriver v2.9.248315, Chrome 38.0.2125.111 m and a local instance of Jenkins 1.588

宝石:黄瓜(1.3.17),硒-webdriver(2.43.0),watir-webdriver(0.6.11)(如果您认为有必要,可以提供所有其他列表)

Gems: cucumber (1.3.17), selenium-webdriver (2.43.0), watir-webdriver (0.6.11) (can provide list of all others if you think necessary)

Windows 7 Professional 64位版本.

Windows 7 Professional 64-bit edition.

运行Jenkins作业,该作业使用chromedriver启动Chrome,然后尝试与之交互时,出现超时错误.通过命令提示符窗口在桌面上执行相同操作时,它可以完美运行.运行相同的Jenkins作业,启动Firefox而不是Chrome,效果很好.

When running a Jenkins job which starts Chrome using chromedriver and then trying to interact with it I get a timeout error. When doing the same on my desktop via a command prompt window it works perfectly. Running the same Jenkins job, starting Firefox instead of Chrome it works perfectly.

简单示例(C:\ test.rb):

Simple example (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批处理命令:

Jenkins job configured to run Windows Batch Command:

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

I have tried enabling "Allow service to interact with desktop" in the Jenkins service, then watching the window (in a more complex scenario) and the Chrome window opens, but does nothing. I originally had the problem with "$browser.cookies.clear" and after commenting out that line I now have the same problem with the line $browser.driver.manage.window.maximize

我正在运行复杂的黄瓜方案,而使用Chromedriver却没有任何问题.然后,我重建了PC,在安装了Jenkins,Ruby,Chromedriver(将它们都添加到PATH)并将旧作业复制到新的Jenkins安装中之后,我遇到了上述问题.然后,我创建了上面的简单示例,对其进行了测试并创建了这篇文章.

I was running complex cucumber scenarios with no trouble using Chromedriver. Then I had my PC rebuilt and after installing Jenkins, Ruby, Chromedriver (adding both to PATH) and copying the old jobs into my new Jenkins installation I had the above problem. I then created the simple example above, tested it and created this post.

如果有人对我如何使Chromedriver重新工作有任何想法,那就太好了.

If anyone has any ideas about how I can get Chromedriver working again that would be great.

推荐答案

在会话0中以系统用户身份运行时,Chrome 38不起作用.通常会发生这种情况,因为Chrome是由Windows服务启动的-在您的情况下是Jenkins作为服务.这是一个已知的问题.请参见此处

Chrome 38 does not work when running as system user in Session 0. Normally this occurs because Chrome is launched by a Windows service - in your case Jenkins which is run as a service. This is a known issue. See Selenium issues here and here.

两种解决方案:

  1. 将Chrome降级到38以下的版本.
  2. 下载并安装 AlwaysUp AlwaysUp解决方案绝对可以使用,但许可费用很少,或者,如果您对Chrome版本不感到烦恼,可以将其降级.

    The AlwaysUp solution definitely works but has a small licencing cost, or if you're not bothered about the Chrome version you can downgrade it.

    这篇关于Selenium Webdriver Chromedriver在无头模式下启动时超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆