开发者

Checking for values in a table row in cucumber

开发者 https://www.devze.com 2023-03-06 18:32 出处:网络
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

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 ha开发者_如何学Pythons 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?


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!


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号