【问题标题】:UIAutomation Instrument Exception "Target app is not frontmost"UIAutomation 仪器异常“目标应用程序不是最前面的”
【发布时间】:2023-11-29 16:33:01
【问题描述】:

我有一个使用 CLLocationManager 的 iOS5 iPad 应用程序,我正在使用 UIAutomation 进行测试。

在运行测试脚本之前,我在使用 CLLocationManager 时在 iOS 显示的对话框中手动按“确定”。

有时,我的测试脚本将无法启动。我按下Instruments 中的“播放”图标,12 秒内没有任何反应。然后,我得到以下异常:

Target app is not frontmost

一旦发生这种情况,我通常必须重新启动才能让仪器再次工作。

当我将CLLocationManager 对话框留在我的应用程序前面时,我曾经遇到过同样的异常。有人知道如何解决这个问题吗?

【问题讨论】:

    标签: ios ios-simulator instruments cllocationmanager ios-ui-automation


    【解决方案1】:
        //Handling Externally Generated Alerts
    UIATarget.onAlert = function onAlert(alert) {
        var title = alert.name();
        UIALogger.logWarning("Alert with title ’" + title + "’ encountered!");
        if (title == "Add Something") {
            alert.buttons()["Add"].tap();
            return true; // bypass default handler
        }
        return false; // use default handler
    }
    
    Use this code to handle location alert 
    

    【讨论】:

      【解决方案2】:

      当应用程序完全启动之前弹出警报视图时会发生这种情况。这是自动化的错误。

      【讨论】:

      • 处理警报以消除此错误,请参阅 Automating_User_Interface_Testing_With_Instruments pdf