【问题标题】:How do you create a collection of tables for ruby/Watir and Page Objects如何为 ruby​​/Watir 和页面对象创建表集合
【发布时间】:2015-05-20 02:57:16
【问题描述】:

我有一个包含一系列动态表格的页面。
我希望能够遍历这些表,将它们转换为哈希(使用 .hashes 方法)并将它们与 .yml 文件中的数据进行比较。 但我似乎无法让集合正常工作。

这是一种尝试(使用虚拟页面):

class ViewOnlyPages
  include PageObject
  page_url("https://developers.google.com/chart/interactive/docs/examples")

  tables(:all_tables, :class =>'google-visualization-table-table')
  def verify_page_against(page_name, dataset)
  #load data from Yml

  #hash spin through all tables (for each table, read each record into hash?)
  self.all_tables.each do |table|
    puts table.hashes
    puts '---'
  end

end

【问题讨论】:

    标签: ruby watir pageobjects page-object-gem


    【解决方案1】:

    tables 访问器方法类似于 elements 访问器方法。创建的方法实际上是all_tables_elements(注意“_elements”部分),而不是创建all_tables 方法。

    换句话说,对表的迭代应该是:

    self.all_tables_elements.each do |table|
      puts table.hashes
      puts '---'
    end
    

    请注意,这实际上不会为示例页面创建任何输出。表格的当前定义假定它们位于主页中。但是,在这种情况下,表格位于 iframe 中。您需要明确说明何时查看 iframe。要获得输出,表应该在in_iframe 块中定义:

    in_iframe(:class => 'framebox') do |frame|
      tables(:all_tables, :class =>'google-visualization-table-table', :frame => frame)
    end
    

    【讨论】:

    • 看起来不错,谢谢。我以前用过你的页面。这是非常有帮助的。我收到有关 Hashes 方法的弃用警告。有什么建议吗?
    • 您使用的是什么版本的页面对象 gem? Table#hashes 方法是刚刚在 v1.0.3(最新版本)中添加的。
    • 我只是追溯了一下。现在更新我的宝石。谢谢!
    猜你喜欢
    • 2020-05-25
    • 2015-06-22
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多