Robot framework: Is there a way to write dynamic test cases?

*爱你&永不变心* 提交于 2021-02-07 14:47:53

问题


I am pretty new to robot framework. I would like to create test cases dynamically without having a input key-value driven approach.

Found some material that suggested the following:

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

I dont see add_step in test case class, Will continue to look around and see if there are any solutions.


回答1:


The TestSuite object has a keywords attribute which itself has a create method which can be used to create new keywords.

The robot framework api documentation gives this 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'])

The above gives you the same test as if you had written it like this:

*** Settings ***
Library    OperatingSystem

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


来源:https://stackoverflow.com/questions/44876885/robot-framework-is-there-a-way-to-write-dynamic-test-cases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!