19

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

shim
  • 9,289
  • 12
  • 69
  • 108
David Karlsson
  • 9,396
  • 9
  • 58
  • 103
  • Does your UI test work when you run it from Xcode, instead of running it directly from Fastlane? – HardikDG Feb 12 '17 at 16:48
  • @HardikDG In my case the tests on the local machine using XCode always succeed, but when running on a Mac Mini using XCode server each test has a chance of about 3% that it will fail. since we have more than 200 UI tests the build on the server will almost always fail. (We had 1 successful build in 2 weeks) – Edwin Vermeer Feb 15 '17 at 10:43
  • Upgrading the machine to SSD and allowing 5 failures removed most of the errors, still sometimes we see them, but not as often... (only allowing 5 tries did not help, but the combination of upgrade+retries). – David Karlsson Mar 09 '17 at 11:34

2 Answers2

3

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

Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
  • see https://github.com/lionheart/openradar-mirror/issues/16226 and https://openradar.appspot.com/29735288 – Edwin Vermeer Feb 07 '17 at 07:53
  • 1
    Great solution even if its not full proof @Edwin. Seems to have reduced the amount of `Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.test.SomeTest-Runner"` I was getting. Thanks – Laser Hawk Mar 13 '17 at 19:46
  • @EdwinVermeer and then you call tryLaunch before every test method? – regetskcob May 25 '23 at 13:16
1

After playing around we were observed that if we run limited test cases, this error went down considerably. You can find more details at https://blog.talentica.com/2017/04/04/use-xcode-8-with-jenkins/

Mahesh K
  • 373
  • 2
  • 8