如何使用 ruby 水豚验证 table 的行数中是否不存在某个值?
How to validate if a value doesn't exist in a table's row count using ruby capybara?
我的 table 中有一列存储 STATUS 列中的活动和非活动值。如果没有 INACTIVE 记录,我想验证是否在搜索 ACTIVE 状态时。
我如何扫描此列并使用 expect 来验证没有出现 INACTIVE 值?
如果它没有出现,我会显示一条消息,例如:“在列表中未找到非活动记录”。
我试过这个:page.all('.tvGrid tr').each do |tr|接下来除非 tr.has_css?('td.Status', text: "ATIVO")
<div style="display:table-cell;">
<table width="100%" class="tvGrid">
<tbody>
<tr>
<th colspan="1" class="tvHeader">Id</th>
<th colspan="1" class="tvHeader">Código</th>
<th colspan="1" class="tvHeader">Descrição</th>
<th colspan="1" class="tvHeader">Centro Operacional</th>
<th colspan="1" class="tvHeader">Status</th>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',0,'','','');" class="tvRow tvRowOdd tvRoll">
<td align="right" class="tvCell" valign="center" nowrap="">21</td>
<td valign="center" align="left" class="tvCell">02</td>
<td valign="center" align="left" class="tvCell">BARRETO PIRES</td>
<td align="left" class="tvCell" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" class="tvCell">ATIVO</td>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',1,'','','');" class="tvRow tvRowEven tvRoll">
<td align="right" class="tvCell" valign="center" nowrap="">41</td>
<td valign="center" align="left" class="tvCell">03</td>
<td valign="center" align="left" class="tvCell">CAFUBÁ PIRATININGA</td>
<td align="left" class="tvCell" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" class="tvCell">ATIVO</td>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',2,'','','');" class="tvRow tvRowOdd tvRoll">
<td align="right" class="tvCell" valign="center" nowrap="">42</td>
<td valign="center" align="left" class="tvCell">04</td>
<td valign="center" align="left" class="tvCell">CAVALÃO</td>
<td align="left" class="tvCell" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" class="tvCell">ATIVO</td>
</tr>
</tr>
</tbody>
</table>
</div>
I want to validate if when searching for the ACTIVE status if there are no INACTIVE records.
由于您想测试数据,而不是测试数据的格式,因此最好将其作为 controller test。
您可以使用 rails-controller-testing
来测试传递给您的视图的内容。 assigns
使您可以访问已传递给您的视图的实例变量。
test "should show only active records" do
# Call the appropriate URL with the appropriate parameters
get search_url, params: { active: true }
# Check the right template is rendered
assert_template 'records/index'
# Check the correct data is passed to the view.
assert_equal Record.active, assigns(:records)
end
我的 table 中有一列存储 STATUS 列中的活动和非活动值。如果没有 INACTIVE 记录,我想验证是否在搜索 ACTIVE 状态时。 我如何扫描此列并使用 expect 来验证没有出现 INACTIVE 值? 如果它没有出现,我会显示一条消息,例如:“在列表中未找到非活动记录”。 我试过这个:page.all('.tvGrid tr').each do |tr|接下来除非 tr.has_css?('td.Status', text: "ATIVO")
<div style="display:table-cell;">
<table width="100%" class="tvGrid">
<tbody>
<tr>
<th colspan="1" class="tvHeader">Id</th>
<th colspan="1" class="tvHeader">Código</th>
<th colspan="1" class="tvHeader">Descrição</th>
<th colspan="1" class="tvHeader">Centro Operacional</th>
<th colspan="1" class="tvHeader">Status</th>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',0,'','','');" class="tvRow tvRowOdd tvRoll">
<td align="right" class="tvCell" valign="center" nowrap="">21</td>
<td valign="center" align="left" class="tvCell">02</td>
<td valign="center" align="left" class="tvCell">BARRETO PIRES</td>
<td align="left" class="tvCell" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" class="tvCell">ATIVO</td>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',1,'','','');" class="tvRow tvRowEven tvRoll">
<td align="right" class="tvCell" valign="center" nowrap="">41</td>
<td valign="center" align="left" class="tvCell">03</td>
<td valign="center" align="left" class="tvCell">CAFUBÁ PIRATININGA</td>
<td align="left" class="tvCell" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" class="tvCell">ATIVO</td>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',2,'','','');" class="tvRow tvRowOdd tvRoll">
<td align="right" class="tvCell" valign="center" nowrap="">42</td>
<td valign="center" align="left" class="tvCell">04</td>
<td valign="center" align="left" class="tvCell">CAVALÃO</td>
<td align="left" class="tvCell" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" class="tvCell">ATIVO</td>
</tr>
</tr>
</tbody>
</table>
</div>
I want to validate if when searching for the ACTIVE status if there are no INACTIVE records.
由于您想测试数据,而不是测试数据的格式,因此最好将其作为 controller test。
您可以使用 rails-controller-testing
来测试传递给您的视图的内容。 assigns
使您可以访问已传递给您的视图的实例变量。
test "should show only active records" do
# Call the appropriate URL with the appropriate parameters
get search_url, params: { active: true }
# Check the right template is rendered
assert_template 'records/index'
# Check the correct data is passed to the view.
assert_equal Record.active, assigns(:records)
end