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

Reply via email to