In one of my projects weare using Robot Framework and a special listener to push results via XRAY to Jira.
Now, we want to call Robot Framework in two different modes named A or B, and different labels need to pushed via XRay to Jira.
I don't want to set some environment variables prior to call robot, as they are really hard to track.
What might be the easiest way to make a global variables of a Robot Framework run accessible in a Robot Framework listener.
I just want to call robot something like this:
robot --listener XRayListener.py --variable Mode:A
How, can I now access the variable Mode inside of XRayListener.py
As detailed in this article , from the listener python code you can use BuiltIn().get_variables() to obtain a given variable value.
from robot.libraries.BuiltIn import BuiltIn
ROBOT_LISTENER_API_VERSION = 2
def end_test(name, attributes):
print("BROWSER = '%s'" % BuiltIn().get_variables()['${BROWSER}'])
Then run it as:
robot --listener ShowVariable simple.robot
The robot file, just for mere reference was:
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${URL} https://www.google.com/
${REMOTE_URL} http://192.168.56.1:4444/wd/hub
${BROWSER} Chrome
*** Test Cases ***
Confirm login popup is accessable
#Go To ${URL}
open browser ${URL} ${BROWSER}
set window size 350 800
[Teardown] Close Browser(base