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