1

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

我的观点是

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

我在 Cucumber 中尝试的是

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

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

4

3 回答 3

2

试试这个:

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

于 2010-10-28T03:40:53.993 回答
1

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')
于 2011-01-21T23:44:17.847 回答
1

你可以使用类似的东西:

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

或者

response.should have_selector("input", :type => "submit", :value => "Press!")
于 2011-08-05T03:37:25.960 回答