我正在學習Cucumber,但我無法爲匹配輸入標籤做出步驟。將輸入標籤與Cucumber/Webrat匹配
我在視圖中什麼是
<input type="submit" value="Press!" />
,也是我試過黃瓜是
Then the "input" field should contain "Press!"
Then the "type" field should contain "submit"
我只是想確認某些值的輸入標籤的存在。沒有互動。
我正在學習Cucumber,但我無法爲匹配輸入標籤做出步驟。將輸入標籤與Cucumber/Webrat匹配
我在視圖中什麼是
<input type="submit" value="Press!" />
,也是我試過黃瓜是
Then the "input" field should contain "Press!"
Then the "type" field should contain "submit"
我只是想確認某些值的輸入標籤的存在。沒有互動。
他們還明確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')
試試這個:
Then I should see "Press!" within "input[type=\"submit\"]"
感謝。對我來說,很奇怪的是,沒有一個框架可以通過簡單的方法來檢查表單元素的存在。 – 2010-10-29 05:49:07
您可以使用類似:
response.should have_xpath("//input[@value='Press!']")
或
response.should have_selector("input", :type => "submit", :value => "Press!")
我通過搜索'trogdor'找到了這個。嚴重不好,老兄! – 2012-09-19 14:55:34