Rails 3 integration testing - using webrat fill_in not finding fields

I am studying testing right now, but I am having some problems with the fact that Webrat does not find the form field using fill_in, although I checked that it is on the correct page. Does Webrat work with field names or identifiers? I tried using Ruby characters and form names to access the field, but none of them work in my case. Do you see something wrong in my implementation?

Error message:

5) Forwarding should forward the user to the requested page after signin
   Failure/Error: integration_sign_in(user)
   Could not find field: :email

Security Code:

it "should forward the user to the requested page after signin" do
  user = Factory(:user)
  visit edit_user_path(user)

  # The test automatically follows the redirect to the signin page
  puts current_url
  integration_sign_in(user)

  # The test follows the redirect again, this time to users/edit
  response.should render_template('users/edit')
end

where integration_sign_inis inspec_helper.rb

def integration_sign_in(user) 
  fill_in :email,   :with => user.email 
  fill_in :password, :with => user.password 
  click_button
end

HTML form field:

<form action='/sessions' class='mtm' id='sign-in-form' method='post'> 
    <input name='authenticity_token' type='hidden' value='iIIqT6bUwiJkpqpgxm5sjAj3egrNcEgeXPsYmbKQ02U='> 
        <div class='landingSignInForm'> 
          <label class='mas signin-label' for='email'>E-mail:</label> 
          <input class="mls ras" id="email" name="email" placeholder="e-mail address" type="text" /> 
          <label class='mas signin-label' for='password'>Password:</label> 
          <input class="mls ras" id="password" name="password" placeholder="password" type="password" /> 
          <input checked='checked' class='mls mtm' name='remember' type='checkbox' value='permanent'> 
          <span class='remember-me-label'>Keep me signed in</span> 
          <input class='mls mvm ram medium silver button' name='submit' type='submit' value='Sign in'> 
          <a class='forgot-password' href='#'>Forget your password?</a> 
        </div> 
</form> 
+5
source share
2 answers

css ID , ? webrat , , , , . webrat, fill_in :symbol only fill_in 'string'

:

def integration_sign_in(user) 
  fill_in 'email',   :with => user.email 
  fill_in 'password', :with => user.password 
  click_button
end

css :

def integration_sign_in(user) 
  fill_in '#email',   :with => user.email 
  fill_in '#password', :with => user.password 
  click_button
end
+1

fill_in 'email', :with => user.email    # field name

fill_in 'E-mail', :with => user.email   # partial label text

. webrat.

, , . HTML, ?

, Capybara, , webrat .

+1

All Articles