首页 > 解决方案 > 有没有办法用多个关键字动态构建机器人框架套件设置?

问题描述

我正在为单元测试构建机器人框架套件和动态测试。我们有一个Global Setup适用于套件级别的所有测试。但是,某些测试集具有额外的设置,也可以在套件级别应用。是否有任何内置方法可以将更多关键字附加到套件设置中?

我有这样的事情:

from robot.api import TestSuite

suite = TestSuite("Foo")
suite.setup.config(name="Global Setup")
# i want to then append to suite.setup based on some condition
if bar:
    # append more keywords to suite.setup
...
# add tests etc
...
result = suite.run(output="out.xml", loglevel="TRACE")

标签: pythonrobotframework

解决方案


我找不到通过侦听器方法向套件设置添加更多关键字的方法。以下是我能召集的最好的。也许这很明显,但似乎应该有更好的方法。

我更新suite.setup.config为运行Run Keywords并使用了ANDin ,args以便可以将多个关键字添加到套件设置中。

from robot.api import TestSuite

suite = TestSuite("Foo")
suite.setup.config(name="Global Setup")
# i want to then append to suite.setup based on some condition
if bar:
    # append more keywords to suite.setup
    suite.setup.config(name="Run Keywords", args=["Global Setup", "AND", "Other Setup"...])
...
# add tests etc
...
result = suite.run(output="out.xml", loglevel="TRACE")

推荐阅读