我正在尝试用UIAutomation测试UIAlertView的存在,但我的处理程序从未被调用过。
在我的javascript的开头,我写道:
UIATarget.onAlert = function onAlert(alert) {
UIALogger.logMessage("alertShown");
return false;
}据我所知,只要我指定了我的onAlert函数,在我的测试过程中出现alertView时就应该调用它。所以我运行了一个显示alertView的测试,下面是显示警报的代码:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:message message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
alertView.accessibilityLabel = @"alerte d'avertissement";
[alertView show];我在仪器中运行我的测试,出现警报,但我的处理程序从未被调用。有没有人能够在UIAutomation中使用事件处理程序?
谢谢,文森特。
发布于 2010-12-24 02:48:04
文档似乎是错的。事实证明,警报是在您的脚本试图运行的同一线程上处理的。因此,如果您希望调用警报处理程序,则需要休眠,例如,
UIATarget.onAlert = { ... }
window.buttons().triggerAlertButton.tap();
UIATarget.localTarget().delay(4);此外,警报的名称和值似乎始终设置为null。然而,我能够访问包含警报标题的第一个静态文本。
发布于 2012-10-04 20:04:39
确保在显示UIAlertView时UI自动化脚本仍在运行。
例如,将以下行添加到脚本的末尾将使脚本保持运行,直到可以访问警报或对象解析的宽限期到期。
// Wait for UIAlert to appear so that UIATarget.onAlert gets called.
target.frontMostApp().alert();我通过彻底阅读和理解Instruments User Guide: Automating UI Testing来弄明白这一点,我强烈建议将其作为UI自动化的入门。
回顾UIATarget Class Reference,特别是popTimeout、pushTimeout、setTimeout、timeout和delay方法也可能很有帮助。
发布于 2012-09-11 20:01:08
下面的代码适用于我。该函数正在处理警报,并在日志上打印"alert Shown“。
var target = UIATarget.localTarget();
var application = target.frontMostApp();
var window = application.mainWindow();
UIATarget.onAlert = function onAlert(alert){
UIALogger.logMessage("alert Shown");
}
target.frontMostApp().mainWindow().tableViews()[0]
.cells()["Fhgui"].buttons()["Images"].tap();
// Alert detected. Expressions for handling alerts
// should be moved into the UIATarget.onAlert function definition.
target.frontMostApp().alert().defaultButton().tap();https://stackoverflow.com/questions/3651316
复制相似问题