我想尝试用户定义的关键字作为机器人框架测试套件和子测试套件中测试用例的设置和拆卸。我有以下结构,
ROOT | |- tests |- __init__.txt |- sample.robot
__init__.txt
包含以下文本
*** Settings *** Test Setup My Keyword1 Test Teardown My Keyword2 *** Keywords *** My Keyword1 Log Inside My Keyword1 My Keyword2 Log Inside My Keyword2
Sample.robot 包含以下代码,
*** Test Cases *** My Testcase1 Log Inside My Testcase1
运行机器人测试
给出以下错误,
============================================================================== Tests ============================================================================== Tests.Sample ============================================================================== My Testcase1 | FAIL | Setup failed: No keyword with name 'My Keyword1' found. Also teardown failed: No keyword with name 'My Keyword2' found. ------------------------------------------------------------------------------ Tests.Sample | FAIL | 1 critical test, 0 passed, 1 failed 1 test total, 0 passed, 1 failed ============================================================================== Tests | FAIL | 1 critical test, 0 passed, 1 failed 1 test total, 0 passed, 1 failed ==============================================================================
你能告诉我上面的结构中缺少什么吗?我需要一种机制,允许我执行用户关键字作为默认设置或拆卸。此外,如果需要,单个测试用例可以覆盖设置/拆卸。
最佳答案
问题是 My Keyword1
和 My Keyword2
是 __init__.txt
文件的本地文件,不能在其他测试用例中使用。您需要将它们移至资源文件中,并将该文件导入到您的测试中。
摘自 initialization files 上的机器人框架用户指南部分:
Variables and keywords created or imported in initialization files are not available in the lower level test suites. If you need to share variables or keywords, you can put them into resource files that can be imported both by initialization and test case files.
关于python - 测试设置和测试拆卸不会选取 __init__.txt 中定义的关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49754614/