Connect variables from a .py file in Robot Framework

Introduction

In this article you can see an example of importing variables from an external Python file.

The test itself will include a .resource file, and that file will in turn include the .py file as Variables

Example

In this example you can see how from a single .resource file you can get variables from both the Variables block and the Settings block

demo |-- Libraries |-- Resources | |-- demo.resource | `-- my_vars.py `-- Tests `-- demo.robot

demo.robot

*** Settings *** Resource ../Resources/demo.resource *** Test Cases *** Using Var From Python File Log To Console \n OUTPUT: Log To Console ${URL} Log To Console ${HOSTING}

demo.resource

*** Settings *** Variables my_vars.py *** Variables *** ${HOSTING}= https://beget.com

my_vars.py

URL = "https://devhops.ru"

robot demo.robot

============================================================================== Demo ============================================================================== Using Var From Python File OUTPUT: .https://devhops.ru .https://beget.com Using Var From Python File | PASS | ------------------------------------------------------------------------------ Demo | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: C:\Users\Andrei\robot\demo\Tests\output.xml Log: C:\Users\Andrei\robot\demo\Tests\log.html Report: C:\Users\Andrei\robot\demo\Tests\report.html

Article author: Andrei Olegovich