5 votes

Comment résoudre l'erreur Capybara::ElementNotFound ?

Je suis confronté au problème suivant, c'est la première fois que j'utilise capybara, avez-vous une idée de la façon dont je peux résoudre ce problème, merci.

J'utilise rails 3.0.0 et les gems suivants

gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'

Mon scénario est le suivant

When I go to the new customer page
And I fill in "Email" with "john@example.com"

Dans mon fichier customer_steps.rb, j'ai

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

À mon avis

- form_for @customer do |f|
  = f.label :email, 'Email'
  = f.text_field :email
  = f.submit

Lorsque j'exécute mon scénario, j'obtiens le message d'erreur suivant

 Scenario: Register new customer                  # features/manage_customers.feature:7
    When I go to the new customer page             # features/step_definitions/customer_steps.rb:1
    And I fill in "Email" with "john@example.com"  # features/step_definitions/customer_steps.rb:5
      cannot fill in, no text field, text area or password field with id, name, or label 'Email' found (Capybara::ElementNotFound)
      ./features/step_definitions/customer_steps.rb:6:in `/^I fill in "([^"]*)" with "([^"]*)"$/'
      features/manage_customers.feature:9:in `And I fill in "Email" with "john@example.com"'

4voto

denisjacquemin Points 3170

J'ai trouvé mon erreur !!!

When I go to the new customer page

avant que l'étape ne soit

When /^I go to (.+)$/ do |page_name|
  path_to page_name 
end

J'ai oublié la visite...

When /^I go to (.+)$/ do |page_name|
  visit path_to(page_name) 
end

2voto

Rishav Rastogi Points 12025

Utilisez plutôt l'identifiant du champ, qui devrait ressembler à

Et je remplis "customer_email" avec "john@example.com"

si le @customer est un modèle de client objet

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X