This page explains how to use different values for each test execution. For example:
Use a different user ID for every test run
Use a different coupon code for every test run
Use a different credit card number for every test run
Table of Contents
- When you can use the “Store unique value generated based on the current time” command
- When you cannot use the “Store unique value generated based on the current time” command
When you can use the “Store unique value generated based on the current time” command
By using the Store unique value generated based on the current time command, you can automatically generate a unique value for each test run.
This command generates a 14-digit number. If necessary, you can shorten the number by combining it with the Store substring matching regular expression command.
When you CANNOT use the “Store unique value generated based on the current time” command
In some cases, the Store unique value command cannot be used because a specific format or condition is required. Examples include:
Selecting a random coupon code from a set of valid candidates
Entering a 16-digit number into a credit card field
Generating a value that includes both letters and numbers
In such cases, consider one of the following methods:
1. Using the “Run TypeScript code” Command
This section explains how to generate a value that increments by 1 each day using the Run TypeScript code command.
This approach is effective for test cases that run once per day, such as scheduled executions.
Implementation steps:
- Use the “Store Fixed Value” command to save the base date into a variable.
(Example: 2026-01-01) - Use the “Date/Time Calculation” command to save today’s date into a variable.
(Format: yyyy-MM-dd) -
Use the “Run TypeScript Code” command to calculate the difference between the two dates, then save the result as an 8-digit zero-padded value into a variable.
If you want to use this across multiple test cases, you can also avoid duplicate values by using the first 1–2 digits as a test case identifier and zero-padding the remaining digits. This helps prevent value duplication when running multiple test cases.
2. Using a Web API
You can create a Web API that generates and returns values, then call it from MagicPod using the Web API Call command. This allows you to retrieve a different value for every test execution.
Below, we describe an example using Postman and its Mock Server to return an "8-character alphanumeric string", and how to retrieve it in MagicPod.
[Steps in Postman]
-
Create a new collection
From the left sidebar, select Collections and click ”+” or ”Create a collection”.
-
Add a GET request and configure a sample
Hover over the collection name in the sidebar and click the "+" button to add a new request to the collection. Select
GETas the HTTP method. Leave the request URL field blank for now, as it will be specified later.Next, click the "Three-dot menu" next to the request name in the sidebar and select "Add sample". Configure the sample with the following three settings:
・Status code:
200 OK・Header:
Key: Content-Type Value: application/json・Response body:
{ "randomString": "{{$randomAlphaNumeric}}{{$randomAlphaNumeric}}{{$randomAlphaNumeric}}{{$randomAlphaNumeric}}{{$randomAlphaNumeric}}{{$randomAlphaNumeric}}{{$randomAlphaNumeric}}{{$randomAlphaNumeric}}" } -
Create a mock server and link it to the collection
From the sidebar, select Mock Servers. (If Mock Servers is not visible in the sidebar, click the icon at the bottom of the sidebar to enable the Mock Servers view.)
Click the "+" button or "Create a mock server" to create a new mock server. Select "Existing collection", enter any mock server name, choose the collection you created earlier, and then click "Create mock server".
-
Set the mock server URL
Copy the issued mock server URL and paste it into the request and sample request URL field.
If the configuration is correct, clicking "Send" on the request or "Try" on the sample will display the generated "8-character alphanumeric string" at the bottom.
[Steps in MagicPod]
In your MagicPod test case, add a Web API Call command and configure as follows:
・Method: GET
・URL: (the mock server URL you created)
・ヘッダー:
Key: Content-Type
Value: application/json ・結果 :
Variable: randomString
Javascript: jsonResponse.randomString The retrieved ”8-character alphanumeric string” will be stored in the variable ${randomString} and can be used in subsequent test steps.
In an actual project, please prepare a Web API that suits your specific use case.
3. Passing values via command line
When executing tests in bulk from the command line, you can pass externally generated values as shared variables. By setting the value in advance, you can provide a different one for each execution.
For details, see: Sharing variables between test cases
4. Combining "Data Pattern" and "Conditional" command
If you want to use different values for scheduled runs (e.g., once per day), you can combine MagicPod’s Data Pattern feature with the Conditional command.
Implementation steps:
First, define a data pattern with the dates and their corresponding values.
Next, edit the test case as follows.
- Use the Date Calculation command to store the current day into a variable.
- Use the If variable equals command so that if the stored date matches the
${day}variable in the data pattern, the subsequent steps are executed.
With this approach, all data patterns are evaluated, but unnecessary steps are skipped by conditional branching, so the impact on execution time is minimal.
However, since the values need to be updated every month, we recommend using the Web API approach described above if you want to avoid the maintenance effort.