检查黄瓜表行中的值

发布于 2024-11-08 19:56:10 字数 436 浏览 0 评论 0原文

我正在尝试检查数据表中的值是否正确,所以我所做的就是选择所有行并检查我要检查的对象名称和值的某个 tr 是否有内容。问题是,我似乎无法在黄瓜中返回:

Then /^I should see "([^"]*)" beside "([^"]*)"$/ do |value, name|
  all("tr").each do |tr|
    if tr.has_content?(value) && tr.has_content?(name)
      assert true and return
    end
  end
  assert false
end

我想要类似的东西。 具有这两个值时,这意味着它是正确的,我应该停止循环并返回 true(否则它最终将继续到 assert false

当我找到一行同时 我去管这个?

I am trying to check if the value in a data table is correct so what I do is select all the rows and check if that certain tr has_content of the object name and value i am checking for. Problem is, I can't seem to do a return in cucumber:

Then /^I should see "([^"]*)" beside "([^"]*)"$/ do |value, name|
  all("tr").each do |tr|
    if tr.has_content?(value) && tr.has_content?(name)
      assert true and return
    end
  end
  assert false
end

I want something like that. When I find a row that has both the values, then that means it is correct and I should stop the loop and just return true(otherwise it will continue on to the assert false in the end)

How do I go about this?

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

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

发布评论

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

评论(2

善良天后 2024-11-15 19:56:10

好吧,这似乎是一个肮脏的黑客,但我只是使用一个变量来检查:

Then /^I should see "([^"]*)" beside "([^"]*)"$/ do |value, name|
  has_value_and_name = false
  all("tr").each do |tr|
    if tr.has_content?(value) && tr.has_content?(name)
      has_value_and_name = true
    end
  end
  assert has_value_and_name
end

我不确定它是否在所有情况下都有效......但如果您有更好的解决方案,也请发布它。谢谢!

well it seems like a dirty hack but I just used a variable to check:

Then /^I should see "([^"]*)" beside "([^"]*)"$/ do |value, name|
  has_value_and_name = false
  all("tr").each do |tr|
    if tr.has_content?(value) && tr.has_content?(name)
      has_value_and_name = true
    end
  end
  assert has_value_and_name
end

I'm not sure if it will work in all cases...but if you have better solutions please post it too. thanks!

煞人兵器 2024-11-15 19:56:10

好吧,如果它是用 Watir 驱动浏览器,你可以做

matchvalue = regex.new(value)
matchname = regex.new(name)

browser.row(:text => matchvalue, :text => matchname).exists?.should = true   

在你的情况下做什么

Then /^I should see "([^"]*)" beside "([^"]*)"$/ do |value, name|
  result = false
  all("tr").each do |tr|
    if tr.has_content?(value) && tr.has_content?(name)
      result = true
      break
    end
  end
  result.should = true
end

Well if it was driving the browser with Watir you could do

matchvalue = regex.new(value)
matchname = regex.new(name)

browser.row(:text => matchvalue, :text => matchname).exists?.should = true   

In your case what about doing

Then /^I should see "([^"]*)" beside "([^"]*)"$/ do |value, name|
  result = false
  all("tr").each do |tr|
    if tr.has_content?(value) && tr.has_content?(name)
      result = true
      break
    end
  end
  result.should = true
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文