XCTest - UITest "Could not obtain the bundle identifier for"

I tried to create an UITest for my application.

I created a new Target and added an XCTestCase Class with the needed UITest.

Everytime I try to run the Test Xcode tells me "Could not obtain the bundle identifier for /path/to/myRepo/build/Debug-iphoneos/My_App.app" and it fails.

I tried to manually set the "TEST_HOST" but after using it with that option it told me that I have an incorrect configuration as I cannot set "USE_XCTRUNNER" and "TEST_HOST" at the same time.


Any suggestions about this problem?

Replies

Did you clean the build folder (i.e. hold Option -> product -> clean)?

I did this and resolved my problem.

I still see this issue on Xcode 9.2 (9C40b), running on MacOS 10.12.6. Cleaning the builder folder didn't help, nor did reinstalling the application in the simulator, closing and reopening Xcode. This is yet another bug with Xcode 9.2 and UI Testing.

Along with cleaning the build folder, delete the contents of XCode's derived data folder.
Go to XCode -> Preferences -> Locations -> Click on the arrow to take you to the Derived Data folder and delete contents of folder

I am having this issua also, Unit Tests work fine, UI tests wont' run. I've spent 6 hours now trying these below in various combinations.

  • cleaning, cleaning build folder, deleting derived data
  • restarted xcode
  • deleted app from phone or from simulator

Targets:

  • deleted unit test and ui test targets from project,
  • recreate just unit test target in project
  • recreate just ui test target in project
  • change tons of uitest target build settings
  • change uitest targets target application to none or to my app

Scheme

  • in scheme test -> info, run test with just uitest tests or with uitest + unittest in tests
  • in scheme test -> options,enable code coverage or disable code coverage
  • in scheme test -> options, set my app as target, set unit test app as target, set ui test app as target, try all 3, try 2 of each
  • disable screen shots, enable screen shots

In UITests

  • in uitest try to init xcuiappicatoin with bundle id or without bundleid
  • try without setup/teardown, try with

The one thing I can't figure out is why the errors shows that myapptests.app is trying to be located, and not myapp.app. myapptests.app is from the unit test target. For every combo above, this still showed as the error. Could not obtain the bundle identifier for '/Users/Me/Library/Developer/Xcode/DerivedData/MyApp-dudugrpbakytmgcypgfwpkusurxt/Build/Products/Development-iphoneos/MyAppTests.app'


In an attempt to change the error message to say anything other than MyAppTests.app, I've changed bundle id and bundle name and produt name on main target, unit test target, ui test target, cleaned, cleaned build folder and deleted dervied data and apps from device, error message remains the same???


I've also noticed the last step in Xcode status bar displays "Fetching Runtime Profiles (0/1)" right before the error appears.


I also tried setting Test_Host, but that doesn't seem to be allowed on UITests.

i finally got this working.


1. Delete Derived data folder (the entire folder, not just the sub folder pertaining to this specific app)

2. In Pod file, under the UITest target, add all pods that are used by Main app. inherit! :search_paths is not sufficient

3. Run pod install, watch for any warnings or errors. Resolve accordingly. Doing step 2 created a few for me, but my app has 8 build configuration, 4 targets , uses two ADP accounts so each scheme uses a different provisioning profile. Issue 1 was Always_Embed_Swift_Standard_Libraries, where bold, needed to be selected and tap delete so bold goes away. Issue 2 was the old pod framework reference for UI target remained, so needed to delete that. Issue 3 was UI tests needed to match the provisioning profile for 1 and only one scheme of the 8 I had. Issue 4 was my project build configuration UI test config after pod update was wrong. Setting it to none and doing pod update again fixed it.

4. Delete app from Device

I ran into this and cleaning the Build and DerivedData directories, along with erasing and resetting the simulator solved the problem.