python - 对嵌套文件夹结构机器人框架中的多个测试套件使用通用套件设置和套件拆解
问题描述
我是Robot框架的新手,当测试的文件夹结构不是“扁平”时,我试图更好地理解Suite Setup和Suite Teardown中的概念和用法。在网上搜索了很久之后,Robot 框架用户指南 - 执行测试部分,还有这个与我的情况类似但不完全一样的问题,我仍然没有找到任何解决方案,所以我们开始吧。
我的项目现在包含以下文件:
_init__.robot
其中包含Suite Setup
& Suite Teardown
“定义”,如下:
*** Settings ***
Library /path/to/some/python/file.py
Suite Setup myCustomSuiteSetup
Suite Teardown myCustomSuiteTeardown
*** Keywords ***
myCustomSuiteSetup
${ret_code} = run keyword MySuiteSetupKeyword
should be eqaul as integers ${ret_code} 0
myCustomSuiteTeardown
${ret_code} = run keyword MySuiteTeardownKeyword
should be eqaul as integers ${ret_code} 0
wheremyCustomSuiteTeardown
和MySuiteTeardownKeyword
are 关键字“链接”到文件中的某些 Python 函数/path/to/some/python/file.py
。
我项目中的 4 个套件文件目前排列如下:
|--tests
|----suite_1.robot
|----suite_2.robot
|----suite_3.robot
|----suite_4.robot
|----__init__.robot
Suite Setup
现在, &的目的(和用法)Suite Teardown
是,将在整个文件夹Suite Setup
的运行开始时运行,即,在第一个套件的第一个测试用例之前,在这种情况下是,并且将在最后一个套件的最后一个测试用例,在这种情况下是.tests
suite_1.robot
Suite Teardown
suite_4.robot
为此,我只需按如下方式调用所有套件(从文件夹“上方”的一个文件tests
夹中):
robot tests
到目前为止,一切都很好。
现在我的问题如下:实际上我希望“重新排列”测试文件的文件夹结构,如下所示:
|--tests
|----testGroup1
|--------suite_1.robot
|--------suite_2.robot
|----testGroup2
|--------suite_3.robot
|--------suite_4.robot
|--__init__.robot <----- Where the __init__.robot file should be placed now ?
意思是,将测试套件“收集”到子文件夹,但是,我仍然希望像以前一样保持Suite Setup
&的使用Suite Teardown
,即在调用“根”文件夹下的每个可能的测试套件子集时tests
,Suite Setup
&Suite Teardown
必须是要执行的第一个和最后一个(分别)“步骤”,例如,假设我希望运行suite_3.robot
& suite_4.robot
,那么现在,Suite Setup
应该在第一个测试用例之前调用,suite_3.robot
并且Suite Teardown
应该在最后一个测试用例之后调用suite_4.robot
. 另外,当然,我希望只保留文件的一个副本__init__.robot
- 即 - 不要__init__.robot
在每个子文件夹中保留两个相似的副本,testGroup1
&testGroup2
. 当我这样做时,它起作用了,但这不是我希望这样做的(正确)方式。
所以我的问题是:
我需要将
__init__.robot
文件放在哪里?例如,如果我希望只运行
testGroup2
(ie-suite_3.robot
&suite_4.robot
) 中的两个测试套件,我需要使用什么命令?
当然,如果这不是实现我的目标的“正确”方式(方法)(单个和统一Suite Setup
以及Suite Teardown
每个测试套件子集) - 请建议应该如何完成。
注意:我使用的是 Robot framework 3.1.2(Linux 上的 Python 3.5.2)
解决方案
tests
您在包含两者的文件夹中testGroup1
放置的初始化文件testGroup2
是正确的。tests
这样,如果您在其子文件夹中的某个位置或内部运行至少一个测试,则套件安装程序将在所有此类测试之前运行,然后在套件拆解之后运行。
要强制运行 Suite Setup 和 Suite Teardown,您必须将父文件夹 ( tests
) 作为您运行的文件夹。最好始终运行包含所有测试的文件夹。这样,您就不会错误地错过任何套件设置或拆解。
然后只运行选择测试,使用选项--include
或--exclude
标记,--suite
或--test
。
在您的示例中,您将运行以下命令:
robot --suite suite_3 --suite suite_4 tests
, 仅运行 suite_3 和 suite_4
或者,您可以使用完全限定的套件名称:
robot --suite tests.testGroup2.suite_3 --suite tests.testGroup2.suite_4 tests
推荐阅读
- r - Dplyr 使用字符串变量作为表达式重命名
- java - 从外部 jpanel 类中移动 JFrame
- python - 将保存在 np.array 中的十六进制图像转换为在 opencv 中导入
- javascript - 在我的 chrome 扩展中从内容发送数据以响应应用程序
- go - 将结构字段编组为没有字段名称的 JSON
- neo4j - 在 Neo4j 中以字符串开头的列表中搜索
- oauth-2.0 - OAuth2 和 OpenID API 到 API 的通信
- django - 事件列表上的 Django 查询:查找最近的事件
- excel - 使用 sum if 根据出击类型计算总飞行小时数
- c++ - C++ 模板只接受具有特定成员的类型名