You may want to specify variable values externally when running tests, for example, when using different values in development and production environments.
In MagicPod, you can use shared variables to specify arbitrary values when running batch tests from the command line.
Running Tests in a Cloud Environment
Reference: Run batch tests from the command line (Cloud environment)
In a cloud environment, you can specify shared variable values at runtime by using a command format that does not use test_settings_number.
First, create a batch run setting that includes shared variables on the batch run settings page.
Then, click the three-dot menu (︙) to the right of the Run new batch button and select Run from command line.
From the Execution method drop-down menu, select a command labeled (detailed settings).
The following section uses the magicpod-api-client Method as an example.
When you select (detailed settings), a command is displayed in which the batch run settings are written directly in the command instead of being referenced by test_settings_number.
Because the settings written in the command can be edited freely, copy the command and set the desired value in the value field under shared_variables.
This allows you to run tests using the specified shared variable values.
Setting Secret Shared Variables Using Environment Variables
If the batch run settings contain secret shared variables, the (detailed settings) command uses environment variables by default.
For example, if a secret shared variable named PASSWORD is configured, ${PASSWORD} is set in the value field under shared_variables.
"shared_variables": [
{
"key": "PASSWORD",
"value": "${PASSWORD}",
"secret": true
}
]A statement for assigning a value to the environment variable is also added at the beginning of the command, as shown below.
SECRET_API_TOKEN="***" PASSWORD="FILL_IN_THE_VALUE" ./magicpod-api-client batch-run ...
Before running the command, replace "FILL_IN_THE_VALUE" for PASSWORD with the value you want to use.
You can also enter a secret shared variable value directly in the value field under shared_variables without using an environment variable.
"shared_variables": [
{
"key": "USERNAME",
"value": "test_user",
"secret": false
},
{
"key": "PASSWORD",
"value": "test_pass",
"secret": true
}
]Note: In the command that is actually copied, double quotation marks in the JSON, including those under shared_variables, are escaped. The escape characters are omitted from the examples above for readability.
Running Tests in a Local PC Environment
Reference: Run batch tests from the command line (Local PC environment)
In a local PC environment, you can specify shared variable values for command line batch runs by configuring shared variables under testCondition.shared_variables in magic_pod_config.json.
For example, suppose you are using the following magic_pod_config.json file.
{
"owner": "SampleCompany",
"project": "SampleApp",
"capabilities": {
"platformName": "iOS",
"platformVersion": "10.3",
"deviceName": "iPhone 7 Plus",
"app": "${HOME}/magicpod_demo_app.app",
"automationName": "XCUITest"
},
"sendMail": true,
"workDir": "${HOME}/magicpod-work"
}To use shared variables, add the testCondition property and configure the variables under shared_variables.
{
"owner": "SampleCompany",
"project": "SampleApp",
"capabilities": {
"platformName": "iOS",
"platformVersion": "10.3",
"deviceName": "iPhone 7 Plus",
"app": "${HOME}/magicpod_demo_app.app",
"automationName": "XCUITest"
},
"sendMail": true,
"workDir": "${HOME}/magicpod-work",
"testCondition": {
"shared_variables": [
{
"key": "USERNAME",
"value": "test_user",
"secret": false
}
]
}
}After configuring the shared variables, you can run the tests using the same command as for a standard command line batch run.
Setting Secret Shared Variables Using Environment Variables
When using a secret shared variable, you can specify an environment variable in the value field under shared_variables.
For example, to use a secret shared variable named PASSWORD, set ${PASSWORD} as its value.
{
...
"testCondition": {
"shared_variables": [
{
"key": "USERNAME",
"value": "test_user",
"secret": false
},
{
"key": "PASSWORD",
"value": "${PASSWORD}",
"secret": true
}
]
}
}When running the tests, assign a value to the environment variable before executing the command.
The following is an example for macOS.
PASSWORD=test_pass "MagicPodDesktop.app/Contents/MacOS/MagicPodDesktop" run --magic_pod_config="<magic_pod_config.jsonのフルパス>"
You can also enter a secret shared variable value directly in the value field under shared_variables without using an environment variable.
"shared_variables": [
{
"key": "USERNAME",
"value": "test_user",
"secret": false
},
{
"key": "PASSWORD",
"value": "test_pass",
"secret": true
}
]