Unable to monitor event loop AND Wait for app to idle

后端 未结 2 1715
孤城傲影
孤城傲影 2021-02-05 13:50

I am writing UITest cases for my app using XCTest. App makes several server calls in the homescreen. I could not navigate to next screen. Automation often stays idle for 1 min o

2条回答
  •  生来不讨喜
    2021-02-05 14:05

    My suggestion would be to help you use one of these two methods below. The first awaits an element appears on the screen. The second element is awaiting hittable. But in any case these methods help you, maybe you can use the method sleep(param). Like sleep(5). Waits for 5 seconds

    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)
                }
            }
        }
    }
    

    I hope to have helped in some way

提交回复
热议问题