Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assert_select first and second html table cell contents in rails

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.

like image 271
dot Avatar asked Jan 09 '23 16:01

dot


1 Answers

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/
like image 132
RPinel Avatar answered Jan 22 '23 10:01

RPinel