[wtr-general] Re: Example of assertions

2009-11-13 Thread QAguy

Can you give me an example of code (generic example) that would allow
be to check if a piece of text is visible on not on the browser page?

Thanks in advance

On Nov 12, 5:38 pm, Ethan notet...@gmail.com wrote:
 This is incorrect. #text returns a string, not an element, and it has no
 #visible? method.
 The simplest way is if you know the container the text is on, is to get a
 reference to that container and call #visible? on that.
 checking browser.text.include?(some_string) probably won't work, because
 #text returns all text even if it's not visible.

 On Thu, Nov 12, 2009 at 17:16, Tiffany Fodor tcfo...@comcast.net wrote:

  Ah - I didn't realize this, but you need to require it:

  require 'watir/contrib/visible'

  -Tiffany

  On Nov 12, 3:08 pm, QAguy qablogm...@gmail.com wrote:
   I try something like this:

   @browser.text.visible?(Preparing to Optimize).should == false

   but I get:

   undefined method `visible?' for #String:0x1032d3ad0

   I'm working with Safariwatir.

   Thanks
   QAguy

   On Nov 12, 4:22 pm, Tiffany Fodor tcfo...@comcast.net wrote:

Oops, sorry - to see if text is visible, use:

ie.text('My Text').visible?

On Nov 12, 2:09 pm, QAguy qablogm...@gmail.com wrote:

 Does anyone have examples of assertions. For example how would I
 assert that text on a page in either visible or invisible.

 Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: Example of assertions

2009-11-13 Thread Ethan
That is a tricky question. There are two much easier questions which may
help you.
1. Does the piece of text exist on the page? If being visible is synonymous
with existing on your page, it is much easier, and the
browser.text.include?(piece_of_text) code will work. But it sounds like this
doesn't apply to you, so moving on:
2. Knowing that the text in question is contained within a particular div,
span, whatever which may or may not be visible, is that div/span/whatever
visible? You can get the element containing the text by the usual watir
methods, which I hope are familiar to you (if not, check the cheat sheet,
http://wiki.openqa.org/display/WTR/Cheat+Sheet ).

If those won't work out for you, then the best I can think of is iterating
recursively down through elements of the page and checking if it contains
the text, thereby finding the smallest container of the text, and checking
#visible? on that container. This is possible in watir, but tricky, and I am
not particularly inclined to try to hack up some sample code for it. but
here's some pseudocode:

def smallest_container_with_text(container, text)
  iterate over the children of container do |child|
if child.text.include?(text)
  return smallest_container_with_text(child, text)
end
  end
  # if we didn't return a child, return self if self includes the text
  return self.text.include?(text) ? self : nil
end
container=smallest_container_with_text(browser, Preparing to Optimize)
text_is_visible=container  container.visible?

the iterating over children is the tricky part. not sure how to do that with
watir currently.

-Ethan

On Fri, Nov 13, 2009 at 11:40, QAguy qablogm...@gmail.com wrote:


 Can you give me an example of code (generic example) that would allow
 be to check if a piece of text is visible on not on the browser page?

 Thanks in advance

 On Nov 12, 5:38 pm, Ethan notet...@gmail.com wrote:
  This is incorrect. #text returns a string, not an element, and it has no
  #visible? method.
  The simplest way is if you know the container the text is on, is to get a
  reference to that container and call #visible? on that.
  checking browser.text.include?(some_string) probably won't work, because
  #text returns all text even if it's not visible.
 
  On Thu, Nov 12, 2009 at 17:16, Tiffany Fodor tcfo...@comcast.net
 wrote:
 
   Ah - I didn't realize this, but you need to require it:
 
   require 'watir/contrib/visible'
 
   -Tiffany
 
   On Nov 12, 3:08 pm, QAguy qablogm...@gmail.com wrote:
I try something like this:
 
@browser.text.visible?(Preparing to Optimize).should == false
 
but I get:
 
undefined method `visible?' for #String:0x1032d3ad0
 
I'm working with Safariwatir.
 
Thanks
QAguy
 
On Nov 12, 4:22 pm, Tiffany Fodor tcfo...@comcast.net wrote:
 
 Oops, sorry - to see if text is visible, use:
 
 ie.text('My Text').visible?
 
 On Nov 12, 2:09 pm, QAguy qablogm...@gmail.com wrote:
 
  Does anyone have examples of assertions. For example how would I
  assert that text on a page in either visible or invisible.
 
  Thanks
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---



[wtr-general] Re: Example of assertions

2009-11-12 Thread Tiffany Fodor

Ah - I didn't realize this, but you need to require it:

require 'watir/contrib/visible'

-Tiffany

On Nov 12, 3:08 pm, QAguy qablogm...@gmail.com wrote:
 I try something like this:

 @browser.text.visible?(Preparing to Optimize).should == false

 but I get:

 undefined method `visible?' for #String:0x1032d3ad0

 I'm working with Safariwatir.

 Thanks
 QAguy

 On Nov 12, 4:22 pm, Tiffany Fodor tcfo...@comcast.net wrote:

  Oops, sorry - to see if text is visible, use:

  ie.text('My Text').visible?

  On Nov 12, 2:09 pm, QAguy qablogm...@gmail.com wrote:

   Does anyone have examples of assertions. For example how would I
   assert that text on a page in either visible or invisible.

   Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---