在rails中assert_select第一个和第二个html表格单元格内容

2024-02-29

我有以下 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"

但没有成功,找不到这样的条目。


你可以这样测试:

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/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在rails中assert_select第一个和第二个html表格单元格内容 的相关文章

随机推荐