Capybara will not fill in input fields

I cannot get Capybara to fill in the values ​​in my login field. Here login_spec.rb

require 'spec_helper' describe "the login process" do it "signs me in" do visit '/login' fill_in 'user_username', :with => 'Admin' fill_in 'user_password', :with => 'Password' end end 

When I run the test, it fails with the following error:

 1) the login process signs me in Failure/Error: fill_in 'user_username', :with => 'Admin' Capybara::ElementNotFound: no text field, text area or password field with id, name, or label 'user_username' found # (eval):2:in `fill_in' # ./spec/integration/login_spec.rb:7:in `block (2 levels) in <top (required)>' 

But when I print the contents of the page with

 print page.html 

I clearly see that the item identifiers are correct.

 <h2>Already Have an Account?</h2> <form accept-charset="UTF-8" action="/login" id="sidebar_login" method="post"> <div style="margin:0;padding:0;display:inline"> <input name="utf8" type="hidden" value="βœ“"><input name="authenticity_token" type="hidden" value="DccrBxhdS7WTAM/iEd08L4z9zt8MjBKTxQ0s6lMVIAA="> </div> <div class="form"></div> <div class="login_form_widget"> Username <div class="inputdiv_widget"> <input class="textfield" id="user_username" name="user[username]" type="text"> </div> Password <div class="inputdiv_widget"> <input class="textfield" id="user_password" name="user[password]" type="password"> </div> 

I tried using the item id (user_username) and name (user [username]), all with the same results. Is something missing here?

+4
source share
1 answer

What to do if you tried to add a shortcut, for example:

 <label for="user_username">Username</label> 

and in your specification you use:

 within ".login_form_widget" do fill_in 'Username', :with => 'Admin' end 

The labels found are especially useful, but otherwise I did not see anything wrong with the syntax you used above.

+6
source

Source: https://habr.com/ru/post/1400083/


All Articles