5

我在 Ruby 中使用 Capybara 和 Selenium(不在测试框架内。)

如果我打开一个 ruby​​ 控制台并运行该方法,它可以工作,但如果我再次运行相同的方法,我会收到此错误。

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

代码如下:

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
4

1 回答 1

2

您可以在设置一些默认时间后尝试吗?

Capybara.default_wait_time = 10

只需在设置当前驱动程序后给出此评论。它可以帮助你克服这个问题。

于 2013-07-16T12:49:12.277 回答