如何将命令行变量作为参数传递给 RobotFramework Listener?
How can I pass a command line variable as an argument to RobotFramework Listener?
这是我正在尝试做的事情:
我正在尝试编写一个 robotframework 侦听器,我需要向它传递一些参数。
robot --listener /path/to/MyListener.py -v VARIABLE_NAME1:VARIABLE_VALUE1 -v VARIABLE_NAME2:VARIABLE_VALUE2 -d Results /path/to/Test.robot
我想将 VARIABLE_NAME1 和 VARIABLE_NAME2 等作为参数传递给 MyListener.py,而不是按如下方式编写它们:
robot --listener /path/to/MyListener.py;VARIABLE_VALUE1:VARIABLE_VALUE2 -d Results /path/to/Test.robot
这能做到吗?提前欣赏任何help/guidance
这是我的问题的答案:
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._variables
访问变量
这是我正在尝试做的事情:
我正在尝试编写一个 robotframework 侦听器,我需要向它传递一些参数。
robot --listener /path/to/MyListener.py -v VARIABLE_NAME1:VARIABLE_VALUE1 -v VARIABLE_NAME2:VARIABLE_VALUE2 -d Results /path/to/Test.robot
我想将 VARIABLE_NAME1 和 VARIABLE_NAME2 等作为参数传递给 MyListener.py,而不是按如下方式编写它们:
robot --listener /path/to/MyListener.py;VARIABLE_VALUE1:VARIABLE_VALUE2 -d Results /path/to/Test.robot
这能做到吗?提前欣赏任何help/guidance
这是我的问题的答案:
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._variables
访问变量