Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I am running selenium tests with firefox and chrome drivers. I get a connection refused error when I run the tests in as a block

Test example :

require 'minitest_helper'

headless = Headless.new
headless.start
browser = Selenium::WebDriver.for :chrome

describe "Test Example" do

  after :all do
    headless.destroy
  end
  it "test" do
    browser.navigate.to "http://google.com"
  end
end 

stack trace:

1) Error:
Example test#test_0001_test:
Errno::ECONNREFUSED: Connection refused - connect(2)
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:762:in `open'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:762:in `connect'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:744:in `start'
    /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1284:in `request'
    /usr/local/rvm/gems/ruby-1.9.3-p125@cam_integration/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
    /usr/local/rvm/gems/ruby-1.9.3-p125@cam_integration/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
    /usr/local/rvm/gems/ruby-1.9.3-p125@cam_integration/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
    /usr/local/rvm/gems/ruby-1.9.3-p125@cam_integration/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/bridge.rb:616:in `raw_execute'
    /usr/local/rvm/gems/ruby-1.9.3-p125@cam_integration/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/bridge.rb:594:in `execute'
    /usr/local/rvm/gems/ruby-1.9.3-p125@cam_integration/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/bridge.rb:100:in `get'
    /usr/local/rvm/gems/ruby-1.9.3-p125@cam_integration/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/navigation.rb:14:in `to'
    test/integration/signup_test.rb:13:in `block (2 levels) in <main>'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
share|improve this question
add comment

1 Answer 1

I was facing a similar issue, and found a solution in this article: http://swdandruby.wordpress.com/2013/05/11/headless-gem-causes-errnoeconnrefused/

You have to specify a different display number for each browser headless instances you need.

So if you want to run at the same time chrome and firefox in separate headless mode, you can do something like:

browsers = {}

[:chrome, :firefox].each do |browser|
  Headless.new(display: rand(99)).start
  browsers[browser] = Selenium::WebDriver.for browser
end

browsers[:chrome].navigate.to "http://google.com"
browsers[:firefox].navigate.to "http://mozilla.org"

This will spawn two separate headless process. Note that you shouldn't rely on random things and better find some kind of unique ids.

share|improve this answer
    
I wrote the blog post reference above. The way I go about this on my CI environment is just assign the CI build job # to the display using the environmental variable set by the job. Jobs are usually on different number iterations, so this seems to work well. The problems with using a random number are the off chance that the same random numbers could be chosen for multiple instances, as well as the difficulty in knowing which display was used incase you want to VNC in to the headless display and observe the interactions. –  bbbco Aug 27 '13 at 14:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.