Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir: How to verify text is NOT present in web page

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.

like image 872
Kim Wilkinson Avatar asked Feb 25 '23 12:02

Kim Wilkinson


1 Answers

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
like image 94
kinofrost Avatar answered Mar 03 '23 13:03

kinofrost