Table of Contents
Overview
When running tests using the MagicPod Web API, you must send test configuration information in the request body.
There are two primary ways to specify test settings:
Create a batch run setting in advance and specify its Batch Run Settings Number at execution time
Specify each test setting individually at execution time
The former approach is recommended, as it allows you to use the settings created and edited in the Web UI.
However, there are cases where you may want to partially modify the settings defined in a batch run setting at execution time—for example, when you want to overwrite the values of shared variables.
Among the MagicPod Web APIs, the Cross Batch Run API allows you to specify a Batch Run Settings Number as the base configuration and overwrite only the required settings while running the test.
Please note that the MagicPod Web API is supported only in cloud environments and external cloud environments. Currently, it is not possible to run tests while specifying a Batch Run Settings Number and overwriting some settings in a local PC environment.
This limitation is recognized as an issue and has already been filed as a feature request.
If you would like this feature to be implemented, please vote for it from here. (See here for how to vote.)
Implementation
1. curl Format (Mac / Linux Terminal)
For general usage, please refer to the documentation here.
In the request body (-d) of the command, specify the following:
test_settings_number: Specify the Batch Run Settings Number to be used as the base configurationtest_settings: Specify the individual settings you want to overwrite
The Batch Run Settings Number is the number shown at the beginning of the setting name on the batch run settings page.
For example, the command looks like the following:
curl -X 'POST' 'https://app.magicpod.com/api/v1.0/<organization_name>/<project_name>/cross-batch-run/'
-H 'Authorization: Token <your_API_token>'
-H 'Content-Type: application/json'
-d '{
"test_settings_number": <batch_run_settings_number>,
"test_settings": [
{
"<setting_to_overwrite>": "<value>"
}
]
}'Below is an actual example command.
Example: Batch Run Setting Number = 1, specify the Target Test Case Numbers (1, 2, 3)
SECRET_API_TOKEN="<your_API_token>"
STATUS_CODE=$(curl -sS -o /dev/stderr -w %{http_code} -X \
POST https://app.magicpod.com/api/v1.0/<organization_name>/<project_name>/cross-batch-run/ \
-H "Authorization: Token ${SECRET_API_TOKEN}" \
-d "{
\"test_settings_number\": 1,
\"test_settings\":[
{
\"test_case_numbers\":\"1, 2, 3\"
}
]
}")
test "$STATUS_CODE" = "200"(You can use this command as-is by replacing <your_API_token>, <organization_name>, and <project_name> with your own values. Please also adjust the value of test_settings_number and the contents under test_settings as needed for your execution settings.)
For other configurable settings, open Batch Run Settings > Three-dot menu > Run from command line, and select “Run with curl (Mac/Linux terminal) (detailed settings)” to view the corresponding command.
2. Invoke-RestMethod Format (Windows PowerShell)
For general usage, please refer to the documentation here.
In the request body (-Body) of the command, specify the following:
test_settings_number: Specify the Batch Run Settings Number to be used as the base configurationtest_settings: Specify the individual settings you want to overwrite
The Batch Run Settings Number is the number shown at the beginning of the setting name on the batch run settings page.
For example, the command looks like the following:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod
-Method POST
-Uri https://app.magicpod.com/api/v1.0/<organization_name>/<project_name>/cross-batch-run/
-Headers @{"Authorization" = "Token " + <your_API_token>}
-Body "{
"test_settings_number": <batch_run_settings_number>,
"test_settings": [
{
"<setting_to_overwrite>": "<value>"
}
]
}"Below is an actual example command.
Example: Batch Run Setting Number = 1, specify the Target Test Case Numbers (1, 2, 3)
$SECRET_API_TOKEN = "<your_API_token>"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod
-Method POST
-Uri https://app.magicpod.com/api/v1.0/<organization_name>/<project_name>/cross-batch-run/
-Headers @{"Authorization" = "Token " + ${SECRET_API_TOKEN}}
-Body "{
`"test_settings_number`": 1,
`"test_settings`": [
{
`"test_case_numbers`":`"1, 2, 3`"
}
]
}"(You can use this command as-is by replacing <your_API_token>, <organization_name>, and <project_name> with your own values. Please also adjust the value of test_settings_number and the contents under test_settings as needed for your execution settings.)
For other configurable settings, open Batch Run Settings > Three-dot menu > Run from command line, and select “Run with Invoke-RestMethod (Win PowerShell) (detailed settings)” to view the corresponding command.
3. magicpod-api-client Format
For general usage, please refer to the documentation here.
Specify the following options in the command:
-S: Specify the Batch Run Settings Number to be used as the base configuration-s: Specify the individual settings you want to overwrite inside thetest_settingsparameter
The Batch Run Settings Number is the number shown at the beginning of the setting name on the batch run settings page.
For example, the command looks like the following:
./magicpod-api-client batch-run
-t <your_API_token>
-o <organization_name>
-p <project_name>
-S <batch_run_settings_number>
-s "{
"test_settings": [
{
"<setting_to_overwrite>": "<value>"
}
]
}"Below is an actual example command.
Example: Batch Run Setting Number = 1, specify the Target Test Case Numbers (1, 2, 3)
SECRET_API_TOKEN="<your_API_token>"
./magicpod-api-client batch-run \
-t ${SECRET_API_TOKEN} \
-o <organization_name> \
-p <project_name> \
-S 1 \
-s "{
\"test_settings\": [
{
\"test_case_numbers\":\"1, 2, 3\"
}
]
}"(You can use this command as-is by replacing <your_API_token>, <organization_name>, and <project_name> with your own values. Please also adjust the value of test_settings_number and the contents under test_settings as needed for your execution settings.)
For other configurable settings, open Batch Run Settings > Three-dot menu > Run from command line, and select “Run with magicpod-api-client (detailed settings)” to view the corresponding command.
4. Notes on Overwriting Shared Variables
When overwriting shared variables, you must specify all shared variables defined in the base batch run setting, not only the variables you want to change, under test_settings.
If you specify only some of the shared variables, any shared variables that are not specified will not be inherited.
As an example, assume that the following three shared variables are defined in the batch run setting:
In this situation, if you want to change only the value of USERNAME and run the test by specifying only USERNAME under shared_variables in test_settings, only USERNAME will be set, and EMAIL and PASSWORD will not be inherited.
This is because the contents specified in shared_variables are applied by replacing the entire set of shared variables defined in the batch run setting.
Therefore, when overwriting shared variables, make sure to specify all shared variables defined in the batch run setting under shared_variables, and then change only the values of the variables you need.
This behavior is also recognized as an issue and has already been filed as a feature request.
If you would like this feature to be implemented, please vote for it from here. (See here for how to vote.)