如何在带有自定义标签的表单中使用 Cucumber
我正在尝试学习如何使用黄瓜并遇到这个问题:
我有一个表格,如下所示:
<p>
<%= f.label :name, "Nome" %><br />
<%= f.text_field :name %>
</p>
在我的黄瓜功能中,我有:
And I fill in "name" with "Reitoria do Porto"
这使测试失败:
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"'
但是,如果我只是制作这样的表格:
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
测试通过。
如何保留我的自定义标签名称并使测试通过?
I'm trying to learn how to use cucumber and got this issue:
I have a form that as:
<p>
<%= f.label :name, "Nome" %><br />
<%= f.text_field :name %>
</p>
And in my cucumber feature I have:
And I fill in "name" with "Reitoria do Porto"
This make the test fail with:
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 just make the form like this:
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
The test passes.
How can I keep my custom label name and make the test pass?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Webrat 使用标签文本来定位要填写的字段。在您的第一个示例中,您是否没有将此标签设置为“Nome”?
我用“Reitoria do Porto”填写“Nome”
有效吗?Webrat uses the label text to locate the field to fill in. In your first example, are you not setting this label to "Nome"?
Does
And I fill in "Nome" with "Reitoria do Porto"
work?您还可以使用 HTML 中显示的字段名称。因此,如果模型
name
属于User
,那么您应该能够通过以下方式访问它:如果有疑问,只需查看生成的 HTML 代码并从那里获取字段名称。
You can also use the field name as it appears in HTML. So if the model
name
belongs to is lets sayUser
than you should be able to access it viaIf in doubt, just have a look at the generated HTML code and take the field name from there.