如何在机器人框架中的测试套件中设置纪元时间和毫秒的全局变量?

发布于 2025-01-09 18:44:26 字数 2783 浏览 1 评论 0原文

我实际上正在努力设置两个 API 请求以在我的机器人框架中启动数据库数据交换作业。 端点需要各种变量,例如纪元格式的 ${startTime}、${timePeriod}、以毫秒为单位的分钟或 $cronExpression} 以使请求可行。

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}

但是,如果每次我都必须手动输入上面的参数并运行测试,但这些参数不在可读的实验室中,那么这是不可持续的...

为了在我的测试套件中使用该变量,我的想法是创建另一个机器人脚本来帮助和设置全局变量,以可读格式包含这些参数,而不是默认参数。但我对机器人框架结构很陌生,不太确定如何配置它......有人可以建议吗?

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}

I am actually working on setting up two API request to start DB data exchange job in my robot framework.
The endpoint requires variety of variable 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, yet the parameters are not in readable labguage...

In order to use the variable in my test suite, my ideas is to create another robot script to help and set up global variables to include those parameters in a readable format instead the default ones . But 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}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

古镇旧梦 2025-01-16 18:44:26

您应该在关键字下定义设置开始时间(或者可能是设置开始时间以明确),并将其设置为测试套件设置或测试用例设置。请注意,获取当前日期可以采用纪元格式

示例:

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
Suite Setup     Set Start Time


*** Variables ***
${timePeriod}            9000000 # minutes to seconds 



*** Test Cases ***
Schedule New Nts Exchange Trade Data Job    ${START_TIME}  ${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 

Set Start Time
    ${date_time}  get current date   time_zone=UTC   result_format=epoch   exclude_millis=true
    log to console      \n${date_time}
    set global variable  ${START_TIME}  ${date_time}

You should define Set Start Time (or perhaps Set Start Time to be clear) under Keyword and set it as a Test suite setup or test case setup. And note that Get Current Date can be in epoch format

Example:

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
Suite Setup     Set Start Time


*** Variables ***
${timePeriod}            9000000 # minutes to seconds 



*** Test Cases ***
Schedule New Nts Exchange Trade Data Job    ${START_TIME}  ${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 

Set Start Time
    ${date_time}  get current date   time_zone=UTC   result_format=epoch   exclude_millis=true
    log to console      \n${date_time}
    set global variable  ${START_TIME}  ${date_time}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文