使用Xvfb(无头宝石)在Jenkins上运行Cucumber / Watir-Webdriver

时间:2015-03-04 19:24:07

标签: ruby selenium-webdriver cucumber watir-webdriver xvfb

尝试使用Xvfb(无头宝石)在Jenkins上运行Cucumber / Watir-Webdriver

这是我的env.rb:

require 'rubygems'
require 'cucumber'
require 'json'
require 'watir-webdriver'
require 'page-object'
require 'page-object/page_factory'
require 'allure-cucumber'
require 'rspec'
require 'data_magic'
require 'fig_newton'
require 'yaml'
require 'headless'

ENVT = FigNewton.load('staging.yml')
DATA = DataMagic.load('data.yml')
KBA = YAML.load_file('config/data/kba.yml')

headless = Headless.new
headless.start
browser = Watir::Browser.new :firefox

Before do
  @browser = browser
end

at_exit do
  @browser.close
  headless.destroy
end

World(PageObject::PageFactory)

这是我得到的错误:

end of file reached (EOFError)
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/2.1.0/net/protocol.rb:153:in `read_nonblock'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/2.1.0/net/protocol.rb:153:in `rbuf_fill'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/2.1.0/net/protocol.rb:134:in `readuntil'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/2.1.0/net/protocol.rb:144:in `readline'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/2.1.0/net/http/response.rb:39:in `read_status_line'
  /lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/remote/bridge.rb:640:in `raw_execute'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/remote/bridge.rb:618:in `execute'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/remote/bridge.rb:112:in `get'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/common/navigation.rb:14:in `to'
  /var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.6.11/lib/watir-webdriver/browser.rb:77:in `goto'
  /var/lib/jenkins/jobs/idme_revelator/workspace/features/support/hooks.rb:32:in `Before'
    * I resize the browser                 # features/step_definitions/misc_step_defs.rb:1
      Connection refused - connect(2) for "127.0.0.1" port 7055 (Errno::ECONNREFUSED)
      ./features/step_definitions/misc_step_defs.rb:2:in `/^I resize the browser$/'

如何使用无头宝石(Xvfb)设置我的env文件以正确运行Cucumber / Watir-Webdriver?

在其他一些尝试中,错误与未定义的方法&goto'等有关。在我的测试中,其他地方如hooks.rb我使用变量@browser或@ browser.driver,所以我需要那些工作。

1 个答案:

答案 0 :(得分:0)

我会看看这个问题的答案,因为你的错误是相同的,除了不同的端口号

Opening several threads with watir-webdriver results in 'Connection refused' error

看起来您可能有多个浏览器同时尝试访问同一个端口。添加睡眠可能会修复它,但不是最佳实践解决方案。我会更清楚地定义每个浏览器连接的端口号。