0
votes

Trying to run Cucumber/Watir-Webdriver on Jenkins using Xvfb (headless gem)

This is my 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)

This is the error I'm getting:

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$/'

How do I need to setup my env file to correctly run Cucumber/Watir-Webdriver using the headless gem (Xvfb)?

In some other attempts, errors have been related to undefined method 'goto', etc. In my tests other places like hooks.rb I use the variable @browser or @browser.driver, so I need those to work as well.

1
Since the stacktrace points at your hooks.rb (and misc_step_def.rb), you should edit your question and show that file.orde
Why would you resize the browser when you run it headless?Dave McNulla
Nevermind. I found that it's used for screenshots. I think we need to see that step def for 'I resize the browser'Dave McNulla

1 Answers

0
votes

I would take a look at the answer to this question as it your error is the same save for the different port number

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

It looks like you maybe have multiple browsers trying to access the same port at the same time. Adding a sleep might fix it, but is not a best-practice solution. I would more clearly define your port numbers that each browser connects to.