使用UIAutomation处理警报 [英] Handling Alert with UIAutomation

查看:144
本文介绍了使用UIAutomation处理警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用UIAutomation测试UIAlertView的存在,但我的处理程序永远不会被调用。

I'm trying to test the presence of an UIAlertView with UIAutomation but my handler never gets called.

在我的javascript开头我写道:

At the beginning of my javascript i write :

UIATarget.onAlert = function onAlert(alert) {
    UIALogger.logMessage("alertShown");
    return false;
}

据我所知,只要我指定了我的onAlert函数,就应该在我的测试期间出现alertView时调用。
所以我运行一个显示alertView的测试,这里是显示警报的代码:

As i understand it, as soon as i specify my onAlert function, it should get called when an alertView appears during my tests. So i run a test that shows an alertView, here is the code that shows the alert :

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:message message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
alertView.accessibilityLabel = @"alerte d'avertissement";
[alertView show];

我在乐器中运行我的测试,警报出现但我的处理程序从未被调用过。有没有人能够使用UIAutomation的事件处理程序?

I run my test in instruments, the alert shows up but my handler is never called. Has anybody been able to use event handlers with UIAutomation ?

谢谢,
Vincent。

Thanks, Vincent.

推荐答案

文档似乎是错误的。事实证明,警报是在脚本尝试运行的同一个线程上处理的。因此,如果你想要调用警报处理程序,你需要睡觉,例如,

The documentation seems to be wrong. It turns out that alerts are handled on the same thread your script tries to run. So if you want the alert handler to be called, you need to sleep, e.g.,

UIATarget.onAlert = { ... }
window.buttons().triggerAlertButton.tap();
UIATarget.localTarget().delay(4);

此外,似乎警报的名称和值始终设置为null。但是,我能够访问包含警报标题的第一个静态文本。

Also, it appears that the alert's name and value are always set to null. I was, however, able to access the first static text which contained the alert's title.

这篇关于使用UIAutomation处理警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆