Skip to main content

How to Use TG Variables in Custom Script

Overview

TG Variables allow you to store and reuse values within your test cases. These variables can be defined and accessed inside custom scripts, making it easier to pass data between different test steps.

Steps to Use TG Variables

  1. Define the TG variable.
    • Create a variable following the required naming convention.

  2. Save the Value
    • Set the value of the variable within a custom script.

  3. Use the variable
    • To use the variable in a custom script, ensure it follows the format: ‘var_<variable_name>’.

Example

Using a TG Variable in a Custom Script

Once a variable is defined, it can be reused in subsequent test steps.

driver.findElement(By.xpath("//input[@id='userName']")).sendKeys(var_Username);

var_count = 465;

Once the variable is defined, it can be accessed and reused in other test steps. If you want to use it in the custom script, you need to use it as ‘var_<variable_name>’.

Using Custom Script Variables in Test Steps

If you define a variable inside a custom script like this:

int var_count = 465;

The system automatically treats it as a TG variable. This means:

  • It can be reused in later steps
  • It can be accessed across the same test case

Eg.—Using a TG Variable in a Custom Script Eg.—Using Custom Script Variables in Test Steps

Important Rule

The variable name inside the custom script must always start with “var_”.

Otherwise, it will not be recognized as a TG variable.

Example valid variables:

  • var_username
  • var_userEmail
  • var_orderId
Table of Contents