Robot Framework 如何在静态API中获取方法运行结果

0 投票
1 回答
1380 浏览
提问于 2025-04-18 01:28

以下是我在测试用例和测试套件(__init__.txt)文件中引用的resource.txt。我想在执行与一个静态API(RobotLibrary)相关的关键字后获取结果,然后将结果传回同一个静态API(RobotLibrary)模块,以便进行结果验证。我尝试在RobotLibrary中保存结果的状态,但这似乎不太奏效,可能是因为RobotLibrary在多个测试中是一个单例?我不介意通过关键字返回结果,并将其作为参数传递给后续调用。

*** Settings ***
Library     ${CURDIR}${/}..${/}src${/}RobotLibrary.py


*** Keywords ***

[return]  ${result_run}

when the configuration file "${filename}" is used to run the journey
        ${result_run}= start journey with config   ${filename}

when the route has a route code of "${routecode}"
        use route code  ${routecode}

journey status should be "${status}"
        assert journey status   ${status}

stop with name "${stopName}" should have an arrival time
        assert stop has arrival time    ${stopName}     ${result}

这没有成功,以下是我在控制台看到的信息。

(acceptance_test)[root@localhost jsf_acceptance_test]# pybot -L TRACE robot-tests/manual/Mandatory-Delayed-S0-Mandatory-Delayed-S1-329-1/
==============================================================================
Mandatory-Delayed-S0-Mandatory-Delayed-S1-329-1 :: Mandatory-Delayed-S0-Man...
==============================================================================
Mandatory-Delayed-S0-Mandatory-Delayed-S1-329-1.Mandatory-Delayed-S0-Mandat...
==============================================================================
Ensure feedback for stop stop0 on route CGXD                          | FAIL |
Parent suite setup failed:
No keyword with name '${result_run}= start journey with config' found.
------------------------------------------------------------------------------
Ensure feedback for stop stop1 on route CGXD                          | FAIL |
Parent suite setup failed:
No keyword with name '${result_run}= start journey with config' found.
------------------------------------------------------------------------------
Mandatory-Delayed-S0-Mandatory-Delayed-S1-329-1.Mandatory-Delayed-... | FAIL |
Parent suite setup failed:
No keyword with name '${result_run}= start journey with config' found.

2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
Mandatory-Delayed-S0-Mandatory-Delayed-S1-329-1 :: Mandatory-Delay... | FAIL |
Suite setup failed:
No keyword with name '${result_run}= start journey with config' found.

2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
Output:  /home/pycharm/jsf_acceptance_test/output.xml
Log:     /home/pycharm/jsf_acceptance_test/log.html
Report:  /home/pycharm/jsf_acceptance_test/report.html

我不太确定该如何处理这个问题——我对robot framework相对较新,发现很难在文档中找到答案。有没有人对此有想法?如果你需要更多信息,我很乐意更新问题。谢谢。

1 个回答

1

你的测试显示了这个错误:

No keyword with name '${result_run}= start journey with config' found.

这意味着机器人测试运行器在一个地方遇到了这个完整的字符串,而它本来应该期待一个关键词。很可能是因为在 =start journey... 之间只有一个空格。试着再加一个空格,这样变量和关键词就会在测试用例表的两个不同单元格里了。

${result_run}=  start journey with config
#             ^^ two spaces

如果你换成使用管道分隔的格式,这类问题会更容易发现。

撰写回答