简体   繁体   English

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

[英]How do I setup a global variable of epoch time and milliseconds to my test suite in robot framework?

I am actually working on setting up two API request to start DB data exchange job in my robot framework.我实际上正在设置两个 API 请求以在我的机器人框架中启动数据库数据交换作业。 The endpoint requires variety of variable like ${startTime} in epoch format, ${timePeriod}, minutes in mills or $cronExpression} to make the request workable.端点需要各种变量,如纪元格式的 ${startTime}、${timePeriod}、米尔斯分钟或 $cronExpression} 以使请求可行。

start_new_exchange_trade_data.robot 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 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...但是,如果每次我都必须手动输入上面的参数并运行测试,但参数不是可读的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 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}

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.您应该在 Keyword 下定义Set Start Time (或者Set Start Time更清楚),并将其设置为测试套件设置或测试用例设置。 And note that Get Current Date can be in epoch format并注意Get Current Date可以是纪元格式

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}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以将定义的机器人关键字放在 Robot Framework 的 Suite SetUp/Test Setup 下吗 - Can I put defined robot keywords under Suite SetUp/ Test Setup in Robot Framework 如何在机器人框架的套件设置中“运行关键字 if tag="debug"” - How to "run a keyword if tag="debug"" in suite setup in robot framework 如何并行运行机器人框架测试用例而不是并行运行测试套件? - How to run robot framework test cases parallel and not Test Suite parallel? 使用 python 对 Robot Framework 中的测试套件中的每个测试用例进行测试设置和拆卸 - Test Setup and Teardown for each test case in a test suite in Robot Framework using python 有什么方法可以减少 Robot Framework 中的套件设置/拆卸和测试设置/拆卸样板? - Any way to reduce suite setup/teardown and test setup/teardown boilerplate in Robot Framework? Robot Framework Test Suite目录如何精确工作? - How are Robot Framework Test Suite Directories working precisely? Robot Framework:如何在不同路径中维护(子)测试套件目录 - Robot Framework : How to maintain (sub) test suite directories in different paths 如何在机器人框架中声明全局变量并在另一个机器人文件中使用它 - How to I declare Global Variable in Robot Framework and use it in another robot file 如何为单元测试套件进行一次设置 - How to do one setUp for a unit test suite 如何使用 Robot Framework 测试 python function? - How do I test a python function using Robot Framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM