When using the “Variables” function, the values on the screen can be temporarily stored for later reference. For example, it can be used to “store the text of a certain UI element as a variable, and check that it matches the text of another UI element on a different screen”.
Table of Contents
- Store values as variables
- Referencing variable values
- Special variables
- Handling of variables you wish to mask
- Sharing variables between test cases
- Date format for the "Date(Time) calculation” command
- Order in which variables are set
1. Store values as variables
- With the “Store value” command, you can store element values on the screen as variables. (Figure 1)
- With the “Store the current second based unique value” command, you can store values that are unique each time as variables. This can be used for tests, etc., where you register users with a different ID each time.
- With the “Store fixed value” command, you can store specified values as variables.
Figure 1 “Store value” command
2. Referencing variable values
The stored variable can be referenced with the format ${variable name} from text from that line onwards. (Figure 2)
Figure 2 Referencing variables
- The stored variables can only be referenced from the same test case.
- With the command for storing the variables, the variable name is written without the ${...}, but when referring to the variable, this is referenced as ${...}. Please take note of the above.
3. Special variables
The following variables are special variables defined by Magic-Pod, and they can be referenced in the ${variable name} format without using the command for storing the variables.
ENVIRONMENT | Mobile app/browser | Test execution environment. Any of “local_pc”, “magic_pod”, “browserstack”, “headspin”, “remote_testkit”, or “saucelabs”. If “Cloud” is selected, this is “magic_pod” |
OS | Mobile app/browser | For the mobile app, this is either “ios” or “android”, and for the browser, this is either “windows”, “mac”, or “linux.” |
VERSION | Mobile app | OS version “13.3” or “10”, etc. |
MODEL | Mobile app | Model. “iPhone 8”, “Nexus 5X”, etc. |
DEVICE_TYPE | Mobile app/browser | Device type. For the mobile app, this is either “simulator”, “emulator”, “arm64_v8a_emulator”, or “real_device”, and for the browser, this is either “desktop” or “mobile_emulation_by_chrome” |
DEVICE_REGION | Mobile app | Device region. Either “Default”, “AU”, “BR”, “CA”, “CN”, “FR”, “DE”, “IN”, “ID”, “IT”, “JP”, “MX”, “NL”, “RU”, “SA”, “KR”, “ES”, “CH”, “TW”, “TR”, “GB”, or “US” |
DEVICE_LANGUAGE | Mobile app | Device language. Either “default”, “en”, “ja”, or “ko” |
APP_PACKAGE | Mobile app | Android app package name. Can be used only with Android. “io.appium.android.apis”, etc. |
BROWSER | Browser | Browser name. Either “chrome”, “firefox”, “internet_explorer”, “safari”, or “edge” |
BASE_URL | Browser | “Base URL” specified in the test execution settings |
- Note that values such as VERSION, MODEL, DEVICE_TYPE, DEVICE_REGION, and DEVICE_LANGUAGE are the values specified in the test execution settings, and may differ from the information of the device that is actually used. For example, when specifying the model for external Cloud services as an “iPhone”, the MODEL value is also “iPhone” rather than the exact model name (i.e., “iPhone 7”).
- It should be noted that the above special values cannot be referenced if a variable with the same name is overwritten by a variable save command or by a secret variable as described below.
4. Handling of variables you wish to mask
If there are values that you do not want to display on the Edit test case screen, results screen, or logs, etc., such as Web API access tokens and password input values, these can be masked by registering them as secret shared variables. Register shared variables on the Details tab of the pop-up screen used for configuring test runtime settings.
Enter an arbitrary variable name in the left column and the value in the right. Click the key symbol in the red box to change a shared variable to a secret shared variable.
Setup of shared variables
It is possible to reference set variables with ${...} in the same way as normal variables. For example, when used for Web API call, this is as follows.
Figure 4 Defining authentication tokens as shared variables with Web API call
Secret shared variable values are masked on the test result logs as “********”.
Note that this feature does not 100% guarantee that the masked values will be invisible. For example, if a masked value is entered as text outside of the password entry area, the value in question could easily be displayed on the application screen.
5. Sharing variables between test cases
・Using shared variables when running tests as a batch
It is possible to register values common to multiple test cases in the same project, such as login information for the application(s) targeted for testing, as shared variables.
Select the Detail tab and register from the test batch execution setup screen.
・Using shared variables from the command line
There are two ways to run test cases with shared variables from the command line.
1. Write the variable value(s) directly in the magic_pod_config.json file
For example, let’s assume that the test was originally run on a JSON file such as this one.
{
"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"
}
This is somewhat complicated, but if you add the following configuration, you can pass shared variables for execution. In this example, the two variables USERNAME and PASSWORD (PASSWORD is a secret shared variable) are set.
{
"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
},
{
"key": "PASSWORD",
"value": "secret_password",
"secret": true
}
]
}
}
Use the same commands to run the test as for normal command line execution.
2. Setup Using Environment Variables
If you want to manage secret shared variable values in a stricter way without leaving them in a file, you can also set them using environment variables. In this case, the description of the magic_pod_config.json file is as follows.
{
"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
},
{
"key": "PASSWORD",
"value": "${PASSWORD}",
"secret": true
}
]
}
}
In this case, the actual value must be given at the time of execution. Therefore, the command to be run is as follows.
PASSWORD=secret_password "MagicPodDesktop.app/Contents/MacOS/MagicPodDesktop" run \
Full path to --magic_pod_config=magic_pod_config.json
6. Date format for the "Date(Time) calculation” command
When using the "Date(Time) calculation " command, there are cases where you cannot achieve what you need to do by using only the "Date type" provided from the start (for example, if you want to get a description of a month that includes zeroes, such as "07(July)"). In such a case, you can specify various "Date format" by setting the "Date type" to "Custom date format". For example, if you want to store the month value in the form of a zero-padded variable, you can specify "MM" in the "Date format".
Date format for displaying the month with zeroes included
In addition, by writing “EEE, MM/dd/yyyy, hh:mm:ss”, you can save the date and time, as “Thu, 07/14/2022, 10:55:00”, in a variable. The library called “date-fns” can be used to describe the “Date format”. See here for a more detailed method of description.
You can also use variables in the "Date format" input area. For this reason, you can specify, for example, the string "MM" to be stored in advance in the variable "MONTH_FORMAT" and ${MONTH_FORMAT} for the date format.
The “Date(Time) calculation” command is in the “System” category. Please take note of this.
7. Order in which variables are set
If there are multiple data pattern values and variables, these are set in the following order.
- Shared variables
- Multi-lang data pattern
- Data pattern
- Command for saving variables in a test script
- Variables that have already been set can be referenced using ${...}.
- In case a variable with the same name is already set, the old values will be overwritten with the newly set values.