Disable idle state waiting for testing iOS application user interfaces

Basically the problem is the same as this one: XCTestCase: Wait for the application to work

I use constantly repeating "background animations" in my views. The! @ # $ # $ & @ UI testing Xcode / iOS wants to wait for the end of the UIView animation to finish before the application considers it to be inactive and continues to work with such things as pressing buttons, etc. It just doesn't work so we developed the application (s). (In particular, we have a button that animates with the parameters UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse, so it never stops.)

But I think there might be some way to disable and / or reduce the "Wait until the application runs." Here? How? Is there any other way around this?

+4
source share
3 answers

Unfortunately, using the Apple UI test, you cannot turn off “application wait” or poll other network activity, however you can use environment variables to turn off animations in your application to make the tests more stable. In your setup method, set your environment variable before your testing.

override func setUp() {
    super.setUp()
    continueAfterFailure = false
    let app = XCUIApplication()
    app.launchEnvironment = ["UITEST_DISABLE_ANIMATIONS" : "YES"]
    app.launch()
}

Now in the source code:

if (ProcessInfo.processInfo.environment["UITEST_DISABLE_ANIMATIONS"] == "YES") {
    UIView.setAnimationsEnabled(false)
}

, , .

+3

wait for app to idle. . , , 20% ( ).

, , - , . XCUIApplicationProcess waitForQuiescenceIncludingAnimationsIdle:

3 - , , .

XCTestCase. Ill call my MyTestCase

static var swizzledOutIdle = false

override func setUp() {
    if !MyTestCase.swizzledOutIdle { // ensure the swizzle only happens once
        let original = class_getInstanceMethod(objc_getClass("XCUIApplicationProcess") as! AnyClass, Selector(("waitForQuiescenceIncludingAnimationsIdle:")))
        let replaced = class_getInstanceMethod(type(of: self), #selector(MyTestCase.replace))
        method_exchangeImplementations(original, replaced)
        MyTestCase.swizzledOutIdle = true
    }
    super.setUp()
}

@objc func replace() {
    return
}

wait for app to idle .

+8

I used gh123man's answer in Objective-C if someone needs this:

- (void)disableWaitForIdle {

    SEL originalSelector = NSSelectorFromString(@"waitForQuiescenceIncludingAnimationsIdle:");
    SEL swizzledSelector = @selector(doNothing);

    Method originalMethod = class_getInstanceMethod(objc_getClass("XCUIApplicationProcess"), originalSelector);
    Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);

    method_exchangeImplementations(originalMethod, swizzledMethod);
}


- (void)doNothing {
    // no-op
}
+1
source

Source: https://habr.com/ru/post/1664516/


All Articles