【问题标题】:assert_select first and second html table cell contents in railsassert_select rails 中的第一个和第二个 html 表格单元格内容
【发布时间】:2015-03-24 09:57:54
【问题描述】:

我有以下 html 表格:

<table class="list user_permission">
  <tr>
    <th>Name</th>
    <th>Permission</th>
  </tr>
  <tr id="permission_1">
    <td>
      test user01
    </td>
    <td>
      Reading permission
    </td>
  </tr>
</table>

我想在我的测试中断言我的第一个和第二个表格单元格的内容。我尝试了以下方式:

assert_select "tr#permission_1 td", "test user01"
assert_select "tr#permission_1 td", "Reading permission"

但是没用,找不到这样的入口。

【问题讨论】:

    标签: ruby-on-rails integration-testing assert


    【解决方案1】:

    你可以这样测试:

    assert_select 'table' do
      assert_select 'tr#permission_1' do
        assert_select 'td:nth-child(1)', 'test user01'
        assert_select 'td:nth-child(2)', 'Reading permission'
      end
    end
    

    如果这不起作用,您也可以尝试使用如下正则表达式:

    assert_select 'td:nth-child(1)', /test user01/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-30
      • 2018-06-16
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      相关资源
      最近更新 更多