[Python] How do I setup a global variable of epoch time and milliseconds to my test suite in...

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am actually working on setting up two API requests to start a DB data exchange job in my Robot Framework. The endpoint requires a variety of variables like ${startTime} in epoch format, ${timePeriod}, minutes in mills, or $cronExpression} to make the request workable.

    start_new_exchange_trade_data.robot:


    Resource ../../resources/Common.robot
    Resource ../../resources/Assertion.robot
    Resource ../000.place_diff_time_in_force_oco.robot

    Test Template Schedule New Nts Exchange Trade Data Job
    Default Tags TA


    *** Variables ***

    ${startTime} 1645029303212 #epoch time parameter
    ${timePeriod} 9000000 # minutes to seconds



    *** Test Cases ***
    Schedule New Nts Exchange Trade Data Job ${startTime} ${timePeriod}

    *** Keywords ***
    Schedule New Nts Exchange Trade Data Job
    [Arguments] ${startTime} ${timePeriod}
    When Start nts new jobs Exchange Trade Data with startime ${startTime} and time forward ${timePeriod} minutes


    start_exchange_trade_data_cron_job.robot:

    *** Settings ***

    Library DateTime

    Resource ../../resources/Common.robot
    Resource ../../resources/Assertion.robot

    Test Template Schedule Nts Exchange Trade Data Cron Job
    Default Tags TA

    *** Variables ***

    ${cronExpression} 0 */30 * * * ? -> cron expression
    ${startTimeFromNow} -1 -> subtract time from current time, depends unit set
    ${startTimeFromNowUnit} HOURS -> time unit
    ${truncatedValue} 0 -> ####
    ${truncatedUnit} HOURS -> time unit
    ${timePeriod} 900000 -> minutes to seconds

    *** Test Cases ***
    Schedule Nts Exchange Trade Data Cron Job ${cronExpression} ${startTimeFromNow} ${startTimeFromNowUnit} ${truncatedValue} ${truncatedUnit} ${timePeriod}

    *** Keywords ***
    Schedule Nts Exchange Trade Data Cron Job
    [Arguments] ${cronExpression} ${startTimeFromNow} ${startTimeFromNowUnit} ${truncatedValue} ${truncatedUnit} ${timePeriod}
    When Start nts exchange trade data in ${cronExpression} minutes with ${startTimeFromNow} hour delay set by ${startTimeFromNowUnit} unit with ${truncatedValue} and ${truncatedUnit} and timeperiod ${timePeriod}


    However, it would not be sustainable if each time I have to manually input the parameters above and run the test, as the parameters are not in readable language...

    In order to use the variable in my test suite, my idea is to create another Robot script to help set up global variables to include those parameters in a readable format instead of the default ones. However, I am quite new to the Robot Framework structure and not so sure how to configure it... Could anyone kindly advise?

    get_time_variables.robot:


    Library DateTime
    Library Selenium2Library
    Library BuiltIn

    *** Test Cases ***
    Get Date Convert To TimeStamp
    ${date_time} get current date UTC exclude_millis=true
    log to console \n${date_time}
    ${start_Time}= convert date ${date_time} epoch exclude_millis=true
    log to console \n${start_Time}
    set global variable ${start_Time}

    Continue reading...

Compartilhe esta Página