3

我正在使用带有 Watir-webdriver 的页面对象 gem。在这里,我正在使用“populate_page_with”功能,当有一些等待元素加载时我无法使用它。

在下面的脚本中,我应该输入详细信息:sum_ctgy:sd然后:foregin我应该等待:sumc可见。我在 yml 文件中使用 populate_page_with data_for 方法,数据如下

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

请告诉我使用填充方法解决此问题的更好方法。

 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
4

1 回答 1

3

我建议为 sumc 元素提供一个块,以便它始终等待消息消失。这是有益的,因为与文本字段的任何交互都将始终等待 - 即,如果您正在设置、获取等。

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

然后,您可以像往常一样使用 populate_page_with。

注意:这假设您使用的是 Ruby 1.9+,其中维护哈希的插入顺序 -page_populate_with即将输入 :sum_ctgy、:sd 和 :foregin 然后 :sumc (并假设这是您指定它们的顺序)。

于 2013-11-22T13:56:17.207 回答