We have the following code that we are using to remove out app in between tests.
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboardApp.activate()
let appIcon = springboard.icons.matching(identifier: "xxxxxx").firstMatch
appIcon.press(forDuration: 1.0)
let removeApp = springboard.buttons["Remove App"]
removeApp.waitForExistance(timeout: 5.0)
removeApp.tap()
let removeAppConfirmDeleteAppButton = springboard.alerts.buttons["Delete App"].firstMatch
removeAppConfirmDeleteAppButton.waitForExistance(timeout: 5.0)
removeAppConfirmDeleteAppButton.tap()
let deleteAppConfirmDeleteButton = springboard.alerts.buttons["Delete"].firstMatch
deleteAppConfirmDeleteButton.waitForExistance(timeout: 5.0)
deleteAppConfirmDeleteButton.tap()
The reason that we are deleting the app is to ensure that tests start from a consistent app state.
We run our tests via fastlane scan. The resulting command looks something like this:
[23:19:30]: $ set -o pipefail && env NSUnbufferedIO=YES xcodebuild -scheme xxxxxTests -project ./xxxxx.xcodeproj -derivedDataPath /Users/vagrant/Library/Developer/Xcode/DerivedData/xxxxx-cjzmgsxnvpzlmjfynrqokkhojhug -destination 'platform=iOS Simulator,id=85C115EF-1FF9-4871-82CC-364D3BAF2098' -resultBundlePath 'build/ui_test_reports/xxxxxTests/xxxxxTests.xcresult' -testPlan 'xxxxxTests' -test-iterations 3 -retry-tests-on-failure test-without-building | tee '/Users/vagrant/git/ios-consumer/build/ui_test_reports/xxxxxTests/xxxxx-xxxxxTests.log' | xcbeautify
The problem is that we get the following error
[10:03:25]: ▸ 2022-12-16 10:03:25.529 xcodebuild[86412:7339751] iOSSimulator: 215F2A17-86F7-4612-9A71-C672FE680813: Failed to launch app with identifier: com.xxxxxx.xxxxxx and options: {
[10:03:25]: ▸ "activate_suspended" = 0;
[10:03:25]: ▸ arguments = (
[10:03:25]: ▸ "-key1,
[10:03:25]: ▸ true,
[10:03:25]: ▸ "-key2",
[10:03:25]: ▸ "AAAAAAAA",
[10:03:25]: ▸ "-key3",
[10:03:25]: ▸ "BBBBBBBBBB"
[10:03:25]: ▸ );
[10:03:25]: ▸ environment = {
[10:03:25]: ▸ "CA_ASSERT_MAIN_THREAD_TRANSACTIONS" = 0;
[10:03:25]: ▸ "CA_DEBUG_TRANSACTIONS" = 0;
[10:03:25]: ▸ "DYLD_FRAMEWORK_PATH" = "/AAAAA/AAAAAAA/Library/Developer/Xcode/DerivedData/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/Build/Products/Debug-iphonesimulator:/AAAAA/AAAAAAA/Library/Developer/Xcode/DerivedData/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/Build/Products/Debug-iphonesimulator/PackageFrameworks";
[10:03:25]: ▸ "DYLD_INSERT_LIBRARIES" = "/Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib";
[10:03:25]: ▸ "DYLD_LIBRARY_PATH" = "/AAAAA/AAAAAAA/Library/Developer/Xcode/DerivedData/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/Build/Products/Debug-iphonesimulator";
[10:03:25]: ▸ "LLVM_PROFILE_FILE" = "/var/folders/y2/rp02hkm94x59s7k472g592wh0000gp/T/com.xxxxxx.xxxxxx/94D6D959-1594-4801-9C26-0AD824A89EEB-86412-00000F3C6FAE4044/FB9B0C24-BB22-4EBF-9525-E8A2FED8691A-%p%c.profraw";
[10:03:25]: ▸ "MTC_CRASH_ON_REPORT" = 1;
[10:03:25]: ▸ NSApplicationQuitWithoutSuddenTermination = YES;
[10:03:25]: ▸ NSUnbufferedIO = YES;
[10:03:25]: ▸ "OS_ACTIVITY_MODE" = info;
[10:03:25]: ▸ "__XCODE_BUILT_PRODUCTS_DIR_PATHS" = "/AAAAA/AAAAAAA/Library/Developer/Xcode/DerivedData/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/Build/Products/Debug-iphonesimulator";
[10:03:25]: ▸ "__XPC_DYLD_FRAMEWORK_PATH" = "/AAAAA/AAAAAAA/Library/Developer/Xcode/DerivedData/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/Build/Products/Debug-iphonesimulator";
[10:03:25]: ▸ "__XPC_DYLD_LIBRARY_PATH" = "/AAAAA/AAAAAAA/Library/Developer/Xcode/DerivedData/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/Build/Products/Debug-iphonesimulator";
[10:03:25]: ▸ "__XPC_LLVM_PROFILE_FILE" = "/var/folders/y2/rp02hkm94x59s7k472g592wh0000gp/T/com.xxxxxx.xxxxxx/94D6D959-1594-4801-9C26-0AD824A89EEB-86412-00000F3C6FAE4044/FB9B0C24-BB22-4EBF-9525-E8A2FED8691A-%p%c.profraw";
[10:03:25]: ▸ };
[10:03:25]: ▸ stderr = "/dev/ttys013";
[10:03:25]: ▸ stdout = "/dev/ttys013";
[10:03:25]: ▸ "terminate_running_process" = 1;
[10:03:25]: ▸ "wait_for_debugger" = 0;
[10:03:25]: ▸ } (error = Error Domain=FBSOpenApplicationServiceErrorDomain Code=4 "The request to open "com.xxxxxx.xxxxxx" failed." UserInfo={NSLocalizedDescription=The request to open "com.xxxxxx.xxxxxx" failed., BSErrorCodeDescription=InvalidRequest, FBSOpenApplicationRequestID=0x87a7, NSUnderlyingError=0x600002a85b00 {Error Domain=FBSOpenApplicationErrorDomain Code=4 "Application info provider (FBSApplicationLibrary) returned nil for "com.xxxxxx.xxxxxx"" UserInfo={BSErrorCodeDescription=NotFound, NSLocalizedFailureReason=Application info provider (FBSApplicationLibrary) returned nil for "com.xxxxxx.xxxxxx"}}})
The error makes it look like the test did not even run, but the tests are running. If I remove the code that deletes the app, the error goes away.
I have tried using different approaches to launching our app like using activate() instead of launch(). I've tried putting the delete in the
setup and teardown. I've put the delete in the test. I've added delays, before and after the delete, nothing can work around the error.
My first question is what is the thing that is checking for the presence of the app and failing?
My second question is there anything I can try that I have not already tried.