机器人框架:有没有办法编写动态测试用例?

Shi*_*hwa 5 robotframework

我是机器人框架的新手.我想动态创建测试用例,而不需要输入键值驱动的方法.

找到了一些建议如下的材料:

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

我没有在测试用例类中看到add_step,将继续环顾四周,看看是否有任何解决方案.

Bry*_*ley 4

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

机器人框架 api 文档给出了这个例子

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'])
Run Code Online (Sandbox Code Playgroud)

上面为您提供了相同的测试,就好像您是这样编写的:

*** Settings ***
Library    OperatingSystem

*** Test Cases ***
Should Activate Skynet
    [Tags]    smoke
    [Setup]    Set Environment Variable    SKYNET    activated
    Environment Variable Should Be Set    SKYNET
Run Code Online (Sandbox Code Playgroud)