Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RobotFramework - get current Date

I need to test that the current date is displayed on my device, The date on the device is in format Monday, September 9, 2018 but when i try to test it i can only use the format Monday, 09, 2018 which would fail the test as there is no 0 in the Month date.

    page should contain element  ${DATE}
    ${DATE_MESSAGE}  get current date  result_format=%A, %d, %Y
    element should contain text  ${DATE}  ${DATE_MESSAGE}

How can change the format in robotframework to verify THis format Monday, September 9, 2018.

ERROR should have contained text 'Monday, 09, 2018' but its text was 'Monday, September 9, 2018'.


2 Answers

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

like image 95
an argie Avatar answered May 10 '26 05:05

an argie


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
like image 24
JaPyR Avatar answered May 10 '26 03:05

JaPyR