Question:
I am trying to work out a method to check the content of an HTML table with Watir-webdriver. Basically I want to validate the table contents against a saved valid table (CSV file) and they are the same after a refresh or redraw action.
Ideas I've come up with so far are to:
- Grab the table HTML and compare that as a string with the baseline value.
- Iterate through each cell and compare the HTML or text content.
- Generate a 2D array representation on the table contents and do an array compare.
What would be the fastest/best approach? Do you have insights on how you handled a similar problem?
Here is an example of the table:
<table id="attr-table">
<thead>
<tr><th id="attr-action-col"><input type="checkbox" id="attr-action-col_box" class="attr-action-box" value=""></th><th id="attr-scope-col"></th><th id="attr-workflow-col">Status</th><th id="attr-type-col"></th><th id="attr-name-col">Name<span class="ui-icon ui-icon-triangle-1-n"></span></th><th id="attr-value-col">Francais Value</th></tr></thead>
<tbody>
<tr id="attr-row-209"><td id="attr_action_209" class="attr-action-col"><input type="checkbox" id="attr_action_209_box" class="attr-action-box" value=""></td><td id="attr_scope_209" class="attr-scope-col"><a href="#" class="ws-invoke-editor" id="attr_scope_209_a"><img src="images/attrib_bullet_global.png" title="global"></a></td><td id="attr_workflow_209" class="attr-workflow-col"></td><td id="attr_type_209" class="attr-type-col"><a href="#" class="ws-invoke-editor" id="attr_type_209_a"><img src="images/attrib_text.png"></a></td><td id="attr_name_209" class="attr-name-col"><a href="#" class="ws-invoke-editor" id="attr_name_209_a">Name of: Catalogue</a></td><td id="attr_value_209" class="attr-value-col"><a href="#" class="ws-invoke-editor lang_10" id="attr_value_209_a"><p class="acms ws-editable-content lang_10">2010 EI-176</p></a></td></tr>
<tr id="attr-row-316"><td id="attr_action_316" class="attr-action-col"><input type="checkbox" id="attr_action_316_box" class="attr-action-box" value=""></td><td id="attr_scope_316" class="attr-scope-col"><a href="#" class="ws-invoke-editor" id="attr_scope_316_a"><img src="images/attrib_bullet_global.png" title="global"></a></td><td id="attr_workflow_316" class="attr-workflow-col"></td><td id="attr_type_316" class="attr-type-col"><a href="#" class="ws-invoke-editor" id="attr_type_316_a"><img src="images/attrib_text.png"></a></td><td id="attr_name_316" class="attr-name-col"><a href="#" class="ws-invoke-editor" id="attr_name_316_a">_[Key] Media key</a></td><td id="attr_value_316" class="attr-value-col"><a href="#" class="ws-invoke-editor lang_10" id="attr_value_316_a"><p class="acms ws-editable-content lang_10"><span class="acms acms-choice" contenteditable="false" id="568">163</span></p></a></td></tr>
<tr id="attr-row-392"><td id="attr_action_392" class="attr-action-col"><input type="checkbox" id="attr_action_392_box" class="attr-action-box" value=""></td><td id="attr_scope_392" class="attr-scope-col"><a href="#" class="ws-invoke-editor" id="attr_scope_392_a"><img src="images/attrib_bullet_global.png" title="global"></a></td><td id="attr_workflow_392" class="attr-workflow-col"></td><td id="attr_type_392" class="attr-type-col"><a href="#" class="ws-invoke-editor" id="attr_type_392_a"><img src="images/attrib_numeric.png"></a></td><td id="attr_name_392" class="attr-name-col"><a href="#" class="ws-invoke-editor" id="attr_name_392_a">_[Key] Numéro d'ordre</a></td><td id="attr_value_392" class="attr-value-col"><a href="#" class="ws-invoke-editor lang_10" id="attr_value_392_a"><p class="acms ws-editable-content lang_10">2</p></a></td></tr>
</tbody>
</table>
Answers
1:
ust one idea I came up with. I used Hash and Class object instead of 2D array.
foo.csv
209,global,text.Catalogue,2010 EI-176
392,global,numeric,Numéro d'ordre,2
require 'csv'
expected_datas = CSV.readlines('foo.csv').map do |row|
{
:id => row[0],
:scope => row[1],
:type => row[2],
:name => row[3],
:value => row[4]
}
end
class Data
attr_reader :id,:scope,:type,:name,:value
def initialize(tr)
id = tr.id.slice(/attr-row-([0-9]+)/,1)
scope = tr.td(:id,/scope/).img.src.slice(/attr_bullet_(.+?).png/,1)
type = tr.td(:id,/type/).img.src.slice(/attrib_(.+?).png/,1)
name = tr.td(:id,/name/).text
value = tr.td(:id,/value/).text
end
end
browser = Watir::Browser.new
browser.goto 'foobar'
datas = browser.table(:id,'attr-table').tbody.trs.map{|tr| Data.new(tr)}
datas.zip(expected_datas).each do |data,expected_data|
Data.instance_methods(false).each do |method|
data.send(method).should == expected_data[method.to_sym]
end
end
# something action (refresh or redraw action)
browser.refresh
after_datas = browser.table(:id,'attr-table').tbody.trs.map{|tr| Data.new(tr)}
datas.zip(after_datas).each do |data,after_data|
Data.instance_methods(false).each do |method|
data.send(method).should == after_data.send(method)
end
end
2:
You could go for exact match
before_htmltable <=> after_htmltable
Or you could strip whitespace
before_htmltable.gsub(/\s+/, ' ') <=> after_htmltable.gsub(/\s+/, ' ')
I would think that creating the array then comparing each element would be more expensive.
Dave
分享到:
相关推荐
BRAIN STORMING头脑风暴法运用实务.ppt
EMS内训07 QCC品管圈培训Brain Storming.pptx
EventStorming
残本秘籍在手,可尽破天下武功! 还在等什么,赶紧来成为风暴战士吧! 请移步以下位置,以支持正版 https://leanpub.com/introducing_eventstorming
Software Architecture for Developers is a practical and pragmatic guide to modern software architecture, specifically aimed at software developers....How to identify risks with risk-storming.
COLLABORATIVE LEARNING FOR COMPLEX DOMAINS EventStorming is a workshop format for quickly exploring complex business domains.
学生信息管理系统 图形用户界面(GUI) java 实现对数据库的操作 数据库用的mysql_hurricane&&storming的博客-CSDN博客_学生信息管理系统界面.html
EventStorming词汇表和备忘单 EventStorming是超越孤岛边界进行协作的最明智的方法。 EventStorming的强大功能来自一个多元化,多学科的群体,他们在一起拥有很多智慧和知识。 虽然最初是为为领域驱动的设计聚合建模...
EventStorming是一种基于研讨会的方法,可以快速找出软件程序领域中正在发生的事情。[1] 与其他方法相比,它非常轻巧,并且不需要计算机的有意支持。 结果以宽墙的粘滞便笺表示。 业务流程被“冲出”为一系列域事件...
P M : M A R C H - A P R I L 2 0 0 3Patnode is a Professor of Program Management and Leadership at the Defense Acquisition University, Fort Belvoir, Va.T E A M D E V E L O P M E N T M O D E LCan't Get ...
本备忘单旨在为准备和推动Event Storming Workshop提供简短的总结。 它不打算对该主题进行完整的介绍,需要有关 DDD 和事件风暴的先验知识才能负责任地使用本文档。所需材料纸卷来创建造型表面。 可在宜家 (Mala, ...
使用通过Event Storming提供的域驱动设计方法,它可以帮助减少项目团队中每个人理解业务域模型所花费的时间。 理论与实践:现实世界中的学习案例 经历所有学习过程,在AWS上开发->构建->部署工件 目录 事件风暴 ...
A curated list of Domain-Driven Design (DDD), Command Query Responsibility Segregation (CQRS), Event Sourcing, and Event Storming resources.
Web日志攻坚是一个互动的Web服务器日志文件分析器(IIS,Apache和Nginx的)的Windows。
事件用户界面项目设置npm install编译和热重装以进行开发npm run serve编译并最小化生产npm run build运行测试npm run test整理和修复文件npm run lint自定义配置请参阅。
-제-음식배달 在MSA / DDD / Event Storming / EDA中运行的产品。 는이티브이티브리케이션의포함합니기포함합니다... 주문은일일365일일일A A A A A A A A A A异步(事件驱动),最终一致性 电路断路器,后备电源 성능
网站访问日志分析软件(Dataland Web Log Storming Professional)是一款功能强大的网站访问日志分析软件,除了生成普通的网站日志报告以外,软件还能够让你逐字地浏览网站统计信息,通过点击感兴趣的图表和清单就能...
送餐样例 此示例配置为涵盖分析/设计/实现/操作的所有阶段,包括MSA / DDD /事件触发/ EDA。 它包括示例答案,以通过开发本地云应用程序所需的检查点。 检查点: : 目录 [服务场景](#服务场景) ...
使用通过Event Storming提供的域驱动设计方法,它可以帮助减少项目团队中每个人理解业务域模型所花费的时间。 理论与实践:现实世界中的学习案例经历所有学习过程,在AWS上开发->构建->部署工件目录事件风暴什么是...
Introducing Starling Building GPU Accelerated Applications 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除