How to Reuse a Variable Value Across Two Test Cases
Overview
Sometimes the same value - for example a batch ID - needs to appear in two different interfaces or test cases, and it must be the exact same value in both. This guide shows how to capture a value from one message and reuse it in another, covering two different setup paths depending on your licensing:
-
Int4 Shield (manual) - without parent/child test case linking. You enter the value once, then re-enter the same value in the second test case.
-
Int4 API Tester (automated) - with parent/child inheritance. The second test case automatically inherits the value from the first, so you never re-enter it manually.
Step-by-step instructions
1. Decide which variable value you want to reuse
Use this approach whenever you need to capture a value from one message and reuse the exact same value in another interface or test case.
-
Identify the field to reuse - typically something like a batch ID in an XML, JSON, or flat file message.
-
Decide which setup path applies to your license:
-
Int4 Shield - manual, no parent/child linking
-
Int4 API Tester - automated, with parent/child inheritance
-
⚠️ Important: Which path you take depends entirely on licensing. If you do not have an Int4 product license allowing you to link Test Cases , you must use the manual approach described in Step 5.
2. Create a variable in the automation object
Create the variable that will hold the reusable value.
-
Open the relevant Automation Object for the test case.
-
Click Edit.
-
Go to Variables and create a new variable.
-
Give it a clear name and description, for example:
-
Name:
batch -
Description:
batch ID
-
3. Configure the variable to read from the source message and replace the value
Configure the variable action so it both reads the source value and replaces it in the target message.
-
Set the variable action to Read and Replace.
-
Open the edit/configuration view for the variable.
-
In the Read section, choose where the value comes from - for this example, select Read from saved message.
-
Use the expression helper to import the payload from the relevant test case.
-
Select the correct payload type depending on your setup:
-
Payload or
-
Input message for certain test types such as PO Unit Test
-
-
Use the XPath helper to select the exact field/node you want to capture, such as a custom batch ID field in an IDoc.
-
In the Replace section, choose how the value should be replaced. For the manual path, choose Read user-defined value from test case so the value can be entered at test case level.
4. Save the automation object and enter the variable value at test case level
Save the configuration and provide the actual value that will be used when the test case runs.
-
Save the automation object after configuring the variable.
-
Open the test case details.
-
Look for the new Edit variable values section - this appears only when the variable is configured to read a user-defined value.
-
Enter the desired value for the variable, such as a specific batch ID.
-
Save the variable values.
When the message is sent, the variable uses the value you entered here.
5. Option A - Manual linking with Int4 Shield (no parent/child license)
If you do not have parent/child linking available, repeat the same setup manually for the second interface.
-
Create the same variable in the second Automation Object/test case.
-
Enter the same value again in Edit variable values.
-
Run the test cases one by one, in sequence.
Each test case uses the manually provided value.
⚠️ Note: This is the only option available under an Int4 Shield license. It works reliably but requires you to keep the value in sync by hand across every test case that needs it. If you have an Int4 API Tester license, Step 6 below removes this manual step entirely.
6. Option B - Automated inheritance with Int4 APITester
In Int4 APITester, avoid manually re-entering the same value by having the second test case inherit it automatically.
-
Create the variable again in the second Automation Object, but configure it slightly differently.
-
Keep the action set to Read and Replace.
-
Read the value from the message using the correct XPath for that interface.
-
In the Replace section, choose Read from previous test case instead of a user-defined value.
-
Enter the variable name used in the previous test case, for example
batch. -
Save the automation object.
7. Link the test cases so the second one inherits the variable value
Establish the parent/child relationship so the inheritance configured in Step 6 actually takes effect.
-
Link the second test case to the first as a child of the parent test case.
-
Example shown in the recording: test case
989075linked to the earlier test case as its parent.
When the test cases run in sequence, the second test case inherits the variable value from the first automatically.
8. Verify that the value was carried forward
Confirm the automated inheritance worked as expected.
-
Run the linked test cases.
-
In the first test case, confirm the variable value was set correctly at the test case level.
-
In the second test case, confirm the value was read from the previous test case.
💡 Tip: Even if the message itself fails to send in a demo environment, you can still verify the variable inheritance directly in the test case details.
Expected outcome
-
✅ A variable is configured on the automation object to Read and Replace a specific field value
-
✅ Option A (Int4 Shield): the same value is entered manually in both test cases and produces consistent results when run in sequence
-
✅ Option B (Int4 APITester): the child test case is linked to its parent and automatically inherits the value, with no manual re-entry
-
✅ The inherited or manually-entered value has been verified in the test case details
Troubleshooting
|
Issue |
Likely cause |
Resolution |
|---|---|---|
|
No Edit variable values section appears on the test case |
Variable is not configured to read a user-defined value |
Set the Replace action to Read user-defined value from test case (Step 3) |
|
Second test case does not inherit the value |
Test cases are not linked as parent/child, or the variable name does not match |
Confirm the child link (Step 7) and check the variable name entered under Read from previous test case matches the parent's variable name exactly (e.g. |
|
Wrong field value captured |
Incorrect XPath selection |
Re-open the XPath helper and re-select the exact field/node in the source payload |
Related resources
-
Int4 Suite Knowledge Center: Variables and Variable Processing