Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara Connection Refused

I am using Capybara with Selenium in Ruby (not within a testing framework.)

If I open a ruby console and run the method, it works, but if i then run the same method again I get this error.

    Errno::ECONNREFUSED: Connection refused - connect(2)
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `open'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `connect'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:744:in `start'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:1284:in `request'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:576:in `execute'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:99:in `get'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/navigation.rb:14:in `to'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/capybara-2.0.1/lib/capybara/selenium/driver.rb:34:in `visit'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/capybara-2.0.1/lib/capybara/session.rb:180:in `visit'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/capybara-2.0.1/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'

The code is like the following:

class ExampleClass
  include Capybara::DSL

  def do_capybara

    Capybara.app_host =  "http://example.com"
    Capybara.run_server = false
    Capybara.current_driver = :selenium

    visit '/'

    page.driver.browser.close

    Capybara.reset_sessions!
  end
like image 812
Ross Avatar asked Nov 03 '22 09:11

Ross


1 Answers

Could you tried after set some default time.

Capybara.default_wait_time = 10

Just give this comment after set the current driver. It may help you to overcome from the issue.

like image 168
KAK Avatar answered Nov 08 '22 05:11

KAK