4

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.

Kim Wilkinson
  • 85
  • 1
  • 1
  • 7
  • 2
    Couldn't you just check the negation? E.g. Assert.IsFalse(ie.ContainsText("Foo", "Record did not get deleted.") – nithins Apr 13 '11 at 16:19

4 Answers4

4

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
kinofrost
  • 768
  • 6
  • 16
  • 1
    Aha, thank you both! I used parts of each - I set it up to if browser.text.include? "badgers are eating my face" = true then Do A Faily Thing, else continue with the script. That worked fine! – Kim Wilkinson Apr 14 '11 at 17:27
  • 1
    I normally don't like 'unless' but in this case I'd argue it reads better than 'if not'. @Kim, what @kinofrost gives here is basically the ruby way of doing just what you are saying.. it just puts the operation first, then the condition under which to perform the operation. – Chuck van der Linden Apr 14 '11 at 22:33
  • @Kim, glad to hear via your comment that we were able to help you. Even better however both in terms of giving credit to those who supplied the answers you needed, and identifying the 'right' answers to other readers, is to 'accept' the answer(s) that worked for you. (upticking them is also nice, but the big green check-mark when an answer is accepted is what gives credit to those who answered, and identifies the working answers to others) – Chuck van der Linden Apr 15 '11 at 18:56
2

How about:

   !browser.text.include?("my string")
ry.
  • 7,885
  • 1
  • 20
  • 10
  • I tried this one and it keeps telling me it's not getting what it expects when the script gets to the quotes. Ticked me off because this should've worked. – Kim Wilkinson Apr 14 '11 at 17:30
2

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)
Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43
0

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?