有一个ExtJS的ListView表格如下,如何用Cucumber代码来测试?
| A Sample Table |
|-------------------------------------------------------------------------|
| Date | Ruby | Volume | Duration | Count | Average | Facebook | Google |
| 201205 | 30 | 12 | 10 | 234 | 10 | 1234 | 4567 |
| 201206 | 50 | 22 | 30 | 3435 | 20 | 4321 | 2222 |
首先在.feature文件中编写如下的代码:
Then I should see the table "A Sample Table" with following data:
| Date | Ruby | Volume | Duration | Count | Average | Facebook | Google |
| 201205 | 30 | 12 | 10 | 234 | 10 | 1234 | 4567 |
| 201206 | 50 | 22 | 30 | 3435 | 20 | 4321 | 2222 |
然后编写steps文件,增加如下代码,方法是通过查找对应表格标题,然后查找对应节点的父节点,再向下查找表格数据内容节点来实现的:
Then /^I should see the table "([^"]*)" with following data:$/ do |text, table|
node = page.find('span.x-panel-header-text', :text => text)
nodes = node.find(:xpath, ".//..//..//..//..//..").all('td.x-grid-cell')
page_data = []
nodes.each { |n| page_data << n.text }
table_data = []
table.rows.each { |row| table_data += row }
table_data.should == page_data
end
评论