3

有人问了这个问题的几个变体,我肯定从阅读该主题中学到了,但大多数答案似乎并不直接适用于这种情况,或者涉及使用 Rspec 或 Cucumber 的解决方案。

我目前正在使用 Minitest 和 Capybara 开发一个测试套件。如果可能的话,我不想引入太多其他的 gem,但如果它们是轻量级的,我愿意接受,因为测试已经需要一段时间才能运行。

Rspec 有:js => true,Cucumber 有@javascript,但 minitest 似乎没有这样的东西。然后,自然的解决方案是切换驱动程序并执行:Capybara.current_driver = :selenium,但是当我这样做时,它不起作用,并且我得到 2 个错误(每个启用 js 的测试都有一个错误)。

我的问题是:为什么会出现这些错误,我怎样才能使一些基本的 JavaScript 测试工作?以下是错误:

Component returned failure code: 0x804b0012 (NS_ERROR_UNKNOWN_PROTOCOL) [nsIWebNavigation.loadURI]
    Exception `Selenium::WebDriver::Error::UnknownError' at:
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:65:in `request'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:576:in `execute'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:99:in `get'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/navigation.rb:14:in `to'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/selenium/driver.rb:36:in `visit'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/session.rb:157:in `visit'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in `visit'
    test/integration/resource_access_test.rb:22:in `block (2 levels) in <top (required)>'

这是另一个错误:

undefined method `[]' for nil:NilClass
    Exception `NoMethodError' at:
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/rack-test-0.6.1/lib/rack/test.rb:171:in `env_for'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/rack-test-0.6.1/lib/rack/test.rb:56:in `get'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/rack_test/browser.rb:62:in `process'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/rack_test/browser.rb:21:in `visit'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/rack_test/driver.rb:32:in `visit'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/session.rb:157:in `visit'
    /Users/epithelialbiology/.rvm/gems/ruby-1.9.2-p320/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in `visit'
    test/integration/resource_access_test.rb:40:in `block (2 levels) in <top (required)>'

有谁知道这里可能发生了什么,以及我如何解决这个问题?

4

1 回答 1

2

尝试使用以下语法切换 Capybara 驱动程序:

Capybara.current_driver = Capybara.javascript_driver
于 2012-09-05T16:24:05.580 回答