Using Variables

Knowing how to use variables is essential while working on WebTestware.

Following restrictions applies to variables.

  • Variable names can be of max length 30 chars
  • Variable names can only have alpha numeric.

Mention only variable name like var1 in Variable property wherever asked.



Use variable name with @ like @var1 if it needs to be used with other values.



For example:

1. Navigate based on variable value.

  • Add SetVariable action to test method. Set its property like below
    Value https://www.google.com
    Variable launchUrl
  • Add NavigateUrl action to test method. Set its property like below
    URL @lauchURL
  • Now browser is navigated to variable value set rather than a constant URL.

2. Using variable in SQL query

  • Add SetVariable action to test method. Set its property like below
    Value USA
    Variable countryName
  • Add SqlExecuteQuery action to test method. Set SQL property like below where variable define is used.

    select * from country where name = '@countryName'

3. Using variables in text

  • Add SetVariable action to test method. Set its property like below
    Value USA
    Variable countryName
  • Add Log action to test method. Set Text property like below where variable define is used.
    Text Name of the country is:@countryName

Note that almost all Variable properties show all existing variable names in drop down.

Defining variables

Type 1: Variables are automatically created when used.

For example: Add Get Current URL action to a test method. Mention any name for Variable property. Variable with given name is created automatically and value is set when action is executed. Explicit variable declaration is not required.

Type 2: Explicitly add SetVariable action to create a new variable. This option is typically used for project settings etc.

Using variable actions

  • Remove variable - Action to remove a variable during test execution.
  • Set Variable - Use this action to set a variable value. New variable is created if given variable doesn't exists.

Concatenate variables

Use character ` (back-tick) to concatenate two variables

For example: if var1 value is 'abcd' and var2 value is 'xyz', then

  • @var1`@var2 gives result abcdxyz
  • @var1`@var2qwerty gives result abcdxyzqwerty. Note that WebTestware recognizes variable in the text and apply value at the place of variable.