0

I'm using cucumber to test and I'm using simple_form for the contact form. I get the following error:

Given I am on the login page 
And I fill in "student_name" with "sadik" 
    Unable to find field "student_name" (Capybara::ElementNotFound)

my steps:

Scenario: Add a student to the database
  Given I am on the login page
  And I fill in "student_name" with "sadik"
  When I press "OK"
  ...

The form:

<%= simple_form_for @student do |f| %>
  <%= f.input :name, label: 'student_name' %>,
    :input_html => { :field => 'student_name' } %>
  <%= f.button :submit %>
<% end %>

I also tried id and name instead of label. But it had no effect.

But the first step is correct:

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

When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
  fill_in(field.gsub(' ', '_'), :with => value)
end

So where is the problem?

Sadık
  • 4,249
  • 7
  • 53
  • 89

1 Answers1

0

Your syntax and labels seem incorrect.

For the form try:

<%= simple_form_for @student do |f| %>
   <%= f.input :name, as: :text, label: 'Student Name' %>
   <%= f.button :submit %>
<% end %>

And for the last step try:

When /^I fill in student_name with "([^\"]*)"$/ do |value|
  fill_in "Student Name", :with => value
end

edit: You might also need to change this line and remove the quotes:

And I fill in student_name with "sadik"
jakmarkiewicz
  • 51
  • 1
  • 1
  • 5
  • That still gives me: Unable to find field "Student Name" (Capybara::ElementNotFound) – Sadık Feb 22 '13 at 14:59
  • 1
    Are you sure your test is looking at the right page ? Try adding `save_and_open_page` to one of your steps and inspect the page source HTML for the correct form name fields. – jakmarkiewicz Feb 22 '13 at 15:08