【发布时间】:2020-01-27 05:35:10
【问题描述】:
我是 Robot 框架的新手,并试图在测试文件夹时更好地理解 Suite Setup 和 Suite Teardown 中的概念和用法结构不是“扁平的”。在网上搜索了很长时间,Robot framework user guide - executing tests section 和 this question 与我的情况相似但不完全一样,我仍然没有找到任何解决方案,所以我们开始吧。
我的项目现在包含以下文件:
_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
其中myCustomSuiteTeardown 和MySuiteTeardownKeyword 是“链接”到文件/path/to/some/python/file.py 中的某些Python 函数的关键字。
我项目中的 4 个套件文件当前排列如下:
|--tests
|----suite_1.robot
|----suite_2.robot
|----suite_3.robot
|----suite_4.robot
|----__init__.robot
现在,Suite Setup 和Suite Teardown 的用途(和用法)是Suite Setup 将在整个tests 文件夹的运行开始时运行,即- 之前 first 套件的 first 测试用例,在本例中为 suite_1.robot 和 Suite Teardown 将在 之后运行 last 套件的strong>last 测试用例,在本例中为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_3.robot 中的第一个测试用例之前调用Suite Setup,并且应该在suite_4.robot 中的最后一个测试用例之后调用Suite Teardown。另外,当然,我希望只保留__init__.robot 文件的单个 副本-即-不要在每个子文件夹testGroup1 和testGroup2 中保留__init__.robot 的两个相似副本.当我这样做时,它起作用了,但这不是我希望这样做的(正确)方式。
所以我的问题是:
我需要将
__init__.robot文件放在哪里?-
如果我希望只运行
testGroup2中的两个测试套件(即-suite_3.robot和suite_4.robot),我需要使用什么命令?
当然,如果这不是实现我的目标的“正确”方式(方法)(每个测试套件子集的单一和统一的 Suite Setup 和 Suite Teardown) - 请建议应该如何完成。
注意:我使用的是 Robot framework 3.1.2(Linux 上的 Python 3.5.2)
【问题讨论】:
标签: python python-3.x automation automated-tests robotframework