如何使用Ruby​ capybara在表中验证是否不存在一个值?

发布于 2025-01-20 04:58:12 字数 2863 浏览 1 评论 0原文

我的表中有一个列将活动和非活动值存储在状态列中。我想在搜索活动状态时是否验证是否没有非活动记录。 我如何扫描本列并使用期望验证没有出现不活跃的值? 如果没有出现,我会提供一条消息,例如:将列表中的“没有不活动记录”放在列表中”。 我尝试了一下:page.all('。tvgrid tr')。每个都做| tr |接下来除非tr.has_css?('td.status',文字:“ 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>

There is a column in my table that stores the active and inactive value in the STATUS column. I want to validate if when searching for the ACTIVE status if there are no INACTIVE records.
How do I scan this column and use expect to validate that no INACTIVE value has appeared?
And if it doesn't appear, I present a message like: puts 'no inactive record found in the list".
i tried this: page.all('.tvGrid tr').each do |tr| next unless 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯寂 2025-01-27 04:58:12

我想验证是否在没有非活动记录的情况下搜索活动状态时。

由于您想测试数据,而不是格式化的格式,因此最好将其作为控制器测试

您可以使用 rails-controller-controller-testing 测试什么传递给您的观点。 分配使您可以访问已传递给您视图的实例变量。

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

I want to validate if when searching for the ACTIVE status if there are no INACTIVE records.

Since you want to test the data, not how it is formatted, this is better done as a controller test.

You can use rails-controller-testing to test what is passed to your views. assigns gives you access to instance variables which have been passed to your views.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文