首页 > 解决方案 > 如何在机器人框架中实现自定义部分

问题描述

我们在 Robot Framework 中有如下部分:

***Settings***
***Variables***
***Test Cases***
***Keywords***

并且在运行文件机器人框架引擎时尝试找到TestCases并执行它。同样,是否可以创建一个自定义部分,比如General并且在运行类时执行定义的关键字/方法?

标签: robotframework

解决方案


It is not possible to add sections to a robot file. However, what you describe can be achieved using Robot Framework by filtering the test cased from the command line using Test Case Tags.

Given the following example:

*** Test Cases ***
Test Case General 1
    [Tags]    General
    No Operation

Test Case General 2
    [Tags]    General
    No Operation

Test Case Feature 1
    [Tags]    Feature 1
    No Operation

Test Case Feature 2
    [Tags]    Feature 2
    No Operation

Starting Robot framework with the argument:

--include General

Will result in

Test Case General 1                                                   | PASS |
------------------------------------------------------------------------------
Test Case General 2                                                   | PASS |
------------------------------------------------------------------------------

and

--include General  --include Feature 2

Will result in

Test Case General 1                                                   | PASS |
------------------------------------------------------------------------------
Test Case General 2                                                   | PASS |
------------------------------------------------------------------------------
Test Case Feature 2                                                   | PASS |
------------------------------------------------------------------------------

推荐阅读