When running scheduled tests in coordination with CI services, there may be cases where you want to specify an app file other than the latest version.
Here, we will introduce how to specify any app file uploaded to MagicPod when running batch tests.
For more details on integration with CI services, please refer to the page below.
Run tests regularly with CI services
Table of Contents
Specify based on upload order
For example, if you want to run tests using the app file uploaded just before the latest one, you can execute it with a shell script like the following:
#!/bin/bash
MAGICPOD_API_TOKEN="XXX"
YOUR_ORGANIZATION_NAME="XXX"
YOUR_PROJECT_NAME="XXX"
# Download and extract the latest version of magicpod-api-client to the current directory
OS=mac # Specify windows for builds on Windows machines, linux for Linux
FILENAME=magicpod-api-client # Any file name
curl -L "https://app.magicpod.com/api/v1.0/magicpod-clients/api/${OS}/latest/" -H "Authorization: Token ${MAGICPOD_API_TOKEN}" --output ${FILENAME}.zip
unzip -q ${FILENAME}.zip
# Get the app_file_number of the second-to-last uploaded file
RESPONSE=$(curl -s -X 'GET' \
'https://app.magicpod.com/api/v1.0/YOUR_ORGANIZATION_NAME/YOUR_PROJECT_NAME/list-files/' \
-H 'accept: application/json' \
-H "Authorization: Token ${MAGICPOD_API_TOKEN}")
ARRAY_LENGTH=$(echo "$RESPONSE" | jq '.app_files | length')
if [ "$ARRAY_LENGTH" -lt 2 ]; then
echo "Error: Insufficient number of elements in app_files (required: 2 or more, actual: $ARRAY_LENGTH)"
exit 1
fi
APP_FILE_NUMBER=$(echo "$RESPONSE" | jq -r '.app_files[1].app_file_number')
echo "Retrieved app_file_number: ${APP_FILE_NUMBER}"
# Execute batch-run
# For how to obtain the execution command, please refer to here
./magicpod-api-client batch-run \
-t ${SECRET_API_TOKEN} \
-o YOUR_ORGANIZATION_NAME \
-p YOUR_PROJECT_NAME \
-s "{\"test_settings_name\":\"xyz\",\"test_settings\":[{\"environment\":\"magic_pod\",\"os\":\"android\",\"device_type\":\"arm64_v8a_emulator\",\"auto_grant_app_permissions\":\"all\",\"version\":\"14.0\",\"model\":\"Pixel 7\",\"app_type\":\"app_file\",\"app_file_number\":\"${APP_FILE_NUMBER}\",\"device_log_level\":\"none\",\"app_time_zone\":\"Default\",\"test_case_numbers\":\"11\",\"visual_diff_pattern\":\"Default\",\"implicit_wait_policy\":\"emphasize_stability\"}]}"
Specify based on the app file name
You can also specify the file to execute by prefix matching or partial matching of the app file name.
Below is an example of specifying the last uploaded file among app files whose names start with "v2".
#!/bin/bash
MAGICPOD_API_TOKEN="XXX"
YOUR_ORGANIZATION_NAME="XXX"
YOUR_PROJECT_NAME="XXX"
# Download and extract the latest version of magicpod-api-client to the current directory
OS=mac # Specify windows for builds on Windows machines, linux for Linux
FILENAME=magicpod-api-client # Any file name
curl -L "https://app.magicpod.com/api/v1.0/magicpod-clients/api/${OS}/latest/" -H "Authorization: Token ${MAGICPOD_API_TOKEN}" --output ${FILENAME}.zip
unzip -q ${FILENAME}.zip
# Get the maximum app_file_number among file names starting with "v2"
APP_FILE_NUMBER=$(curl -s -X 'GET' \
'https://app.magicpod.com/api/v1.0/YOUR_ORGANIZATION_NAME/YOUR_PROJECT_NAME/list-files/' \
-H 'accept: application/json' \
-H "Authorization: Token ${MAGICPOD_API_TOKEN}" \
| jq -r '.app_files[] | select(.app_file_name | ascii_downcase | startswith("v2")) | .app_file_number' \
| sort -nr \
| head -n 1)
# Verify if it was successfully retrieved
if [ -z "$APP_FILE_NUMBER" ]; then
echo "Error: app_file_number could not be retrieved"
exit 1
fi
echo "Retrieved app_file_number: ${APP_FILE_NUMBER}"
# Execute batch-run
# For how to obtain the execution command, please refer to here
./magicpod-api-client batch-run \
-t ${SECRET_API_TOKEN} \
-o YOUR_ORGANIZATION_NAME \
-p YOUR_PROJECT_NAME \
-s "{\"test_settings_name\":\"xyz\",\"test_settings\":[{\"environment\":\"magic_pod\",\"os\":\"android\",\"device_type\":\"arm64_v8a_emulator\",\"auto_grant_app_permissions\":\"all\",\"version\":\"14.0\",\"model\":\"Pixel 7\",\"app_type\":\"app_file\",\"app_file_number\":\"${APP_FILE_NUMBER}\",\"device_log_level\":\"none\",\"app_time_zone\":\"Default\",\"test_case_numbers\":\"11\",\"visual_diff_pattern\":\"Default\",\"implicit_wait_policy\":\"emphasize_stability\"}]}"
About the batch-run execution command
The batch-run execution command using magicpod-api-client can be obtained by the following method.
First, in the batch run settings, click "︙" > "Run from command line", and select "Run with magicpod-api-client (detailed settings)".
Copy the part after ./magicpod-api-client batch-run, edit the \"app_file_number\" field to \"app_file_number\":\"${APP_FILE_NUMBER}\", and use it.