assert_select first and second html table cell con

2019-07-13 02:16发布

问题:

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/