Robotframework:在运行时使用特定格式的Get Current date获取日期



我使用Get Current Date关键字以年-月-日格式返回日期。我使用这个特定的信息来确保在自动化测试中帐户的创建的时间戳是正确的。

问题是关键字不被识别,我的代码应该是正确的(它应该工作它应该以我希望的格式产生日期。

*** Keywords ***
Initialize Test Data
    ${DATE}=    Get Current Date    result_format=timestamp
    ${MYNUM}=    faker.Random Int
    Set Suite Variable  ${MYNUM}
    Set Suite Variable  ${DATE}

为什么我得到错误No keyword with name 'Get Current Date' found.

关键字Get Current Date是否存在于标准射频库中?取而代之的是一个内置关键字获取时间。文档解释了如何格式化输出。要使用Get Current Date,首先需要导入DateTime库。

更新:RF脚本的例子,为我工作:

*** Settings ***
Library           DateTime
*** Test Cases ***
datatimetest
   ${d}=    get time
   log    {d}
   ${d}=    Get Current Date    result_format=%Y-%m-%d
   log    {d}
   ${d} =    Add Time To Date    2014-05-28 12:05:03.111    7 days
   log    {d}

请记住,DateTime是一个新的库,所以如果你有旧版本的Robot Framework,你需要安装库或升级RF。

我正在使用Python的RF,默认情况下我的IDE检测Python DateTime库。尝试使用完整路径:

Library           robot.libraries.DateTime

robot.libraries.DateTime .

您也可以根据自己的喜好设置时间格式。看看这个答案。它提供格式建议。您可以使用Python DateTime函数,如

所示
   ${now}    Evaluate    '{dt.day}/{dt.month}/{dt.year}'.format(dt=datetime.datetime.now())    modules=datetime
   Log   ${now}
   Log to Console   now time 1: ${now}
   ${now}    Evaluate  '{dt:%A}, {dt:%B} {dt.day}, {dt.year}'.format(dt=datetime.datetime.now())    modules=datetime
   Log   ${now}
   Log to Console   now time 2: ${now}

最新更新