【发布时间】:2017-01-21 14:43:01
【问题描述】:
我有一个列出用户 ID、姓名、电子邮件和用户名的用户表。我正在尝试做的是验证该表中是否有特定条目。
所以基本上我想做的是找到 ID = 22 的行,然后验证 name = John Smith、email = john@smith.com 和 username = jsmith。能够设置如下所示。我不明白的是几件事......
- 如何获得包含特定文本的行,即即 user.id = 22。
- 拥有该行后,如何使用它获取每个元素。
我以为我可以做一种 for 循环,但不知道如何设置 has_selector? 条件。 (以下为伪代码)
page.all('tr').each do |tr|
next unless tr.has_selector?('td.id = 22') #psuedocode
expect(tr.get('td.name').to eq("John Smith")
#other expects here...
end
表格代码
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td class="id"><%= user.id %></td>
<td class="name"><%= link_to user.name, user %></td>
<td class="email"><%= user.base_name %></td>
<td class="username"><%= user.username %></td>
</tr>
<% end %>
</tbody>
</table>
【问题讨论】:
标签: html ruby-on-rails ruby capybara