Watir:如何验证网页中不存在文本

发布于 2024-11-01 19:14:27 字数 239 浏览 1 评论 0原文

我正在编写一个删除记录的测试,并且我需要验证该记录在删除后是否不再存在。我知道如何使用“browser.text.include?”验证页面中存在记录文本,但是有没有办法可以验证该文本不存在 代替现在?如果文本在据称被删除后仍然存在,我需要测试失败。 我已经搜索过,但搜索到的唯一结果告诉我如何验证文本是否存在 - 这与我需要的相反。

非常感谢。

I'm writing a test where I delete a record, and I need to verify that the record is no longer present after I've deleted it. I know how to verify the record text is present in a page, with "browser.text.include?", but is there a way that I can verify that the text is not present instead? I need the test to fail if the text is still present after it's supposedly been deleted.
I've searched but the only hits I get on search tell me how to verify text is present - which is the opposite of what I need.

Thank you very much.

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

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

发布评论

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

评论(4

离线来电— 2024-11-08 19:14:27

浏览器.文本.包括?返回一个布尔值(实际上是 truetype 或 falsetype,但现在不是讨论的时候),因此否定它会反转您的搜索。

do_a_faily_thing if not browser.text.include? "badgers are eating my face"

请随意根据您自己的需求进行定制。附言。这基本上是 ry 的答案,只是针对食脸獾。

根据查克的建议,出于历史兴趣而添加:

do_a_faily_thing unless browser.text.include? "face-eating-badger-eating-badgers are eating my face-eating badgers"

添加以显示“其他”示例:

if browser.text.include? "badgers are eating my face"
   do_a_thing
else
   phew_no_badgers
end

browser.text.include? returns a boolean value (actually a truetype or a falsetype, but this isn't the time for that discussion), so negating it will inverse your search.

do_a_faily_thing if not browser.text.include? "badgers are eating my face"

Feel free to customise for your own needs. PS. This is basically ry's answer, only with face-eating badgers.

Added for historical interest, from Chuck's suggestion:

do_a_faily_thing unless browser.text.include? "face-eating-badger-eating-badgers are eating my face-eating badgers"

Added to show an "else" example:

if browser.text.include? "badgers are eating my face"
   do_a_thing
else
   phew_no_badgers
end
如痴如狂 2024-11-08 19:14:27

怎么样:

   !browser.text.include?("my string")

How about:

   !browser.text.include?("my string")
相思故 2024-11-08 19:14:27

或者取决于您使用的测试框架

# RSpec and/or Cucumber
browser.text.include?("my string").should != true

# TestUnit
assert(browser.text.include?("my string") != true)

or depending on what testing framework you are using

# RSpec and/or Cucumber
browser.text.include?("my string").should != true

# TestUnit
assert(browser.text.include?("my string") != true)
哑剧 2024-11-08 19:14:27

如果记录是包裹HTML元素,使用exists?方法是验证存在性的另一种方法。

已删除记录(示例)

<p class='foo'>bar</p>

检查脚本

p(:class,'foo').exist?

If the record is wrapped HTML element, using exist? method is the another way to verify existence.

deleted record (sample)

<p class='foo'>bar</p>

check script

p(:class,'foo').exist?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文