Robot Framework:根据 robot.properties 文件填充参数?
Robot Framework: Populating parameters based off of a robot.properties file?
我正在尝试模拟一个 'robot.properties' 文件,以便在我的测试用例中使用 Robot Framework。在我的 robot.properties 文件中,它包含例如以下内容:
project.username=Whosebug
在我的测试用例文件中,我多次尝试通过在设置中添加 'import' robot.properties 文件:资源 ../path/to/properties 等(请参阅下面的目录结构),但是当我尝试将 'project.username' 作为参数传递给测试时,它会将其作为文字字符串值 'project.username' 而不是值 'stack overflow' 传递。我是 Robot 的新手,我已经用 Java/C# 等其他语言实现了它,但我完全认为导入阻止我访问我的值。任何帮助将不胜感激,不幸的是,我在网上找到的这种驾驶测试方式并没有真正被引用。
目录结构:
Tests/Acceptance/MyTestCase.机器人
Tests/robot.属性
如果我尝试 Library ../robot.properties 我得到:
"Import by filename is not supported"
如果我尝试 Resource ../robot.properties 我得到:
"Unsupported file format .properties"
机器人框架不支持“.properties”文件。
一种解决方案是使用 variable file, which lets you define variables in python. Since you want to use dot notation, one way is to create a class and define your variables as properties of the class. The variable file can then make an instance of that class as a variable, and you can use extended variable syntax 来访问变量。
与纯文本文件相比,使用变量文件的优势在于您可以通过调用其他 python 函数来动态创建变量。作为一个简单的示例,您可以创建一个名为 "now" 的变量,其中包含当前日期,或者 "host" 这是机器的主机名 运行 测试。
示例:
properties.py
import platform
class Properties(object):
username = "Whosebug"
password = "SuperSecret!"
hostname = platform.uname()[1]
properties = Properties()
example.robot
*** Settings ***
Variables properties.py
Suite Setup log running on ${properties.hostname}
*** Test Cases ***
Example
should be equal ${properties.username} Whosebug
我正在尝试模拟一个 'robot.properties' 文件,以便在我的测试用例中使用 Robot Framework。在我的 robot.properties 文件中,它包含例如以下内容:
project.username=Whosebug
在我的测试用例文件中,我多次尝试通过在设置中添加 'import' robot.properties 文件:资源 ../path/to/properties 等(请参阅下面的目录结构),但是当我尝试将 'project.username' 作为参数传递给测试时,它会将其作为文字字符串值 'project.username' 而不是值 'stack overflow' 传递。我是 Robot 的新手,我已经用 Java/C# 等其他语言实现了它,但我完全认为导入阻止我访问我的值。任何帮助将不胜感激,不幸的是,我在网上找到的这种驾驶测试方式并没有真正被引用。
目录结构:
Tests/Acceptance/MyTestCase.机器人
Tests/robot.属性
如果我尝试 Library ../robot.properties 我得到: "Import by filename is not supported" 如果我尝试 Resource ../robot.properties 我得到: "Unsupported file format .properties"
机器人框架不支持“.properties”文件。
一种解决方案是使用 variable file, which lets you define variables in python. Since you want to use dot notation, one way is to create a class and define your variables as properties of the class. The variable file can then make an instance of that class as a variable, and you can use extended variable syntax 来访问变量。
与纯文本文件相比,使用变量文件的优势在于您可以通过调用其他 python 函数来动态创建变量。作为一个简单的示例,您可以创建一个名为 "now" 的变量,其中包含当前日期,或者 "host" 这是机器的主机名 运行 测试。
示例:
properties.py
import platform
class Properties(object):
username = "Whosebug"
password = "SuperSecret!"
hostname = platform.uname()[1]
properties = Properties()
example.robot
*** Settings ***
Variables properties.py
Suite Setup log running on ${properties.hostname}
*** Test Cases ***
Example
should be equal ${properties.username} Whosebug