以下是我要做的:
我正在尝试编写一个机器人框架监听器,我需要向它传递一些论点。
robot --listener /path/to/MyListener.py -v VARIABLE_NAME1:VARIABLE_VALUE1 -v VARIABLE_NAME2:VARIABLE_VALUE2 -d Results /path/to/Test.robot
我想将VARIABLE_NAME1和VARIABLENAME2等作为参数传递给MyListener.py,而不是按如下方式编写它们:
robot --listener /path/to/MyListener.py;VARIABLE_VALUE1:VARIABLE_VALUE2 -d Results /path/to/Test.robot
这能做到吗?感谢提前提供的任何帮助/指导。
这是我的问题的答案:
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
from robot.api import logger
class SampleListener:
ROBOT_LISTENER_API_VERSION = 2
def __init__(self):
self._variables = None
def get_all_variables(self):
"""
Gets all the RobotFramework Command Line variables as a dictionary
Returns: Dictionary of command line variables
"""
self._variables = dict(BuiltIn().get_variables())
return self._variables
从此以后,您可以从self访问变量_变量