无法监视事件循环并等待应用程序空闲

Unable to monitor event loop AND Wait for app to idle

我正在使用 XCTest 为我的应用编写 UITest 用例。应用程序在主屏幕中进行了多次服务器调用。我无法导航到下一个屏幕。自动化经常闲置 1 分钟,甚至比消息

闲置的时间更长

Wait for app to idle

Unable to monitor event loop

有没有办法让应用程序执行我的测试用例来打破这个???

我的建议是帮助您使用以下两种方法之一。第一个等待元素出现在屏幕上。第二个元素正在等待可命中。但无论如何这些方法对你有帮助,也许你可以使用方法 sleep(param)。喜欢sleep(5)。等待 5 秒

import XCTest

class BaseTestCase: XCTestCase {

    func waitForElementToAppear(element: XCUIElement, timeout: NSTimeInterval = 60,  file: String = #file, line: UInt = #line) {
        let existsPredicate = NSPredicate(format: "exists == true")
        expectationForPredicate(existsPredicate,
                                evaluatedWithObject: element, handler: nil)
        waitForExpectationsWithTimeout(timeout) { (error) -> Void in
            if (error != nil) {
                let message = "Failed to find \(element) after \(timeout) seconds."
                self.recordFailureWithDescription(message, inFile: file, atLine: line, expected: true)
            }
        }
    }

    func waitForHittable(element: XCUIElement, timeout: NSTimeInterval = 70, file: String = #file, line: UInt = #line) {
        let existsPredicate = NSPredicate(format: "hittable == 1")
        expectationForPredicate(existsPredicate, evaluatedWithObject: element, handler: nil)

        waitForExpectationsWithTimeout(timeout) { (error) -> Void in
            if (error != nil) {
                let message = "Failed to find \(element) after \(timeout) seconds."
                self.recordFailureWithDescription(message,
                                                  inFile: file, atLine: line, expected: true)
            }
        }
    }
}

我希望能以某种方式提供帮助

我在 UI 测试中设置了参数 class

let app = XCUIApplication()
app.launchArguments = ["NoAnimations"]
app.launch()

在我的 Appdelegate 的 didFinishLaunchingWithOptions 方法中我进行了检查

 NSArray *args = [NSProcessInfo processInfo].arguments;

    for (NSString *arg in args){
        if ([arg isEqualToString:@"NoAnimations"]){
            [UIView setAnimationsEnabled:false];
        }
    }

所以现在我的应用程序中没有任何动画,我的应用程序也不再被阻止。这将我的自动化时间从 25 分钟减少到 2 分钟。