Unable to monitor event loop AND Wait for app to idle
Asked Answered
I

2

16

I am writing UITest cases for my app using XCTest. The app makes several server calls on the home screen. I could not navigate to the next screen. Automation often stays idle for 1 min or even more than that with the message

Wait for the app to idle

or

Unable to monitor event loop

Is there a way to make the app execute my test cases breaking this ???

Interpenetrate answered 20/10, 2016 at 13:42 Comment(0)
I
18

I have set argument in UI test class

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

In my Appdelegate's didFinishLaunchingWithOptions method I made a check

 NSArray *args = [NSProcessInfo processInfo].arguments;
    
    for (NSString *arg in args){
        if ([arg isEqualToString:@"NoAnimations"]){
            [UIView setAnimationsEnabled:false];
        }
    }

So now all over my app, there won't be any animation and my app is no more blocked. This reduced my automation time from 25mins to 2mins.

Interpenetrate answered 3/11, 2016 at 11:17 Comment(0)
C
1

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

Courtroom answered 22/10, 2016 at 11:48 Comment(1)
Thanks for finding time to help me. The element is still hittable and exists but again it waits long time with same "Wait for app to idle" message. Sometimes I do see this message ---- " App animations complete notification not received, will attempt to continue".Interpenetrate

© 2022 - 2024 — McMap. All rights reserved.