目前我得到的时间与关键字Get time epoch
,这是在几秒钟内返回时间。但我需要以毫秒为单位的时间,所以我可以得到的时间跨度为一个特定的事件。
或是否有任何其他方式获得的时间跨度为特定事件或testsceanrio?
检查新的测试库DateTime
,其中包含关键字Get Current Date
,这也将返回毫秒。它也有关键字Subtract Dates
两个时间戳之间计算差异。
其中一个机器人的更强大的功能是,你可以使用评估关键字直接调用从一个测试脚本Python代码。例如,你可以调用time.time()功能,并做一些数学:
*** Test cases
| Example getting the time in milliseconds
| | ${ms}= | Evaluate | int(round(time.time() * 1000)) | time
| | log | time in ms: ${ms}
请注意,即使time.time
返回一个浮点值,并不是所有的系统将返回一秒钟更精确的数值。
在报告中,每间套房,测试和关键字,您有起点,终点和长度以毫秒的细节信息。就像是:
Start / End / Elapsed: 20140602 10:57:15.948 / 20140602 10:57:16.985 / 00:00:01.037
我不明白的方式使用Builtin
做到这一点,请看:
def get_time(format='timestamp', time_=None):
"""Return the given or current time in requested format.
If time is not given, current time is used. How time is returned is
is deternined based on the given 'format' string as follows. Note that all
checks are case insensitive.
- If 'format' contains word 'epoch' the time is returned in seconds after
the unix epoch.
- If 'format' contains any of the words 'year', 'month', 'day', 'hour',
'min' or 'sec' only selected parts are returned. The order of the returned
parts is always the one in previous sentence and order of words in
'format' is not significant. Parts are returned as zero padded strings
(e.g. May -> '05').
- Otherwise (and by default) the time is returned as a timestamp string in
format '2006-02-24 15:08:31'
"""
time_ = int(time_ or time.time())
format = format.lower()
# 1) Return time in seconds since epoc
if 'epoch' in format:
return time_
timetuple = time.localtime(time_)
parts = []
for i, match in enumerate('year month day hour min sec'.split()):
if match in format:
parts.append('%.2d' % timetuple[i])
# 2) Return time as timestamp
if not parts:
return format_time(timetuple, daysep='-')
# Return requested parts of the time
elif len(parts) == 1:
return parts[0]
else:
return parts
你必须写自己的模块,你需要的东西,如:
import time
def get_time_in_millies():
time_millies = lambda: int(round(time.time() * 1000))
return time_millies
然后,在平顺导入该库套件,你可以使用的方法名称,比如关键字,在我的情况下,将Get Time In Millies
。更多信息here。
使用DateTime library
,通过janne的建议:
*** Settings ***
Library DateTime
*** Test Cases ***
Performance Test
${timeAvgMs} = Test wall clock time 100 MyKeywordToPerformanceTest and optional arguments
Should be true ${timeAvgMs} < 50
*** Keywords ***
MyKeywordToPerformanceTest
# Do something here
Test wall clock time
[Arguments] ${iterations} @{commandAndArgs}
${timeBefore} = Get Current Date
:FOR ${it} IN RANGE ${iterations}
\ @{commandAndArgs}
${timeAfter} = Get Current Date
${timeTotalMs} = Subtract Date From Date ${timeAfter} ${timeBefore} result_format=number
${timeAvgMs} = Evaluate int(${timeTotalMs} / ${iterations} * 1000)
Return from keyword ${timeAvgMs}