Cucumber 验证表中的空单元格

Cucumber 验证表中的空单元格,cucumber,watir,watir-webdriver,page-object-gem,rspec-expectations,Cucumber,Watir,Watir Webdriver,Page Object Gem,Rspec Expectations,您能建议一些脚本来验证表格单元格中的空值吗?我需要确认表中没有空单元格 tableFG = page.table(:id => 'FinancialsGrid') tableFG.rows.each do |row| row.cells.each do |cell| expect(cell.tableFG_element.text).should_not be_nil end end 可能还有另一种检查空值的方法。对于手动编写循环来迭代并验证每个单元格,我不喜欢的一点是,

您能建议一些脚本来验证表格单元格中的空值吗?我需要确认表中没有空单元格

tableFG = page.table(:id => 'FinancialsGrid')
tableFG.rows.each do |row|
  row.cells.each do |cell|
    expect(cell.tableFG_element.text).should_not be_nil
  end
end

可能还有另一种检查空值的方法。

对于手动编写循环来迭代并验证每个单元格,我不喜欢的一点是,您只看到第一次失败的结果。如果有两个空白单元格,则测试失败仅显示一个单元格

因此,我尝试使用内置的期望匹配器来检查每个元素(例如
all
)。例如,下面获取每个单元格的文本长度,并确保其长度至少为1个字符。请注意,Watir会去除前导/尾随空格,因此长度1应该是实际字符

financials_grid = browser.table(:id => 'FinancialsGrid')
expect(financials_grid.tds.map(&:text).map(&:length)).to all( be > 0 )
失败的预期如下所示,包括每个失败的单元格:

expected [1, 0, 0, 1] to all be > 0

object at index 1 failed to match:
expected: > 0
got:   0

object at index 2 failed to match:
expected: > 0
got:   0
使用页面对象gem类似(方法略有不同)。假设该表在页面中定义为
财务网格

page = MyPage.new(browser)
expect(
    page.financials_grid_element.cell_elements.map(&:text).map(&:length)
).to all( be > 0 )

伟大的谢谢你,贾斯汀。比我想象的要好。即使我有一个空的手机,它已经很糟糕了。所以,即使找到一个空单元格也不坏,因为不应该没有一个空单元格。