机器人框架 - Post 运行 钩子发送消息

Robot framework - Post run hook to send message

我运行像这样在一个pybot命令中使用多个测试套件,

pybot suite1.robot suite2.robot suite3.robot

现在,这些机器人套件中的每一个都将一个键值添加到一个全局字典中(这个测试变量包含一些需要返回给测试调用者的指标)作为,

{ "suite1-res" : xxxx,
"suite2-res" : yyyy,
"suite3-res" : zzzz }

现在,需要将此字典posted 到kafka/any 消息代理。我喜欢将此功能编写在一个 post-运行 钩子 function/robot 案例中,在所有机器人案例结束时仅 运行 一次。

能否将此 post-运行 挂钩功能添加为 运行 时间参数(如 suite teardown),而不是将其作为额外的机器人测试用例参数传递.

使用套件文件

如果您将所有这些套件放在一个文件夹中,您可以在文件夹中附加一个套件拆解,该文件夹将在所有 child 个套件完成后 运行。

$ mkdir all_tests
$ mv suite*.robot all_tests
$ # edit all_tests/__init__.robot to have a suite teardown
$ pybot all_tests

使用侦听器

您可以使用侦听器,它可以收集数据和 运行 post 处理步骤。例如,您的测试可以将指标附加为套件元数据,当为每个套件调用 end_suite 时,侦听器将获得该元数据。侦听器可以存储所有这些元数据,然后在 close 被调用时对其进行处理。有关详细信息,请参阅内置库中的 Using the listener interface in the robot framework users guide, and the documentation for Set Suite Metadata 关键字。

编写自定义脚本

有关详细信息,请参阅机器人框架用户指南中标题为 Test Suite Directories 的部分。为此,您的测试必须将字典写入文件。

您的另一种选择是编写一个简单的 bash 或批处理脚本 运行 pybot 命令,然后执行您想要的任何 post 处理。您的测试需要以某种方式使字典数据可用。例如,您可以将数据存储为 suite metadata,然后让 post-processing 步骤将该数据从 output.xml 中拉出。或者,您的套件可以将数据写入文件。