Connection refused error when running selenium with chrome and firefox drivers



  • 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 :face_with_thermometer: 
    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 '
    
    1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
    


  • 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.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2