没有Rails,Rspec或Cucumber的Capybara的NoMethod错误

时间:2022-08-22 22:44:05

I'm trying to run Capybara without Rails,Cucumber,Rspec just in pure Ruby.

我试图在没有Rails,Cucumber,Rspec的情况下运行Capybara,只是在纯Ruby中。

My test script looks like this:

我的测试脚本如下所示:

require 'capybara'
require 'selenium-webdriver'

url = "MyAccessKey"
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome
capabilities.platform = :LINUX

Capybara.register_driver :sauce do |app|
Capybara::Selenium::Driver.new(app,
  :browser => :remote, :url => url,
  :desired_capabilities => capabilities)
end

Capybara.default_driver=:sauce
Capybara.app_host="127.0.0.1:8888"


include Capybara::DSL
# include Capybara::RSpecMatchers

visit('')
feature "Signing in" do
    scenario "Should sign in" do
        within ('#form_content') do
            fill_in 'login',:with=>'user'
            fill_in 'password',:with=>'pwd'
            find(:xpath,'//input[@type="submit"]').click    
        end
    end
end

visit works fine... but feature and scenario gives a NoMethodError. Should I include anything here?

访问工作正常...但功能和方案给出NoMethodError。我应该在这里包括什么吗?

1 个解决方案

#1


1  

feature and scenario are part of RSpec. This is not loaded by default when using Capybara.

功能和场景是RSpec的一部分。使用Capybara时,默认情况下不会加载。

Assuming you want to include the Capybara modified RSpec, instead of doing:

假设您想要包含Capybara修改的RSpec,而不是:

require 'capybara'

Do:

require 'capybara/rspec'

If you just want plain RSpec, you can of course do:

如果您只想要普通的RSpec,您当然可以:

require 'capybara'
require 'rspec'

#1


1  

feature and scenario are part of RSpec. This is not loaded by default when using Capybara.

功能和场景是RSpec的一部分。使用Capybara时,默认情况下不会加载。

Assuming you want to include the Capybara modified RSpec, instead of doing:

假设您想要包含Capybara修改的RSpec,而不是:

require 'capybara'

Do:

require 'capybara/rspec'

If you just want plain RSpec, you can of course do:

如果您只想要普通的RSpec,您当然可以:

require 'capybara'
require 'rspec'