Re: [wtr-general] testing a page that goes through multiple redirects.

2011-01-20 Thread vishnu
Hi Jarib
   I understand what you mean about not being able to decide what
finished means in general, but tools could be provided to tell me if
something is finished in a specific case.

For example, there has been a lot of discussion about solving the
problems of waiting for ajax requests in general. But when I'm testing
a web application where I have used jquery for example, every time I
do an action that results in an ajax request, I do a Watir::Wait.until
{ @browser.execute_script(return jQuery.active == 0) } so that I
know that all ajax calls are done. I prefer this to a
wait_till_present on an element since I can distinguish between a
failure and a slow ajax request AND because this code is generic to
all my ajax requests.

Ideally in the case of these redirects, I'd like to be able to check
if watir believes the page is loaded AND if no javascript is currently
executing, because I know that in this specific case, on none of my
pages do I have to worry about javascript running on a setTimeout.
Done is well defined in my case. Is it possible for me to check that
my definition of done is true?

On Thu, Jan 20, 2011 at 1:37 AM, Jari Bakken jari.bak...@gmail.com wrote:
 On Wed, Jan 19, 2011 at 8:31 PM, vishnu path...@gmail.com wrote:

 I posted an issue on github and jarib suggested I use something like
 wait_until_present to make sure I'm on the page I expect to be. But I
 have 2 concerns.
 firstly, even with wait_until_present is there a likelyhood I get a
 stale reference error?

 This error only occurs if you're trying to interact with an element
 that is no longer on the page, e.g.

  button = browser.button
  # page refreshes, or the button is removed
  button.click

 I think seeing this error from calling wait_until_present is very
 unlikely. If you do, please create a test case I can look at.

 secondly, sometimes one of these redirects on the way might actually
 fail and throw me onto an error page. In which case I'll have to
 wait_until_present with a timeout.

 As mentioned in the issue, check out the docs for these methods.
 #wait_until_present and friends include a built-in timeout. You can
 pass the number of seconds to wait as the first argument.

 I'd prefer a more deterministic
 approach. Is there a way for me to get watir to check if the current
 page has completely loaded AND all onload scripts have run before
 giving me control? Something I can run in a loop so that the script
 continues only when all redirects are done


 No. Since browsers are inherently asynchronous, there's no way for the
 tool to know what you consider finished. We try to wait for the most
 obvious things, but at some point we have to give control back to the
 user. Consider e.g.

  body onload=setTimeout(someFunction, 1000)

 someFunction could call out to code that does more setTimeout (or
 other async calls) and eventually end up changing elements or
 redirecting to some other page. The most deterministic solution you'll
 get is polling the DOM for the state you want it to be in before
 proceeding, which is what wait.rb in watir-webdriver was designed to
 let you do easily.

 --
 Before posting, please read http://watir.com/support. In short: search before 
 you ask, be nice.

 watir-general@googlegroups.com
 http://groups.google.com/group/watir-general
 watir-general+unsubscr...@googlegroups.com


-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


Re: [wtr-general] testing a page that goes through multiple redirects.

2011-01-20 Thread Jari Bakken
On Thu, Jan 20, 2011 at 12:06 PM, vishnu path...@gmail.com wrote:
 Ideally in the case of these redirects, I'd like to be able to check
 if watir believes the page is loaded AND if no javascript is currently
 executing, because I know that in this specific case, on none of my
 pages do I have to worry about javascript running on a setTimeout.
 Done is well defined in my case. Is it possible for me to check that
 my definition of done is true?

JavaScript is always currently executing - i.e. the event loop is
always running. At no point will the browser throw up its hands and
say all done! - the closest you'll get is polling the document's
readyState property

  browser.execute_script(return document.readyState) == complete

but in my experience, relying on this sort of stuff as a generic
mechanism leads to race conditions and a lot of flaky tests. My
advice: poll for the elements you want to interact with to be there.

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


Re: [wtr-general] testing a page that goes through multiple redirects.

2011-01-20 Thread vishnu
haha I was actually considering this, but here I can see the race
condition where the readystate might be complete before the onload
fires.

Another idea I had was to in a wait block
attachEventListener to document load a function of the form
setTimeout(0, function(){}) and my attached function would set some
element on the page and use watir to check for this element. This way
the element I attach will eventually exist on the correct page or on
any of various error pages.
What do you think of this approach? Are there some pitfalls I'm
missing? If it seems that this too is likely to fail, then I'll just
poll for the elements I expect on the success page as you suggest.

On Thu, Jan 20, 2011 at 4:58 PM, Jari Bakken jari.bak...@gmail.com wrote:
 On Thu, Jan 20, 2011 at 12:06 PM, vishnu path...@gmail.com wrote:
 Ideally in the case of these redirects, I'd like to be able to check
 if watir believes the page is loaded AND if no javascript is currently
 executing, because I know that in this specific case, on none of my
 pages do I have to worry about javascript running on a setTimeout.
 Done is well defined in my case. Is it possible for me to check that
 my definition of done is true?

 JavaScript is always currently executing - i.e. the event loop is
 always running. At no point will the browser throw up its hands and
 say all done! - the closest you'll get is polling the document's
 readyState property

  browser.execute_script(return document.readyState) == complete

 but in my experience, relying on this sort of stuff as a generic
 mechanism leads to race conditions and a lot of flaky tests. My
 advice: poll for the elements you want to interact with to be there.

 --
 Before posting, please read http://watir.com/support. In short: search before 
 you ask, be nice.

 watir-general@googlegroups.com
 http://groups.google.com/group/watir-general
 watir-general+unsubscr...@googlegroups.com


-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


Re: [wtr-general] testing a page that goes through multiple redirects.

2011-01-20 Thread Jari Bakken
On Thu, Jan 20, 2011 at 1:01 PM, vishnu path...@gmail.com wrote:

 Another idea I had was to in a wait block
 attachEventListener to document load a function of the form
 setTimeout(0, function(){}) and my attached function would set some
 element on the page and use watir to check for this element. This way
 the element I attach will eventually exist on the correct page or on
 any of various error pages.
 What do you think of this approach? Are there some pitfalls I'm
 missing? If it seems that this too is likely to fail, then I'll just
 poll for the elements I expect on the success page as you suggest.


Absolutely - if you're able to change the application under test to
provide hooks for the test code to let it know when it's finished,
that's a good solution. From the Ruby side you're still polling the
state of the DOM, but you have more control.

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


[wtr-general] testing a page that goes through multiple redirects.

2011-01-19 Thread vishnu
Hi
   I'm testing an application that integrates with a payment gateway.
This involves about 3 redirects. Each of these is not 302's but a page
that has a form and an onload script that submits the form via
javascript.
The problem is sometimes watir continues before the chain of
redirects. So sometimes the page the browser is on when our script
continues execution is not the last page and the script throws an
error.

sometimes webdriver throws an error because references have become
stale. This is not a reference that I have saved and then used but
just something as simple as @browser.text.should include('some text')

we get errors like
Unable to locate element: {method:tag name,selector:body}
 # [remote server]
file:///private/var/folders/W5/W5PGX-JAH0KpXOjqG8XwgTM/-Tmp-/webdriver-profile20110119-41715-1iz0tqc/extensions/fxdri...@googlecode.com/resource/modules/utils.js:7081:in
`WebDriverError'

or

 Element not found in the cache
 # [remote server]
file:///private/var/folders/W5/W5PGX-JAH0KpXOjqG8XwgTM/-Tmp-/webdriver-profile20110119-40433-14jajfa/extensions/fxdri...@googlecode.com/resource/modules/utils.js:7081:in
`WebDriverError'
 # [remote server]
file:///private/var/folders/W5/W5PGX-JAH0KpXOjqG8XwgTM/-Tmp-/webdriver-profile20110119-40433-14jajfa/extensions/fxdri...@googlecode.com/resource/modules/utils.js:7198:in
`'


I posted an issue on github and jarib suggested I use something like
wait_until_present to make sure I'm on the page I expect to be. But I
have 2 concerns.
firstly, even with wait_until_present is there a likelyhood I get a
stale reference error?
secondly, sometimes one of these redirects on the way might actually
fail and throw me onto an error page. In which case I'll have to
wait_until_present with a timeout. I'd prefer a more deterministic
approach. Is there a way for me to get watir to check if the current
page has completely loaded AND all onload scripts have run before
giving me control? Something I can run in a loop so that the script
continues only when all redirects are done

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


Re: [wtr-general] testing a page that goes through multiple redirects.

2011-01-19 Thread Jari Bakken
On Wed, Jan 19, 2011 at 8:31 PM, vishnu path...@gmail.com wrote:

 I posted an issue on github and jarib suggested I use something like
 wait_until_present to make sure I'm on the page I expect to be. But I
 have 2 concerns.
 firstly, even with wait_until_present is there a likelyhood I get a
 stale reference error?

This error only occurs if you're trying to interact with an element
that is no longer on the page, e.g.

  button = browser.button
  # page refreshes, or the button is removed
  button.click

I think seeing this error from calling wait_until_present is very
unlikely. If you do, please create a test case I can look at.

 secondly, sometimes one of these redirects on the way might actually
 fail and throw me onto an error page. In which case I'll have to
 wait_until_present with a timeout.

As mentioned in the issue, check out the docs for these methods.
#wait_until_present and friends include a built-in timeout. You can
pass the number of seconds to wait as the first argument.

 I'd prefer a more deterministic
 approach. Is there a way for me to get watir to check if the current
 page has completely loaded AND all onload scripts have run before
 giving me control? Something I can run in a loop so that the script
 continues only when all redirects are done


No. Since browsers are inherently asynchronous, there's no way for the
tool to know what you consider finished. We try to wait for the most
obvious things, but at some point we have to give control back to the
user. Consider e.g.

  body onload=setTimeout(someFunction, 1000)

someFunction could call out to code that does more setTimeout (or
other async calls) and eventually end up changing elements or
redirecting to some other page. The most deterministic solution you'll
get is polling the DOM for the state you want it to be in before
proceeding, which is what wait.rb in watir-webdriver was designed to
let you do easily.

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com