Disabling waiting for idle state in UI testing of iOS apps

后端 未结 5 1124
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 12:37

Basically the problem is the same as this one: XCTestCase: Wait for app to idle

I am using perpetually repeating \"background animations\" in my views. The !@#$#$&@

5条回答
  •  孤街浪徒
    2021-02-04 12:58

    You actually can disable wait for app to idle. This is a hack and may not be stable. With animations disabled, and this hack enabled I am seeing about a 20% performance gain (on top of the performance boost from disabling animations).

    All you have to do is swizzle out the method that is called to idle the app and no-op it. That method is XCUIApplicationProcess waitForQuiescenceIncludingAnimationsIdle:

    Here is my working solution in swift 3 - there is likely a better way but this works for a proof of concept.

    Extend the XCTestCase class. Ill call mine 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
    }
    

    Note wait for app to idle will no longer appear in the logs.

提交回复
热议问题