RobotFramework - get current Date

旧巷老猫 提交于 2019-12-06 12:47:13

Something like that should work:

${now}    Evaluate    '{dt.day}/{dt.month}/{dt.year}'.format(dt=datetime.datetime.now())    modules=datetime

After update:

${now}    Evaluate  '{dt:%A}, {dt:%B} {dt.day}, {dt.year}'.format(dt=datetime.datetime.now())    modules=datetime

This can be done much more easy

${date}=      Get Current Date      UTC      exclude_millis=yes
${convert}=      Convert Date      ${date}      result_format=%a %B %d %H:%M:%S UTC %Y
Log      ${convert}      console=yes

(%a = f.e. Mon
%A = f.e. Monday
%B = f.e. May
%H:%M:%S - f.e. 13:04:09
UTC = f.e. part of string needed
%Y = 2019)

The output on the console of the string above will give:

Fri May 10 10:12:31 UTC 2019

If you want to add certain amount of days use:

${date}=      Get Current Date      UTC      exclude_millis=yes
${plus14}=      Add Time To Date      ${date}      14 days
${future}      Convert Date      ${plus14}      result_format=%a %B %d %H:%M:%S UTC %Y
Log      ${future}      console=yes

The output will be:

Fri May 24 10:12:31 UTC 2019

Robot Framework has an extensive DateTime library built-in (since version 2.8.5).

If you are able to import that library, documented here ( http://robotframework.org/robotframework/latest/libraries/DateTime.html ). You should be able to use the Get Current Date keyword.

This keyword has a parameter that allows you to use Python's date formation format to get the date/time format you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!