How to use cucumber in forms using custom labels

I am trying to learn how to use a cucumber and got this problem:

I have a form that:

<p> <%= f.label :name, "Nome" %><br /> <%= f.text_field :name %> </p> 

And in my cucumber function, I have:

  And I fill in "name" with "Reitoria do Porto" 

This will cause the test to fail:

 And I fill in "name" with "Reitoria do Porto" # features/step_definitions/web_steps.rb:34 Could not find field: "name" (Webrat::NotFoundError) (eval):2:in `fill_in' ./features/step_definitions/web_steps.rb:35:in `/^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/' features/manage_institutions.feature:10:in `And I fill in "name" with "Reitoria do Porto"' 

However, if I simply create the form as follows:

  <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> 

The test passes.

How can I save my own shortcut name and make a test pass?

+4
source share
2 answers

Webrat uses shortcut text to find the field to fill. In your first example, you do not set this shortcut to "Nome"?

Does And I fill in "Nome" with "Reitoria do Porto" ?

+3
source

You can also use the field name as it appears in HTML. So if the name model belongs, then let's say User , than you should have access to it through

And I fill in "user_name" in "Reitoria do Porto"

If in doubt, just take a look at the generated HTML code and take the name of the field there.

+1
source

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


All Articles