assert_select first and second html table cell contents in rails

十年热恋 提交于 2019-12-10 21:45:36

问题


I have the following html table:

<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>

I want to assert in my tests the content of my first and second table cells. I tried it in the following way:

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

But it didn't work, it couldn't find such a entry.


回答1:


You could test like this:

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

If that doesn't work, you may also try with a regexp like:

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


来源:https://stackoverflow.com/questions/29229544/assert-select-first-and-second-html-table-cell-contents-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!