Robotframework动态添加测试用例以及解析xml报告获取失败用例

本文介绍了如何在Robotframework中动态注册测试用例,并详细讲解了通过Python解析XML报告以获取失败测试用例的步骤。
摘要由CSDN通过智能技术生成

动态添加RF case:

from __future__ import print_function

# from .version import VERSION

# __version__ = VERSION


class DynamicTestCase(object):
    ROBOT_LISTENER_API_VERSION = 3
    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
    # ROBOT_LIBRARY_VERSION = __version__

    def __init__(self):
        self.ROBOT_LIBRARY_LISTENER = self
        self.current_suite = None

    def _start_suite(self, suite, result):
        # save current suite so that we can modify it later
        self.current_suite = suite

    def add_test_case(self, name, kwname, *args):
        """Adds a test case to the current suite

        'name' is the test case name
        'kwname' is the keyword to call
        '*args' are the arguments to pass to the keyword

        Example:
            add_test_case  Example Test Case
            ...  log  hello, world  WARN
        """
        tc = self.cu
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Robot Framework中,测试用例是通过关键字驱动的方式编写的。每个测试用例都由一系列关键字和参数组成,以描述测试的步骤和预期结果。以下是编写Robot Framework测试用例的方法: 1. 创建测试用例文件:使用文本编辑器创建一个新的文件,并将其保存为`.robot`扩展名。 2. 定义测试用例:在测试用例文件中,使用`*** Test Cases ***`标记定义测试用例的部分。在该部分下,每一行代表一个测试用例。 3. 编写关键字:在测试用例中,使用关键字来描述测试步骤和预期结果。关键字可以是内置关键字、自定义关键字或导入的库中的关键字。 4. 添加参数:在关键字后面,使用空格分隔的方式添加参数。参数可以是固定值、变量或表达式。 5. 添加注释:使用`#`符号添加注释,以提供更多的说明和上下文。 以下是一个示例的Robot Framework测试用例: ```robotframework *** Test Cases *** Example Test Case [Documentation] This is an example test case Open Browser https://www.example.com chrome Input Text id=search-input example Click Button css=.search-button Page Should Contain Example Search Results ``` 在上面的示例中,`Example Test Case`是测试用例的名称。`Open Browser`、`Input Text`、`Click Button`和`Page Should Contain`是关键字,它们描述了测试的步骤。`https://www.example.com`、`chrome`、`id=search-input`、`example`和`css=.search-button`是参数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值