使用WebRat检查元素不存在
-
06-07-2019 - |
题
以下工作正常:
Then /^I should see a button called "([^\"]*)"$/ do |name|
response.should have_selector("li") do |li|
li.should have_selector("a") do |a|
a.should contain(name)
end
end
end
现在我需要用这样的步骤补充它:
Then /^I should not see a button called "([^\"]*)"$/ do |name|
[snip...]
end
标准“我不应该看到”不满意,因为它会在页面的任何位置拾取目标短语 - 而不仅仅是在按钮内。我特别需要检查没有带有目标文本的按钮。
我的第一直觉是尝试这样的事情:
Then /^I should see a button called "([^\"]*)"$/ do |name|
response.should have_selector("li") do |li|
li.should have_selector("a") do |a|
a.should_not contain(name)
end
end
end
但是,只要页面上没有包含目标文本的任何按钮,即使还有一个或多个按钮包含目标文本,它也会通过。
你的想法?
非常感谢,
史蒂芬。
解决方案 2
问题解决了!我给了每个控件一类“控制”,然后写了 这一步定义:
Then /^I should not see a control called "([^\"]*)"$/ do |name|
response.should have_selector("a.control", :content => name, :count
=> 0)
end
当然,这假设我很乐意给他们所有的一类 "控制" ...
第
其他提示
您可以使用 assert_not_contain
(也许 not_contain
但我怀疑它,因为它不在 rdoc )。
a.should assert_not_contain(name)
你的按钮实际上是链接吗?对于按钮(有提交值),我使用:
assert_have_selector "input[type=submit][value=\"#{text}\"]"
和
assert_have_no_selector "input[type=submit][value=\"#{text}\"]"
第h
不隶属于 StackOverflow