Selenium Webdriver Chromedriver timeout on start in headless mode

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

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

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-bit edition.

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.

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 job configured to run Windows Batch Command:

cd \ ruby test.rb

The output when I run the job:

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

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

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.

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

回答1:

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.

Two solutions:

  1. Downgrade Chrome to a version less than 38.
  2. Download and install AlwaysUp and configure it to run your Jenkins service as a user other than default system user

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.



回答2:

Chrome cannot run in headless mode in windows. you need to use HTMLdriver for this.

If you badly needs it, you need to try setup a vnc server and run within it. http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/



回答3:

The answer by SDET helped me (upvoted), Session 0 was my problem, but you don't need AlwaysUp, you can just launch the jenkins slave from some startup script by: javaws http://<jenkins-master>/computer/<node-name>/slave-agent.jnlp



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!