使用黄瓜水豚测试kendoGrid数据

时间:2013-11-19 15:38:10

标签: selenium kendo-ui cucumber capybara kendo-grid

我正在尝试编写一些黄瓜/水豚测试来验证KendoGrid UI组件中的数据,并且在确定如何选择和验证页面上的数据方面遇到了一些麻烦。

我已经找到了关于使用表格数据的黄瓜/水豚的基本教程和示例,但看起来KendoGrid利用了它的表格和数据的略有不同的配置,其中1.)没有“id”可以轻松选择网格在页面和2.)有多个表(一个用于标题),另一个用于实际数据本身。

以下是我想检查的当前kendoGrid数据的摘录:

<div id="item_grid" data-role="grid" class="k-grid k-widget k-secondary" style="">
  <div class="k-grid-header" style="padding-right: 17px;">
    <div class="k-grid-header-wrap">
      <table role="grid">
        <colgroup>
          <col>
          <col>
          <col>
        </colgroup>
        <thead>
          <tr>
            <th role="columnheader" data-field="ItemA" data-title="Item A" class="k-header" data-role="sortable">
              <a class="k-link" href="#">Item A</a>
            </th>
            <th role="columnheader" data-field="ItemB" data-title="Item B" class="k-header" data-role="sortable">
              <a class="k-link" href="#">Item B</a>
            </th>
            <th role="columnheader" data-field="ItemC" data-title="Item C" class="k-header" data-role="sortable">
              <a class="k-link" href="#">Item C</a>
            </th>
          </tr>
        </thead>
      </table>
    </div>
  </div>
  <div class="k-grid-content">
  <table role="grid">
    <colgroup>
      <col>
      <col>
      <col>
    </colgroup>
    <tbody>
      <tr data-uid="2c77ea57-50ea-474d-950a-8379b3690936" role="row">
        <td role="gridcell">A</td>
        <td role="gridcell">223.63</td>
        <td role="gridcell">0</td>
      </tr>
      <tr class="k-alt" data-uid="979534bc-7dea-47e9-9471-088c5bffe5b5" role="row">
        <td role="gridcell">B</td>
        <td role="gridcell">223.63</td>
        <td role="gridcell">180</td>
      </tr>
      <tr data-uid="4d4c31e7-4daf-44ad-b6c1-20ffdfde57c4" role="row">
        <td role="gridcell">C</td>
        <td role="gridcell">143.58</td>
        <td role="gridcell">0</td>
      </tr>
      <tr class="k-alt" data-uid="8d315558-b014-4219-b21b-dbe52cc6dd18" role="row">
        <td role="gridcell">D</td>
        <td role="gridcell">143.58</td>
        <td role="gridcell">180</td>
      </tr>
    </tbody>
  </table>
  </div>
</div>

开始编写测试以涵盖这种情况的最佳位置在哪里?

我已经完成了Telerik Test Studio的一些额外播放,并且在该应用程序中测试这个特定场景非常简单!

1 个答案:

答案 0 :(得分:1)

一种方法是使用以下方法将数据表收集到2D数组中:

data_rows = page.all(:css, 'div#item_grid div.k-grid-content tr')
data = data_rows.collect do |tr|
  tr.all(:css, 'td').collect(&:text)
end
p data
#=> [["A", "223.63", "0"], ["B", "223.63", "180"], ["C", "143.58", "0"], ["D", "143.58", "180"]]

然后使用数据(并假设您知道表中应该包含哪些数据),您可以验证数据数组:

# If you want to validate the entire table and row order matters:
expect(data).to eql([["A", "223.63", "0"], ["B", "223.63", "180"], ["C", "143.58", "0"], ["D", "143.58", "180"]])

# If you want to validate the entire table and row order does not matter:
expect(data).to match_array([["B", "223.63", "180"], ["A", "223.63", "0"], ["D", "143.58", "180"], ["C", "143.58", "0"]])    

# If you want to validate a specific row exists:
expect(data).to include(["B", "223.63", "180"])