The Variables feature allows you to temporarily store values from a UI for later reference. For example, you can store the text of a UI element in a variable and then check if it matches the text of another UI element on a different page.
Table of Contents
- Store values in variables
- Refer to variable values
- Special variables
- Use shared variables
- Mask variables
- Pass variables between test cases
- Date format for the "Date calculation” command
- Order in which variables are set
1. Store values in variables
You can use different commands to store values in variables.
- Store value: Stores element values on the page in variables (see Figure 1).
- Store current second-based unique value: Stores a unique value each time the test is executed. This is useful in many cases where a different value needs to be used every time a test is run (e.g. tests that require different IDs for each user registration).
- Store fixed value: Stores specified values in variables.
Figure 1. The Store value command.
2. Refer to variable values
Refer to stored variables using the format ${variable name} (see Figure 2).
Figure 2. Refer to variables.
Note that:
- The stored variables can only be referenced within the same test case.
- When storing variables, name them without using ${...}. Use these symbols when referring to them later in the test case.
- Variables can also be referenced from locators using the ${variable name} format. Learn more about adding and editing locators here.
3. Special variables
MagicPod defines special variables that can be referenced directly using ${variable name} without needing to store them first.
| Name | Environment | Description |
| ENVIRONMENT | Mobile app/browser | Test execution environment. Any of “local_pc”, “magic_pod”, “browserstack”, “remote_testkit”, or “saucelabs”. If “Cloud” is selected, this is “magic_pod” |
| OS | Mobile app/browser | For the mobile app, this is one of “ios” or “android”, and for the browser, this is one of “windows”, “mac”, “linux”, “ios”, or “android”. |
| 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 one of “simulator”, “emulator”, “arm64_v8a_emulator”, or “real_device”, and for the browser, this is one of “desktop” or “mobile_emulation_by_chrome” |
| DEVICE_REGION | Mobile app | Device region. One of “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. One of “default”, “en”, “ja”, “ko”, “zh”, “de”, “it”, “nl”, “pt”, “fr”, “id”, “th”, “ar”, “ru”, “es”, “bg”, “cs”, or “hu” |
| APP_PACKAGE | Mobile app | Android app package name. Can be used only with Android. “io.appium.android.apis”, etc. |
| BROWSER | Browser | Browser name. One of “chrome”, “firefox”, “internet_explorer”, “safari”, or “edge” |
| BASE_URL | Browser | “Base URL” specified in the test execution settings |
- Special values may differ from actual device information if specified in test execution settings. 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 iPhone, the MODEL value is also iPhone rather than the exact model name (i.e., iPhone 7).
- These special values cannot be referenced if a variable is overwritten by a variable save command or by a secret variable as described below.
4. Use shared variables
You can register values that are commonly used across multiple test cases in the same project, such as login information for the app under test, as shared variables.
Register shared variables in the Advanced settings tab of the test run settings dialog. Enter any variable name in the left column and its value in the right column.
To learn how to pass shared variables from outside when running batch tests, see Specifying Shared Variables for Command Line Batch Runs.
5. Mask variables
To keep sensitive information like API tokens and passwords hidden, use secret variables.
- Register secret shared variables in the Advanced Settings tab of the test run settings dialog.
- Enter the variable name and value, then click the lock symbol to mark it as secret (see Figure 3).
- Reference secret shared variables using the same notation as variables ${...}.
Figure 3. Set up secret shared variables.
Figure 4. Define authentication tokens as shared variables with Web API call.
Secret shared variable values are masked on the test result logs as “********”.
Please note that masked values may still be visible in certain scenarios, such as if text entries are made outside password fields.
6. Pass variables between test cases
If you want to use predefined variables across multiple test cases, you can use shared variables.
However, shared variables cannot be used to carry over variables that are defined (or updated) during a test case run to another test case.
To learn how to pass a variable saved in Test Case A to Test Case B, see How to Pass Variables Between Test Cases.
If you would like to use saved variables directly in another test case, please vote for Use variables saved in one test case in another test case on the MagicPod Product Portal.
7. Date format for the "Date calculation” command
When using the Date calculation command, there are cases where you cannot achieve what you need to do by using only 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.
Figure 6. 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 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 calculation command is in the System category. Take note of this.
Figure 7. The Date calculation command
8. Order in which variables are set
When there are multiple data pattern values and variables, variables 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 been set can be referenced using ${...}. If a variable with the same name is set again, the old value will be overwritten.