HY!我正在尝试在calabash ios中编写预定义的步骤来查找具有特定标题的按钮。我的问题是如何在葫芦中使用其标题标签找到某个UIButton?我尝试了以下内容:
Then (/^I see button with title "([^\"]*)" disabled$/) do |buttonTitle|
buttons = query("UIButton").compact
buttons.each do |button|
if query(button, :titleLabel, :text) == buttonTitle
fail(msg="Button found")
return
end
end
end
答案 0 :(得分:1)
为什么不喜欢
Then (/^I should not see button with title "([^\"]*)"$/) do |button_title|
button = query("view marked:'#{button_title}'")
unless button.empty?
screenshot_and_raise "Error: #{button_title} is visible."
end
end
答案 1 :(得分:1)
irradio的回答是正确的,但我想补充一些评论,以帮助你理解你做错了什么。
# Returns an Array of query results for buttons, #compact
# is not necessary because all the values will be non-nil.
buttons = query("UIButton")
# This is incorrect; you should not pass a query result back to query.
buttons.each do |button|
query(button, ...)
end
# If you wanted to extract titles of all the buttons
query("button descendant label", :text)
=> an Array of titles
# [button titleForState:UIControlStateNormal]
query("button", {:titleForState => 0})
=> an Array of titles for UIControlStateNormal
# [[button titleLabel] text]
query("button", :titleLabel, :text)
=> an Array of titles