我在目录中分隔了一些机器人测试用例。目录层次结构为:
ParentTestDirectory
|__ ChidTestDirectoryOne
|__ TestOne.robot
|__ ChidTestDirectoryTwo
|__ TestTwo.robot
|__ __init__.robot
__init__.robot
的内容:
*** Settings ***
Test Setup LOG TO CONSOLE Test setup from __init__.robot
Test Teardown LOG TO CONSOLE Test teardown from __init__.robot
TestOne.robot
的内容:
*** Settings ***
Test Setup LOG TO CONSOLE Test setup from TestOne.robot
Test Teardown LOG TO CONSOLE Test teardown from TestOne.robot
*** Test Cases ***
Test One
LOG TO CONSOLE This is Test One!
TestTwo.robot
的内容:
*** Settings ***
Test Setup LOG TO CONSOLE Test setup from TestTwo.robot
Test Teardown LOG TO CONSOLE Test teardown from TestTwo.robot
*** Test Cases ***
Test Two
LOG TO CONSOLE This is Test Two!
我有一个用python编写的跑步者,它使用机器人跑步者模块;这是使用命令sudo python run.py --testsuit scenarios.ParentTestDirectory
:
==============================================================================
Scenarios
==============================================================================
Scenarios.ParentTestDirectory
==============================================================================
Scenarios.ParentTestDirectory.ChidTestDirectoryOne
==============================================================================
Scenarios.ParentTestDirectory.ChidTestDirectoryOne.TestOne
==============================================================================
Test One Test setup from TestOne.robot
.This is Test One!
.Test teardown from TestOne.robot
Test One | PASS |
------------------------------------------------------------------------------
Scenarios.ParentTestDirectory.ChidTestDirectoryOne.TestOne | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Scenarios.ParentTestDirectory.ChidTestDirectoryOne | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo
==============================================================================
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo.TestTwo
==============================================================================
Test Two Test setup from TestTwo.robot
.This is Test Two!
.Test teardown from TestTwo.robot
Test Two | PASS |
------------------------------------------------------------------------------
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo.TestTwo | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Scenarios.ParentTestDirectory.ChidTestDirectoryTwo | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Scenarios.ParentTestDirectory | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
Scenarios | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
如您所见,它只运行最新的测试设置/拆卸。我希望它也可以从父目录运行测试设置/拆卸,它应该在孩子之前执行。换句话说,我希望在它自己的设置之前分别为每个测试用例运行父设置。我能用机器人框架功能实现这一目标吗?
答案 0 :(得分:3)
测试用例只能进行一次设置。将Test Setup
放入整个套件的设置时,会定义默认测试设置。如果子套件或单个测试定义了测试设置,则它将运行而不是更高级别定义的套件级别设置。
在机器人框架用户指南中标题为Initialization files的部分中,它说明了这一点(我强调了这一点):
测试设置,测试拆解,测试超时
将测试设置/拆卸或测试超时的默认值设置为此目录包含的所有测试用例。 可以在较低级别覆盖。在Robot Framework 2.7中添加了对初始化文件中定义测试超时的支持。
如果您希望套件定义除了每个测试指定的设置之外运行的测试设置,您应该将该代码放入自定义关键字中,并让每个测试调用该关键字作为其设置的一部分。