黄瓜 +网络老鼠 + selenium,如何忽略隐藏文本?

发布于 2024-08-16 03:46:23 字数 315 浏览 4 评论 0原文

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

环境:cucumber 0.3.11,selenium-client 1.2.17,webrat 0.6.0

谢谢。

I am using Cucumber, webrat and selenium to test a web application. I use 'I should see "something"' to verify changes. However, in many places, text to be verified only changes from hidden to visible (this might be caused by removing 'hidden' class from itself or one of its ancestors). In this case, above test does not actually verify the change. I am trying to use 'response.should_not have_tag("div#myId.hidden")', which does not work. What is the recommended way to test this?

Environment: cucumber 0.3.11, selenium-client 1.2.17, webrat 0.6.0

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不打扰别人 2024-08-23 03:46:23

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

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 I should see "something",而应使用 Then the element matches by "something" should bevisible

For cases as these I use those two custom steps:

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

Put those into a Ruby file under step_definitions/ directory.

So, in your case, instead of Then I should see "something" use Then the element matched by "something" should be visible.

随心而道 2024-08-23 03:46:23

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

Does it work when using have_selector("div#myId.hidden") instead?

禾厶谷欠 2024-08-23 03:46:23

接受的解决方案不适用于以下环境:
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

The accepted solution does not work with the following environment:
Rails (3.0.0), webrat (0.7.3) selenium-client (1.2.18), cucumber (0.10.)

The solution that works, with the example provided in the answer is now:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文