gpt4 book ai didi

cucumber - Capybara中表格的复杂断言

转载 作者:行者123 更新时间:2023-12-01 23:10:51 25 4
gpt4 key购买 nike

我的应用中有一个表格。

enter image description here

使用 Capybara 和 Cucumber,我如何断言值 4.5 和 1.1 仅出现在 Mike 的行中?
在 Capybara 中是否可以这样断言?

谢谢!

最佳答案

您可以使用 within到您正在搜索特定值的范围:

例如,要断言值 4.5 出现在 Mike 行的第二列,请尝试以下操作:

within("table tr:nth-child(2)") do
find("td:nth-child(2)").text.should == 4.5
end

如果您愿意,可以将它们包装在辅助方法中以便于使用:

def within_row(num, &block)
within("table tr:nth-child(#{num})", &block)
end

def column_text(num)
find("td:nth-child(#{num})").text
end

现在您可以通过执行以下操作对 Mike 的行做出相同的断言:

within_row(2) do
column_text(2).should == 4.1
end

希望您会发现其中一种技术对您正在尝试做的事情有用。

关于cucumber - Capybara中表格的复杂断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14527556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com