gpt4 book ai didi

python - 如何列出没有测试用例的 .robot 文件中的所有关键字

转载 作者:行者123 更新时间:2023-12-01 15:48:32 24 4
gpt4 key购买 nike

问题陈述:我有一个 .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 模型而不是TestDataKeywordTable。其次,您必须调用 populate 方法使关键字可见。真正读取文件并导入关键字的是 populate 方法。

from robot.parsing.model import ResourceFile

rf = ResourceFile("Track2_Keywords.robot")
rf.populate()
for kw in rf.keywords:
print(kw.name)

关于python - 如何列出没有测试用例的 .robot 文件中的所有关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60487322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com