python - 测试设置和测试拆卸不会选取 __init__.txt 中定义的关键字

标签 python robotframework

我想尝试用户定义的关键字作为机器人框架测试套件和子测试套件中测试用例的设置和拆卸。我有以下结构,

    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 Keyword1My 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/

相关文章:

python - 向 Python 的 NoneType 添加方法

robotframework - 在一个机器人文件中混合关键字驱动测试和数据驱动测试

python - 使用 Robot 框架的 Selenium 网格实现

python - for c in string 有没有办法找到c的位置

python - 使用piprequirements.txt更新下游项目的依赖关系

python - 如果条目数小于一定数量,则每隔 15 秒删除所有条目

python - 如何限制xgboost执行时间?

python - 如果两个或多个测试失败,如何停止执行测试?

selenium - Chrome 74 : Deleting cookies takes very long time

selenium - 识别 xpath 以在 phptravels.net 站点中选择下拉列表