Couple of ideas for reliable automation

1) watir-webdriver's certain APIs like goto, click waits for the whole page 
to load (document.readyState == 0)  but this definition does not include 
ajax calls
all_ajax_calls_completed = browser.execute_script("return jQuery.active") 
== 0, try if this helps before you interact with the table if you use 
jQuery in your page

2) Ask your developers to create a div tag in the page once the page is 
loaded or the table is loaded. This means you only have to poll on that div 
tag before interacting with the table. This helps for very dynamic pages.

3) We are using a solution where our UI framework will set a tag to true 
once all the html elements, include js are loaded, still this does not help 
with Ajax so we follow 2 & 3 for making our automation reliable

4) Try passing 45 seconds to wait_until_present(45) to increase the timeout 
and see if it helps.
Regards
Ragavan



On Friday, August 1, 2014 11:12:36 PM UTC+1, Lakshya Kapoor wrote:
>
> The issue I am facing is some times the elements take longer than expected 
> to appear on the page. Watir tries to interact with them before they load 
> and fails. I am aware of wait_until_present and when_present methods, but 
> they fail in the scenario I am working on. I have a table that 
> auto-populates rows from the database, but occasionally it takes well over 
> 10 seconds due to performance issues on server or client side.
>
> I want to extract text from the first row when it is present, but 
> sometimes the row element passes my sleep_until_present test, but no text 
> is extracted from the row. Here is my simple 2 step approach with 
> sleep_until_present() method.
>
> 1. Wait until element is !nil.
> 2. Wait until element is present.
>
>   def sleep_until_present(element_name)
>     sleep_timer = 0
>     nil_timer = 0
>     found = nil
>
>     while sleep_timer < 60
>       # Sleep 30s if element is nil
>       while !element_name && nil_timer < 30 
>         break if element_name != nil
>         $log.info "Element is nil. Waiting..."
>         sleep(1)
>         nil_timer += 1
>       end
>
>       if element_name.present?
>         if element_name.locate # If located
>           found = element_name.flash
>           return true if found
>         end
>       end
>
>       sleep(1) # sleep until element is present
>  
>      # Get last 100 chars which includes the element ID
>       element_id = element_name.inspect[-95..-1]
>       $log.info "(#{sleep_timer+1}) Waiting for -> #{element_id}"  
>       sleep_timer += 1
>     end
>
>     return false
>   end
>
> This may not be the best approach, but I am interested in learning how I 
> can approach such situations in a better way.
>
> P.S. New to automated testing. Any constructive criticism is welcome!
>

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to watir-general+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to