如何在带有自定义标签的表单中使用 Cucumber

发布于 2024-08-24 04:44:07 字数 903 浏览 3 评论 0原文

我正在尝试学习如何使用黄瓜并遇到这个问题:

我有一个表格,如下所示:

  <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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2024-08-31 04:44:08

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?

秉烛思 2024-08-31 04:44:08

您还可以使用 HTML 中显示的字段名称。因此,如果模型name属于User,那么您应该能够通过以下方式访问它:

我用“Reitoria do Porto”填写“user_name”

如果有疑问,只需查看生成的 HTML 代码并从那里获取字段名称。

You can also use the field name as it appears in HTML. So if the model namebelongs to is lets say Userthan you should be able to access it via

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文