4

我正在使用 Cucumber、webrat 和 selenium 来测试 Web 应用程序。我使用'我应该看到“某些东西” '来验证更改。但是,在许多地方,要验证的文本只会从隐藏变为可见(这可能是由于从自身或其祖先之一中删除了“隐藏”类所致)。在这种情况下,上述测试实际上并未验证更改。我正在尝试使用'response.should_not have_tag("div#myId.hidden")',它不起作用。推荐的测试方法是什么?

环境:黄瓜 0.3.11,selenium-client 1.2.17,webrat 0.6.0

谢谢你。

4

3 回答 3

5

对于这些情况,我使用这两个自定义步骤:

Then /^the element matched by "([^\"]*)" should be visible$/ do |locator|
  selenium.should be_visible(locator)
end

Then /^the element matched by "([^\"]*)" should not be visible$/ do |locator|
  selenium.should_not be_visible(locator)
end

将它们放入 step_definitions/ 目录下的 Ruby 文件中。

所以,在你的情况下,不是Then 我应该看到 "something"使用Then 与 "something" 匹配的元素应该是可见的。

于 2009-12-31T18:17:55.303 回答
3

改为使用 have_selector("div#myId.hidden") 时是否有效?

于 2009-12-31T18:18:18.483 回答
1

接受的解决方案不适用于以下环境:Rails (3.0.0)、webrat (0.7.3) selenium-client (1.2.18)、cucumber (0.10.)

有效的解决方案,答案中提供的示例现在是:

Then /^the element matched by "([^\"]*)" should be visible$/ do |locator|
  selenium.is_visible(locator).should be_true
end

Then /^the element matched by "([^\"]*)" should not be visible$/ do |locator|
  selenium.is_visible(locator).should_not be_true
end
于 2011-01-28T00:55:50.330 回答