问题陈述: 我有一个.robot文件,其中包含很多关键字。这是一个更高级别的robot文件,不包含任何测试用例。 我想列出所有的关键字名称
到目前为止我试过什么
from robot.parsing.model import TestData
suite = TestData(parent=None,source="Track2_Keywords.robot")
这是错误的
raise NoTestsFound('File has no tests or tasks.') robot.parsing.populators.NoTestsFound: File has no tests or tasks.
我也试过:
from robot.parsing.model import KeywordTable
suite = KeywordTable("Track2_Keywords.robot")
for item in suite:
... print (item.name)
但它是空的
首先,您需要使用
ResourceFile
模型,而不是TestData
或KeywordTable
。其次,必须调用populate
方法以使关键字可见。实际上是populate
方法读取文件并导入关键字我不明白你的目标是什么。如果文件不包含测试,则它是一个资源文件。在这种情况下,您可以添加一个虚拟测试用例,例如:
这样,您的代码就不应该抱怨缺少测试
如果您想在测试套件中查找未使用的关键字,可以在RIDE(https://github.com/robotframework/RIDE/)中使用该现有功能
相关问题 更多 >
编程相关推荐