Robotframework 运行 x 分钟

Robotframework run for x amount of minutes

我正在尝试 运行 重复 x 分钟的测试。 我对关键字的看法:

*** Keywords ***

Run test looped
   FOR    ${i}    IN RANGE    9999
      Do something
      Exit For Loop If    ${ELAPSED} > ${MAX_DURATION}
   END

我正在尝试查找如何以分钟为单位计算经过的时间。 我找到了 robotframework 的 datetime 类型,但不知道如何计算分钟数。如何获得以分钟为单位的经过时间?

对于此类用例,使用纪元更容易 - 在循环之前获取它,并比较其中的当前值:

Run test looped
   ${start}=    Evaluate    time.time()    time
   FOR    ${i}    IN RANGE    9999
      Do something
      ${now}=    Evaluate    time.time()    time
      Exit For Loop If    (${now} - ${start})/60 > ${MAX_DURATION}    # divide the runtime seconds by 60, as ${MAX_DURATION} is in minutes
   END

内置库中有 Repeat Keyword - 它可以满足您的需求:

Repeat Keyword  2 minutes   Do Something    arg1    arg2

有关详细信息,请参阅:http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Repeat%20Keyword