![](/img/trans.png)
[英]How to verify web text while excluding random vars with ruby/watir
[英]Watir: How to verify text is NOT present in web page
我正在編寫一個刪除記錄的測試,我需要在刪除后驗證記錄是否已不存在。 我知道如何驗證記錄文本存在於網頁,以“browser.text.include?”,但沒有辦法,我可以驗證該文本不存在,而不是一個辦法嗎? 如果文本在被刪除之后仍然存在,我需要測試失敗。 我搜索過,但我搜索到的唯一點擊告訴我如何驗證文本是否存在 - 這與我需要的相反。
非常感謝你。
browser.text.include? 返回一個布爾值(實際上是一個truetype或falsetype,但這不是討論的時間),所以否定它將反轉你的搜索。
do_a_faily_thing if not browser.text.include? "badgers are eating my face"
您可以根據自己的需要自定義。 PS。 這基本上是ry的答案,只有吃面子的獾。
根據Chuck的建議添加了歷史興趣:
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?("my string")
或者取決於您使用的測試框架
# RSpec and/or Cucumber
browser.text.include?("my string").should != true
# TestUnit
assert(browser.text.include?("my string") != true)
如果記錄是包裝HTML元素,使用存在? 方法是驗證存在的另一種方法。
刪除記錄(樣本)
<p class='foo'>bar</p>
檢查腳本
p(:class,'foo').exist?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.