Question

I am using the page object gem with Watir-webdriver. Here, I am using "populate_page_with" feature which i am unable to use it when there is some wait for an element to load.

In Below script, I should enter details for :sum_ctgy, :sd and :foregin then i should wait for :sumc to visible. I am using populate_page_with data_for method with data as follows in the yml file

sumdetailspage:
  sum_ctgy: Test1
  sd: Test2
  sumc: 502
  sumd: -450

Please tell me a better approach to solve this problem with using the populate method.

 class SumDetailsPage
  include PageObject
  include DataMagic

  select_list(:sum_ctgy, :name => /categoryDescription/) --> send details
  text_field(:sd, :id => /sumDestination/) --> continue
  text_field(:foreign, :name => /foreignSymbol/) --> continue
  div(:pw, :id => /PleaseWaitMessage/) --> please wait behavior to complete(until hidden)
  text_field(:sumc, :id => /sumCalc/) --> then continue, but it is not waiting for this element to load
  text_field(:sumd, :id => /sumCalcdep/)

  def train_details(data = {})
    DataMagic.load('traindata.yml')
    populate_page_with data_for(:sumdetailspage, data)
    pw_element.when_not_visible  --> wait
    populate_page_with data_for(:sumdetailspage, data) --> again continue...
  end
end
Was it helpful?

Solution

I would suggest providing a block for the sumc element so that it always waits for the message to disappear. This is beneficial in that any interaction with the text field will always wait - ie if you are setting, getting, etc.

text_field(:sumc){ 
  pw_element.when_not_visible
  text_field_element(:id => /sumCalc/)
}

You can then use populate_page_with as you would normally.

Note: This assumes that you are using Ruby 1.9+ where the insertion order into hash is maintained - ie page_populate_with will input the :sum_ctgy, :sd and :foregin then :sumc (and assuming that is the order you specify them in).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top