在XML重新启动解析期间设置链接

2024-09-30 22:09:55 发布

您现在位置:Python中文网/ 问答频道 /正文

情况是这样的:我有一个django后端来运行测试,创建XML文件,并将它们发送到django前端,django前端可以对它们执行任何操作(实际上生成HTML文件)

[后端]->;XML->[前端]->;HTML格式

我的问题是:在XML文件中,我有指向文档的外部链接,文档由我的前端托管,其URL只有后者知道

如何配置“.robot”文件以创建在处理XML文件期间由rebot更改的元素,以及需要为rebot提供哪些参数

编辑: 如评论中所问,下面是一个例子:

我的robot文件实际上包含如下测试:

Test_1
  [Documentation]Doc: [${PathToRefDoc}#test_1 | test_1_doc]
  <:Do Things:>

${PathToRefDoc}值在生成XML文件的过程中被替换,它给出如下内容:

<test id="1" name="Test_1"
    <doc>Doc: [<:ref doc URL:>#test_1 | test_1_doc]</doc>
    <:Infos on things done:>
</test>

我想要不带<;的XML文件:参考文档URL:>;值已经被设置,因为它的值在创建文件的过程中是未知的,但是作为“宏”应该在reboot处理XML文件的过程中给出


Tags: 文件django文档testgturldoc过程
1条回答
网友
1楼 · 发布于 2024-09-30 22:09:55

我终于在robotframework存储库的API文档中找到了一个解决方案:

Robotframework ouput documentation

我需要创建一个继承SuiteVisitor类的类,下面是代码

from robot.api import SuiteVisitor

class DocURLSetter(SuiteVisitor):
    """
    Changes every instances of ${PathToRefDoc} contained in the tests
    documentation with the URL given at instantiation
    """

    def __init__(self, doc_url):
        self.doc_url = doc_url

    def visit_test(self, test):
        test.doc = test.doc.replace("${PathToRefDoc}", self.doc_url)

在调用rebot框架的代码中,我必须添加'prerebotmodifier'参数:

robot.rebot(src, log=dst,
            report=None,
            loglevel='TRACE:WARN',
            exclude='TEST_SKIPPED',
            stdout=None,
            stderr=None,
            prerebotmodifier=DocURLSetter(my_doc_url))

相关问题 更多 >