This guide explains two methods for passing a variable saved in Test Case A to Test Case B, so that it can be reused across different test cases.
If you need to use a pre-defined variable across multiple test cases, we recommend using the Shared Variable.
Additionally, if the steps involved in passing a variable between two separate test cases (A and B) are not too complex, you may also consider consolidating them into a single test case for better maintainability.
1. Using Local Storage Commands
The first method involves using Local Storage.
MagicPod provides the following commands related to Local Storage:
Using these commands, you can pass variables between test cases.
Usage Steps:
-
In Test Case A (the sender), insert the Set value to local storage command to store the variable.
-
In Test Case B (the receiver), insert the Store local storage value command to retrieve the variable.
⚠️ In Test Case B, be sure to set the browser launch option to Restart process only at the first run, or the Local Storage data may not persist correctly.
💡 For better maintainability, it is recommended to place the retrieval logic (i.e., the "Save value from Local Storage" command) at the beginning of Test Case B. This clarifies the test’s dependency on another test case.
2. Using a Web API
Another approach is to use a Web API.
In this method, Test Case A sends the variable to an external API server via a POST request, and Test Case B retrieves the value via a GET request. This allows variable values to be passed across test cases through API communication.
This method requires creating and publishing a Web API. Below is the general procedure.
-
Create a Web API
You will need to implement an API server that supports both of the following:
・A POST request to send the variable
・A GET request to retrieve the variable
-
Test Case A: Save the Variable and Send to API
(1) Save a Unique Value to a Variable
For example, use the Store unique value generated based on the current time command into a variable named
USER_ID.USER_ID = 20250708045743
(2) Send the Variable via Web API (POST)
Use the Web API Call command to send the saved variable to the API.
・Method:
POST・URL:
https://<your-api-server-domain>/users・Body:
{ "key": "user_id", "value": "${USER_ID}" }This request temporarily stores the value associated with the key (e.g.,
user_id) on the server. -
Test Case B: Retrieve the Value from API and Reuse It
(1) Retrieve Variable via Web API (GET)
Use the Web API Call command to fetch the value stored previously.
・Method:
GET・URL:
https://<your-api-server-domain>/users・Header:
Key: Content-Type Value: application/json
・Result:
Variable: USER_ID JavaScript: jsonResponse["users"][0]["user_id"]
The expression
jsonResponse["users"][0]["user_id"]retrieves the most recent user ID that was sent via the earlier POST request.(2) Use the Variable
The retrieved
${USER_ID}can then be used in subsequent steps in the test.
That concludes the explanation of how to pass variables between test cases using a Web API.