What are the different types of variables supported?

Robot Framework supports several types of variables to handle different kinds of data and scenarios in your tests. Here's a breakdown of the main variable types:

1. Scalar Variables (${...}):

  • Purpose: These are the most common type of variable. They hold a single value, which can be a string, number, boolean, or any other Python object.
  • Example :
  • ${USERNAME}    myuser
    ${AGE}        30
    ${IS_ADMIN}   True

2. List Variables (@{...}):

  • Purpose: These variables hold an ordered collection of values (like an array or list in other programming languages).
  • Example :
  • @{COLORS}    red    green    blue
    @{USER_ROLES}    admin    editor    viewer

3. Dictionary Variables (&{...}):

  • Purpose: These variables store key-value pairs (like a dictionary or hash map).
  • Example :
  • &{USER_DATA}  name=John   age=30   city=New York
    &{PRODUCT}    id=123   name=Laptop   price=999

4. Environment Variables (%env{...}):

  • Purpose: These variables access environment variables set in your operating system. This is useful for accessing system-specific information or configurations.
  • Example :
  • %{PATH}
    %{USERNAME}

5. Built-in Variables:

  • Purpose: Robot Framework provides some built-in variables that are always available. These can be useful for accessing information about the test execution environment or for performing certain tasks.
  • Examples:
    • ${CURDIR}: The absolute path to the directory where the test data file is located.
    • ${TEMPDIR}: The absolute path to the system temporary directory.
    • ${EXECDIR}: The absolute path to the directory where test execution was started from.

6. Extended Variable Syntax:

  • Purpose: Robot Framework also supports a more extended variable syntax that allows for more complex variable manipulation and evaluation. This includes features like variables inside variables and inline Python evaluation.

Key Considerations:

  • Variable type identifiers: The symbols ${...}, @{...}, &{...}, and %env{...} are used to identify the type of the variable.
  • Variable names: Variable names can contain letters, numbers, underscores, and spaces.
  • Variable scopes: Variables can have different scopes (global, suite, test case, local), which determine where they are accessible in your tests.