0

在 iOS 7 之后,我们遇到了使用葫芦进行 UIAlertView 验证的问题。

现在我可以使用来检测警报消息

wait_for_elements_exist(["view:'_UIModalItemRepresentationView'"], :timeout => 20)
query("view:'_UIModalItemRepresentationView' label marked:'#{text}'",).empty?

我从https://gist.github.com/seanoshea/7613671得到了这个想法

但以前(在 iOS 6 中)我们能够像这样清楚地检测到消息和标题

title = query("view:'UIAlertView'",:title).first
msg = query("view:'UIAlertView'",:message).first

有什么方法可以在 iOS7 中做同样的事情吗?我认为“坦率”的人也会这样做https://github.com/moredip/Frank/pull/262

注意:jmoody请帮助我们在 calabash 自动化中处理这个 iOS 7 警报。

4

1 回答 1

2

现在我一直在使用这个解决方案。如果有人遇到同样的问题,可以使用它,直到我们有一个好的解决方案。

Then /^I should see empty email alert$/ do
  is_alert_exist_with_text("Email cannot be empty.")
  sleep(0.5)
  touch_alert_button("OK")
end
######## 定义函数
def touch_alert_button(button)
  btn = query("view:'_UIModalItemTableViewCell' label marked:'#{button}'").first.empty?
  if (btn)
    screenshot_and_raise "button not found '#{button}'"
  else
    touch("view:'_UIModalItemTableViewCell' label marked:'#{button}'").first
    sleep(0.2)
  end
end

def is_alert_exist_with_text(text)
  unless query("view:'_UIModalItemRepresentationView' label marked:'#{text}'",).empty?
    return true
  else
    screenshot_and_raise "could not find the text '#{text}' in alert view"
  end
end

此外...

def is_alert_exist_with_title_and_message(title, message)
  elements = query("view:'_UIModalItemRepresentationView' label", 'text')
  buttons = query("view:'_UIModalItemTableViewCell' label", 'text')
  textLabels = elements - buttons

  if (textLabels.count == 2)
    screenshot_and_raise "Alert Title '#{title}' not found" unless (textLabels[0].eql? title)
    screenshot_and_raise "Alert Message '#{message}' not found" unless (textLabels[1].eql? message)
  else
    screenshot_and_raise "Argument error...isAlertExistWithTitleAndMessage function"
  end
end
于 2014-02-09T18:26:56.530 回答