Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCTests failing to launch app in simulator intermittently

Has anyone experienced and fixed:

XCTests are failing intermittently to launch app in the simulator for UI testing (XCUI). I am running through fastlane, different tests appear to fail each test run.

OSX: 10.12.3 iOS simulator: 10.0 Xcode 8.2.1 Fastlane 2.11.0

Attempted to fix it by adding a 3 second sleep between setup and launch in my tests, but it still appears, maybe not as often but still...

UI Testing Failure - Failure attempting to launch <XCUIApplicationImpl: 0x600000231b20 no.something.bb.debug at /Users/server/Library/Developer/Xcode/DerivedData/ex-gmtcdujyggxwfrarizpgaromjfxj/Build/Products/Debug-iphonesimulator/BB.app>: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "no.something.bb.debug" failed." UserInfo={NSLocalizedDescription=The request to open "no.something.bb.debug" failed., NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace) for reason: Busy ("Application "no.something.bb.debug" is installing or uninstalling, and cannot be launched")., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0x6080002598f0 {Error Domain=FBSOpenApplicationErrorDomain Code=6 "Application "no.something.bb.debug" is installing or uninstalling, and cannot be launched." UserInfo={BSErrorCodeDescription=Busy, NSLocalizedFailureReason=Application "no.something.bb.debug" is installing or uninstalling, and cannot be launched.}}}

like image 283
David Karlsson Avatar asked Jan 26 '17 11:01

David Karlsson


1 Answers

I experienced the same issue. I found out that there is a rader open for this. In the comments I found a tip that I implemented in a function that does a retry.

The arguments array is an array of enum values where the base type is String. I use that for the app arguments.

Unfortunately this is still not full prove. In my case the number of failures went down considerably, but did not go away.

var app: XCUIApplication = XCUIApplication()
public func tryLaunch<T>(_ arguments: [T], _ counter: Int = 10) where T: RawRepresentable {
    sleep(3)
    XCUIApplication().terminate()
    sleep(3)

    app = XCUIApplication()
    app.launchArguments = arguments.map { $0.rawValue as! String }
    app.launch()
    sleep(3)
    if !app.exists && counter > 0 {
        tryLaunch(arguments, counter - 1)
    }
}

The function above is included in https://github.com/evermeer/UITestHelper

like image 68
Edwin Vermeer Avatar answered Oct 26 '22 18:10

Edwin Vermeer