Get Variable Value

Contents
Documentation
Example
From Python library
Related articles

Introduction

In this article you can learn about the use of the Get Variable Value keyword in Robot Framework

A selection of articles about variables in Robot Framework you can study here

Documentation

Get Variable Value

Example

Show Execdir: Let's get the value of the ${EXECDIR} variable and output it to the console.

Demo Default: Let's make sure that if the variable does not exist, the default value will be substituted.

*** Settings *** *** Test Cases *** Show Execdir ${e_dir} = Get Variable Value ${EXECDIR} Log To Console ${\n}Execdir is: Log To Console ${e_dir} Log To Console ${EXECDIR} Should Be Equal ${e_dir} ${EXECDIR} Demo Default ${un} = Get Variable Value ${ABC} Unknown Log To Console ${un}

============================================================================== Demo ============================================================================== Show Execdir . Execdir is: .C:\Users\Andrei\robot .C:\Users\Andrei\robot Show Execdir | PASS | ------------------------------------------------------------------------------ Demo Default .Unknown Demo Default | PASS | ------------------------------------------------------------------------------ Demo | PASS | 2 tests, 2 passed, 0 failed ============================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

It is not clear from this example why it is necessary to call the function separately when you can simply output the value to the terminal by substituting the variable itself into the Log To Console keyword.

In the following example we use Get Variable Value from an external library.

Get value from Python library

Let's assume we use an additional Python library.

This library has a function that uses the value of a Robot Framework variable.

It can get this value using Get Variable Value

get_var_demo/ |-- Libraries | `-- common.py `-- Tests `-- demo_lib.robot

# demo_lib.robot *** Settings *** Library ../Libraries/common.py *** Test Cases *** With Lib Run If Execdir Is Robot

# common.py from typing import Any from robot.api import logger from robot.libraries.BuiltIn import BuiltIn _built_in = BuiltIn() def get_robot_variable(variable_name: str) -> Any: return _built_in.get_variable_value("${" + variable_name + "}") def run_if_execdir_is_robot(): exec_dir = get_robot_variable("EXECDIR") if exec_dir == "C:\Users\Andrei\robot": logger.info("Running") else: logger.info("Not running")

Related Articles
Robot Framework
Declare a variable
Reasssign variable
Get Variable Value
Passing arguments to a keyword
Evaluate

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat