This page explains how to automatically register the results of tests executed on MagicPod to the test management tool Xray using GitHub Actions.
1. Overview
On this page, we will demonstrate how to register the test results in Xray using two test cases created in MagicPod. We use GitHub Actions as the CI tool, to execute everything from test execution to result registration in a single job.
Flow to register results
- Run tests via MagicPod's Web API.
- Register each test result in the test cases via Xray's Web API.
Test result registered in Xray (Test execution item)
MagicPod test results
2. Preparations
This section describes the preparations required for Xray, MagicPod, and GitHub Actions.
2-1. Xray
2-1-1. Create test cases
Create test cases in Xray. In this example, two test cases (XSP-86 and XSP-87) are created.
Xray test case screen
2-2. MagicPod
2-2-1. Create test cases
Create test cases in MagicPod. In this example, two test cases (#1, #2) are created. Please add test keys on each MagicPod test case for the script to register them in Xray.
MagicPod project screen
2-3. GitHub Actions
2-3-1. Register secrets
Register the following items in your Repository secrets (secret variables created in the repository environment). Please check the GitHub Actions document for details on how to register.
| Secret Name | Description |
| MAGICPOD_API_TOKEN | MagicPod API token |
| XRAY_ID | Xray API ID |
| XRAY_SECRET | Xray API secret key |
GitHub repository secrets screen
3. Create scripts
First, download the script from the GitHub Repository.
From here, we will explain the steps according to the GitHub Actions job definition file, ".github/workflows/magicpod_test.yml" (hereinafter referred to as the “yml file”).
GitHub Actions workflow run screen
3-1. Install Python
(No action required) Since part of this script is written in Python, steps to install Python and HTTP library "requests" are defined.
## .github/workflows/magicpod_test.yml
- name: Set up Python
uses: actions/setup-python@v4
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install requests3-2. Install magicpod-api-client
(No action required) The yml file is configured to run "download_magicpod_api_client.sh" as shown below. For more information about the magicpod-api-client, please consult this help page.
## .github/workflows/magicpod_test.yml
- name: Install magicpod-api-client
env:
MAGICPOD_API_TOKEN: ${{ secrets.MAGICPOD_API_TOKEN }}
run: bash download_magicpod_api_client.sh3-3. Run tests in MagicPod
Define MAGICPOD_ORGANIZATION_NAME, MAGICPOD_PROJECT_NAME, and MAGICPOD_TEST_SETTING_ID in the yml file. Tests will then be executed based on these specified batch run settings. In this example, two test cases are executed in three patterns, yielding a total of six tests.
## .github/workflows/magicpod_test.yml
- name: Run MagicPod
env:
MAGICPOD_API_TOKEN: ${{ secrets.MAGICPOD_API_TOKEN }}
MAGICPOD_ORGANIZATION_NAME: <YOUR ORGANIZATION_NAME>
MAGICPOD_PROJECT_NAME: <YOUR PROJECT_NAME>
MAGICPOD_TEST_SETTING_ID: <YOUR SETTING_ID>
run: python run_magicpod.py3-4. Register MagicPod test results in Xray
Define XRAY_ID and XRAY_SECRET in the yml file.
## .github/workflows/magicpod_test.yml
- name: Add test results to Xray
env:
XRAY_URL: <YOUR URL>
XRAY_ID: ${{ secrets.XRAY_ID }}
XRAY_SECRET: ${{ secrets.XRAY_SECRET }}
run: python xray_import_results.py
--magicpod-json magicpod_result 4. Run a job in GitHub Actions
This script will automatically run MagicPod and add test results to Xray each time code is pushed to GitHub. In addition to pushes, other events such as pull_requests and deployments can also trigger these actions. For more details, please check the GitHub Actions documentation.