skip to Main Content

I have UI test (for an iOS app) that opens iOS photo gallery and taps on specific image.
I want to have custom script that will copy this image to simulator’s photo gallery at the beginning of the test of even right before it will start.

I have sh script that works when I manually run it after simulator is launched, but I want it to be executed during test run on Xcode Cloud.

This is script code

#!/bin/bash

# Get the UDID of the simulator (adjust for your target simulator)
SIMULATOR_UDID=$(xcrun simctl list devices | grep "Booted" | awk -F '[()]' '{print $2}')

# Path to the image
IMAGE_PATH="./myImage.jpg"

# Add the image to the simulator gallery
xcrun simctl addmedia $SIMULATOR_UDID $IMAGE_PATH

I already tried to add it to pre-test actions for Test Scheme and to Build Phases of UI test target – no luck, I even wasn’t able to find logs related to this script execution.

2

Answers


  1. Here is detailed answer on the matter of scripts for Xcode Cloud. And this is related apple documentation page. Please, let me know if it helped.

    Login or Signup to reply.
  2. Try this script code:

    #!/bin/bash
    
    # Ensure the script logs output for debugging
    set -x
    
    # Path to the image (adjust if necessary)
    IMAGE_PATH="$SRCROOT/myImage.jpg"
    
    # Get the UDID from environment variable
    SIMULATOR_UDID="$TARGET_DEVICE_IDENTIFIER"
    
    # Wait until the simulator is booted
    boot_status=$(xcrun simctl bootstatus "$SIMULATOR_UDID" -b)
    if [ $? -ne 0 ]; then
      echo "Simulator failed to boot"
      exit 1
    fi
    
    # Add the image to the simulator gallery
    xcrun simctl addmedia "$SIMULATOR_UDID" "$IMAGE_PATH"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search