将输入标签与 Cucumber/Webrat 匹配

发布于 2024-09-30 04:58:47 字数 305 浏览 1 评论 0原文

我正在学习 Cucumber,但我无法仅匹配输入标签。

我在视图中看到的是

<input type="submit" value="Press!" />

,我在 Cucumber 中尝试过的是,

Then the "input" field should contain "Press!"
Then the "type" field should contain "submit"

我只是想确认具有某些值的输入标签的存在。没有互动。

I'm learning Cucumber, but I can't make a step for just matching input tags.

What I have in the view is

<input type="submit" value="Press!" />

And what I tried in Cucumber are

Then the "input" field should contain "Press!"
Then the "type" field should contain "submit"

I just wanna confirm the existence for the input tags with certain values. No interaction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

新雨望断虹 2024-10-07 04:58:47

试试这个:

然后我应该看到“按!”在“输入[类型=\”提交\“]”内

Try this:

Then I should see "Press!" within "input[type=\"submit\"]"

心房敞 2024-10-07 04:58:47

webrat 也明确支持它们。即使您找不到 Cucumber 的内置支持,您也可以随时放入自己的步骤定义中。

来源:http://cheat.errtheblog.com/s/webrat/

== Assertions

   # check for text in the body of html tags
   # can be a string or regexp
  assert_contain("BURNINATOR")
  assert_contain(/trogdor/i)
  assert_not_contain("peasants")

  # check for a css3 selector
  assert_have_selector 'div.pagination'
  assert_have_no_selector 'form input#name'


== Matchers

  # check for text in the body of html tags
  # can be a string or regexp
  # Matchers are verbs used with auxillary verbs should, should_not, etc.
  response.should contain("BURNINATOR")
  response.should contain(/trogdor/i)
  response.should_not contain("peasants")

  # check for a css3 selector
  response.should have_selector('div.pagination')
  response.should_not have_selector('form input#name')

They're also explicitly supported in webrat. Even if you can't find the built-in support in cucumber, you can always just drop into your own step definitions.

source: http://cheat.errtheblog.com/s/webrat/

== Assertions

   # check for text in the body of html tags
   # can be a string or regexp
  assert_contain("BURNINATOR")
  assert_contain(/trogdor/i)
  assert_not_contain("peasants")

  # check for a css3 selector
  assert_have_selector 'div.pagination'
  assert_have_no_selector 'form input#name'


== Matchers

  # check for text in the body of html tags
  # can be a string or regexp
  # Matchers are verbs used with auxillary verbs should, should_not, etc.
  response.should contain("BURNINATOR")
  response.should contain(/trogdor/i)
  response.should_not contain("peasants")

  # check for a css3 selector
  response.should have_selector('div.pagination')
  response.should_not have_selector('form input#name')
半仙 2024-10-07 04:58:47

您可以使用类似以下内容:

response.should have_xpath("//input[@value='Press!']")

response.should have_selector("input", :type => "submit", :value => "Press!")

You can use something like:

response.should have_xpath("//input[@value='Press!']")

or

response.should have_selector("input", :type => "submit", :value => "Press!")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文