【问题标题】:Robot framework: Is there a way to write dynamic test cases?机器人框架:有没有办法编写动态测试用例?
【发布时间】:2020-11-13 07:36:02
【问题描述】:

我对机器人框架很陌生。我想动态创建测试用例,而不需要输入键值驱动的方法。

找到了一些暗示以下内容的材料:

suite = TestSuite('Example suite', doc='...')
tc = TestCase('Example test')
tc.add_step(TestStep('Log', args=['Hello, world!'])
suite.add_test(tc)

测试用例类中没有看到add_step,继续四处看看有没有解决办法。

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    TestSuite 对象有一个keywords 属性,它本身有一个create 方法,可以用来创建新的关键字。

    robot framework api documentation 给出了这个example

    from robot.api import TestSuite
    
    suite = TestSuite('Activate Skynet')
    suite.resource.imports.library('OperatingSystem')
    test = suite.tests.create('Should Activate Skynet', tags=['smoke'])
    test.keywords.create('Set Environment Variable', args=['SKYNET', 'activated'], type='setup')
    test.keywords.create('Environment Variable Should Be Set', args=['SKYNET'])
    

    上面给你的测试和你写的一样:

    *** Settings ***
    Library    OperatingSystem
    
    *** Test Cases ***
    Should Activate Skynet
        [Tags]    smoke
        [Setup]    Set Environment Variable    SKYNET    activated
        Environment Variable Should Be Set    SKYNET
    

    【讨论】:

    • 这正是我想要的,感谢您将我指向文档。
    • 执行后如何获取log.html和report.html?
    猜你喜欢
    • 2017-05-07
    • 2014-05-16
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 2018-08-06
    • 2021-12-03
    • 1970-01-01
    • 2016-03-01
    相关资源
    最近更新 更多