相关疑难解决方法(0)

如何解决Capybara :: ElementNotFound错误

我遇到了以下问题,这是我第一次使用水豚,请你知道如何解决这个问题,谢谢

我使用rails 3.0.0和以下宝石

gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'
Run Code Online (Sandbox Code Playgroud)

我在Senario中有以下内容

When I go to the new customer page
And I fill in "Email" with "john@example.com"
Run Code Online (Sandbox Code Playgroud)

在我的customer_steps.rb我有

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
  fill_in arg1, :with => arg2
end
Run Code Online (Sandbox Code Playgroud)

在我看来

- form_for @customer do |f|
  = f.label :email, 'Email'
  = f.text_field :email
  = f.submit
Run Code Online (Sandbox Code Playgroud)

当我运行我的方案时,我收到此错误消息

 Scenario: Register new customer                  # features/manage_customers.feature:7
    When I go to the …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails cucumber capybara

5
推荐指数
1
解决办法
6121
查看次数

Capybara :: ElementNotFound,但它就在那里

我收到以下错误:

Capybara::ElementNotFound: Unable to find field "username"
./spec/controllers/sessions_controller_spec.rb:10:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

规格:

require 'spec_helper'

describe SessionsController do
  before :each do
    @user = FactoryGirl.create(:user)
  end
  context 'creating a new session' do
    it 'can set the current_user variable to the logged user' do
      visit '/login'
      fill_in 'username', with: 'gabrielhilal' #I have tried `Username` as well
      fill_in 'password', with: 'secret'
      click_button 'Login'
      current_user.should == @user
      current_user.username.should == 'gabrielhilal'
    end
  end
  context 'destroying existing session' do
    xit 'can destroy the current_user' …
Run Code Online (Sandbox Code Playgroud)

bdd rspec ruby-on-rails capybara ruby-on-rails-4

3
推荐指数
2
解决办法
1万
查看次数

Capybara :: ElementNotFound:错误

我正在关注railstutorial.org教程我收到以下错误

  1) User pages signup with valid information should create a user
     Failure/Error: fill_in "password" , with: "foobar"
     Capybara::ElementNotFound:
       cannot fill in, no text field, text area or password field with id, name, or label 'password' found
     # (eval):2:in `fill_in'
     # ./spec/requests/user_pages_spec.rb:32:in `block (4 levels) in <top (required)>'

  2) Authentication signin with invalid information 
     Failure/Error: before { click_button "Sign in" }
     Capybara::ElementNotFound:
       no button with value or id or text 'Sign in' found
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:14:in `block (4 …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-3 railstutorial.org ruby-on-rails-3.2

1
推荐指数
1
解决办法
2545
查看次数