iOS UI 自动化 deactivateAppForDuration 失败

标签 ios ios-ui-automation

我正在处理我的第一个 UI 自动化脚本,但在下面的 deactivateAppForDuration 行遇到故障:

// Verify password field is shown when app is moved to the foreground
UIALogger.logMessage("move app to background");
target.deactivateAppForDuration(10);
UIALogger.logMessage("move app to foreground");

我从 Instruments 得到的错误是:

Script threw an uncaught JavaScript error: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().switcherScrollView().buttons()["TimeClock"]

我在测试设备上看到的是应用程序已切换到后台并显示 iOS 应用程序切换器。我可以看到我的应用程序 (TimeClock)。从错误消息和设备屏幕上都可以看出,UI 自动化无法选择我的应用程序以过渡到前台。

有没有人遇到过这个问题?有解决方法吗?

谢谢。

最佳答案

我已经尝试了您的代码,它在这里工作正常。如果您在新的 Instruments 文件中运行以下代码(仅此而已),是否有效?

var target = UIATarget.localTarget();
UIALogger.logMessage("move app to background");
target.deactivateAppForDuration(1);
UIALogger.logMessage("move app to foreground");

请注意:Instruments 并不总是向您准确显示错误发生的位置。有时它在显示的线上方或下方几行。 但是:错误发生的原因是正确的。我承认你在这一行中有一个错误,我猜你是从 Springboard 回来后打电话的:

Script threw an uncaught JavaScript error: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().switcherScrollView().buttons()["TimeClock"]

您确定 switcherScrollView().buttons()["TimeClock"] 元素存在于您的应用中并且可以访问吗?

关于iOS UI 自动化 deactivateAppForDuration 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9829024/

相关文章:

ios - CoreBluetooth - centralManagers 方法 didDiscoverPeripheral 在 sleep 模式下变得最不频繁到没有

ios - 自动调整 ImageView 大小

ios - 如何在 jenkins 上运行 ios 模拟器进行 ui 自动化测试

ios - 音乐程序的 TabBarController

objective-c - 绘制触摸事件

ios - 无法通过 url 方案从我的 iOS 应用程序在 MS-Excel iOS 应用程序中打开我的 excelSheet

iOS8 - 是否有来自代码的 UIAutomation 框架示例?

ios - 仪器自动化跟踪只允许一个目标连接?

javascript - UIAutomation,UITableViewCell 内的 UITableView

ios - 点击按钮上的命令在 UIAutomation 中不起作用