[英]How do you create a collection of tables for ruby/Watir and Page Objects
我有一個包含一系列動態表的頁面。
我希望能夠遍歷這些表,將它們轉換為Hash(使用.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
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.