机器人框架:有没有办法写动态测试用例? [英] Robot framework: Is there a way to write dynamic test cases?
本文介绍了机器人框架:有没有办法写动态测试用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对机器人框架很陌生.我想在没有输入键值驱动方法的情况下动态创建测试用例.
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)
我在测试用例类中没有看到add_step,会继续环顾四周,看看有没有解决方案.
I dont see add_step in test case class, Will continue to look around and see if there are any solutions.
推荐答案
TestSuite
对象有一个 keywords
属性,它本身有一个 create
可用于创建新关键字的方法.
The TestSuite
object has a keywords
attribute which itself has a create
method which can be used to create new keywords.
机器人框架 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'])
上面给你的测试就像你这样写一样:
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
这篇关于机器人框架:有没有办法写动态测试用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文