我正在学习Cucumber,但是我无法仅仅匹配输入标签。
我在视图中的内容是
<input type="submit" value="Press!" />
我在Cucumber尝试过的是
Then the "input" field should contain "Press!"
Then the "type" field should contain "submit"
我只想确认具有特定值的输入标签的存在。没有互动。
答案 0 :(得分:2)
试试这个:
Then I should see "Press!" within "input[type=\"submit\"]"
答案 1 :(得分:1)
他们也在webrat中得到明确支持。即使您无法在黄瓜中找到内置支持,也可以随时进入自己的步骤定义。
来源: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')
答案 2 :(得分:1)
您可以使用以下内容:
response.should have_xpath("//input[@value='Press!']")
或
response.should have_selector("input", :type => "submit", :value => "Press!")