Get Variable Value

Contentes
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")

Article author: Andrei Olegovich

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

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: