Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robotframework: Getting date at runtime using Get Current Date, in specific format

I am using the Get Current Date keyword to return the date in the format year-month-day. I use this particular information to make sure that an account's created timestamp is correct in automated tests.

The issue is that the keyword is not recognised, my code should be correct (it should work and it should produce the date in the format I wish.

*** Keywords ***

Initialize Test Data
    ${DATE}=    Get Current Date    result_format=timestamp
    ${MYNUM}=    faker.Random Int

    Set Suite Variable  ${MYNUM}
    Set Suite Variable  ${DATE}

Why do I get the error No keyword with name 'Get Current Date' found.?

Thanks in advance.

like image 909
LeonH Avatar asked Feb 13 '23 10:02

LeonH


1 Answers

Does a keyword Get Current Date exist in standard RF lib? There is a builtin keyword called Get Time instead. Documentation explains how to format output. To use Get Current Date you need to import DateTime library first.

Update: RF script sample which works for me:

*** 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}

Please remember that DateTime is a new library so in case you have old version of Robot Framework, you need to either install library or upgrade RF.

like image 114
Marcin Kowalczyk Avatar answered Feb 18 '23 22:02

Marcin Kowalczyk