The easiest way to run MagicPod tests from GitLab CI is to use magicpod-api-client and follow these steps to run tests using a cloud device or external cloud service device.
Table of contents
- Create a shell script
- Create an execution configuration file for GitLab CI
- Confirmation of operation
1. Create a shell script
Create a shell script run_magicpod_test.sh under the top-level folder of the project where the source code is located to run tests on MagicPod.
For Mobile app tests:
#!/bin/bash -e
# (Using -e, terminate processing at the line where there is a command error)
# Download and unzip the latest version of magicpod-api-client to the current directory
# For security, MAGICPOD_API_TOKEN is set using the GitLab CI variables
OS=linux # Specify windows for builds on Windows machines and mac for builds on Mac machines
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
# Set the various environment variables used on MagicPod
export MAGICPOD_ORGANIZATION=<MagicPod organization name>
export MAGICPOD_PROJECT=<MagicPod project name>
# Upload the app/ipa/apk file to MagicPod, and acquire the FILE_NO.
APP_PATH=<Any directory in the project to store the app file)>
FILE_NO=$(./magicpod-api-client upload-app -a ${APP_PATH})
# Run batch tests using the app just uploaded and the test run settings number
TEST_SETTING_NUMBER=<MagicPod test run settings number>
./magicpod-api-client batch-run -S ${TEST_SETTING_NUMBER} -s "{\"app_file_number\":\"${FILE_NO}\"}"
# If the test is successful, delete the uploaded app (optional)
if [ $? = 0 ]; then
./magicpod-api-client delete-app -a ${FILE_NO}
fi
For Browser tests:
#!/bin/bash -e
# (Using -e, terminate processing at the line where there is a command error)
# Download and unzip the latest version of magicpod-api-client to the current directory
# For security, MAGICPOD_API_TOKEN is set using the GitLab CI variables
OS=linux # Specify windows for builds on Windows machines and mac for builds on Mac machines
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
# Set the various environment variables used on MagicPod
export MAGICPOD_ORGANIZATION=<MagicPod organization name>
export MAGICPOD_PROJECT=<MagicPod project name>
# Run batch test
TEST_SETTING_NUMBER=<MagicPod test run settings number>
./magicpod-api-client batch-run -S ${TEST_SETTING_NUMBER}
- For security,
MAGICPOD_API_TOKENis set in a GitLab CI/CD variable.- First, go to https://gitlab.com/<username>/<project>/-/settings/ci_cd, click Variables > Add variable, input MAGICPOD_API_TOKEN in Key, and input a value copied from MagicPod API token in Value.
-
Note:
TEST_SETTING_NUMBER=<MagicPod test run settings numberis not a test case number but a batch run number. - If you want to perform efficient processing without waiting for the batch execution to complete, use the
-noption. (For more details, click here.)
2. Create an execution configuration file for GitLab CI
Create a file named .gitlab-ci.yml under the root directory, then write the following in the created yml file.
# Define the job stages. Jobs in the same stage run in parallel.
stages:
- test
# Define the job named `magic_pod_job`.
magic_pod_job:
# Specify the stage this job belongs to.
stage: test
# Specify when the pipeline should run.
# This tells GitLab to run the pipeline on every push to a branch.
rules:
- if: $CI_PIPELINE_SOURCE == "push"
# Define the script to be executed in the job.
script:
- echo "Running batch tests using MagicPod..."
# The variable is available as an environment variable in the job's shell.
- bash run_magicpod_test.sh
3. Confirmation of operation
Push all of the following files to the repository where the source code is located, and you will see that it runs tests with MagicPod in the Bulid > Pipelines tab in GitLab.
- Shell script to run tests with MagicPod created in 1
- YML file created in 2