Robotframework 如何计算应用程序在测试执行期间的总等待时间?
我已经为等待功能创建了通用关键字,如下所示Robotframework 如何计算应用程序在测试执行期间的总等待时间?,robotframework,Robotframework,我已经为等待功能创建了通用关键字,如下所示 Wait_Function [Arguments] ${Element} Wait Until Keyword Succeeds 120s 2s Element Should Be Visible ${Element} Wait_Function_For_Text [Arguments] ${Element} ${Text} Wait Until Keyword Suc
Wait_Function
[Arguments] ${Element}
Wait Until Keyword Succeeds 120s 2s Element Should Be Visible ${Element}
Wait_Function_For_Text
[Arguments] ${Element} ${Text}
Wait Until Keyword Succeeds 120s 2s Element Should Contain ${Element} ${Text}
我在应用程序需要时间加载元素的地方调用了“Wait_Function”/“Wait_Function_For_Text”,如下所示:
Function A
Click Element ${Add}
Wait_Function ${Save}
Click Element ${Save}
Wait_Function ${Home_Icon}
Function B
Scroll Element Into View ${Add}
Wait_Function ${Add}
Click Element ${Add}
Wait_Function_For_Text id=SuccessMsg User added successfully
类似地,许多测试用例(函数C、函数D等)中都使用了这个常见的等待关键字
现在,我想计算每个测试用例的等待时间,以及验证性能的总累计等待时间
我需要像这样的输出
Wait time for Function A: 00:00:01:750 (1 sec 750 ms)
Wait time for Function B: 00:00:00:350 (350 ms)
Overall Cumulative Wait time: 00:00:02:100 (2 sec 100 ms)
任何输入/建议都会很有帮助。当您运行robot套件时,它会生成一个XML文件。每个关键字(包括函数A和函数B)都作为一个XML元素存在。例如:
<kw library="BuiltIn" name="Get Time">
<doc>Returns the given time in the requested format.</doc>
<arguments>
<arg>year month day</arg>
</arguments>
<assign>
<var>${year}</var>
<var>${month}</var>
<var>${day}</var>
</assign>
<msg level="INFO" timestamp="20180315 17:22:00.692">${year} = 2018</msg>
<msg level="INFO" timestamp="20180315 17:22:00.692">${month} = 03</msg>
<msg level="INFO" timestamp="20180315 17:22:00.693">${day} = 15</msg>
<status endtime="20180315 17:22:00.693" starttime="20180315 17:22:00.690" status="PASS"></status>
</kw>
以请求的格式返回给定的时间。
年月日
${year}
${month}
${day}
${year}=2018年
${month}=03
${day}=15
注意最后一个子项,状态
。它有两个时间戳:starttime
和endtime
要获得函数所花费的累计时间,您可以编写一个脚本或程序来处理此XML文件,计算关键字函数a和函数B的每个实例的
endtime
和starttime
之间的差异,并计算这些差异的总和。非常好的观察Petr!!!使用机器人框架已经有一段时间了,但真的错过了!