assert_select Rails中的第一个和第二个html表单元格内容 [英] assert_select first and second html table cell contents in rails

查看:100
本文介绍了assert_select Rails中的第一个和第二个html表单元格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想在测试中声明第一个和第二个表单元格的内容.我以以下方式尝试过:

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.

推荐答案

您可以像这样进行测试:

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/

这篇关于assert_select Rails中的第一个和第二个html表单元格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆