ios-snapshot-test-case icon indicating copy to clipboard operation
ios-snapshot-test-case copied to clipboard

Xcode cloud, reference path matches but "Unable to load reference image."

Open baphony opened this issue 9 months ago • 1 comments

  • In MyProject.xctestplan:
FB_REFERENCE_IMAGE_DIR: "$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages"
  • In Github I do have my reference image:
MyProjectTests/ReferenceImages_64/UITests.UITests/[email protected]
  • Xcode cloud Error:
UITests.testLoginUsername()
failed - Snapshot comparison failed: Optional(
  Error Domain=FBSnapshotTestControllerErrorDomain
  Code=1 "Unable to load reference image."
  UserInfo={
      NSLocalizedFailureReason=Reference image not found. You need to run the test in record mode,
      NSLocalizedDescription=Unable to load reference image.,
FBReferenceImageFilePathKey=/Volumes/workspace/repository/PROJECT_NAMETests/ReferenceImages_64/UITests.UITests/[email protected]
  }
)
UITests.swift:67

This works fine locally

baphony avatar Mar 17 '25 13:03 baphony

The reason is that UI tests don't have access to the project source files, so it doesn't have access to the snapshots.

The solution:

Create the ci_scripts directory (in Xcode):

  • Open your project or workspace in Xcode and navigate to the Project navigator.
  • In the Project navigator, Control-click your project and choose New Group to create the group and its corresponding directory.
  • Name the new group ci_scripts.

Create a symbolic link to (from a terminal in the project root folder):

cd ci_scripts
ln -s ../PROJECT_NAMETests # replace PROJECT_NAME by your own

Add the environment variables (in Xcode cloud > Manage Workflows > Your custom workflow name > Environment):

(Replace PROJECT_NAME by your own) Image

baphony avatar Mar 27 '25 10:03 baphony