简体   繁体   中英

How to implement polling in Robot Framework

I am new to Robot Framework. I have a test case which performs below steps 1. Connects to the DB 2. Submits a job to a server 3. Once the Job is completed a status is updated in the Job table Job Completed 4. Once the Job table is updated to status Job Completed want to check the other values in other tables in the DB

Right now i have introduced sleep after step 2 which i want to avoid. Sometimes the job might take 5 minutes to complete and sometimes 2 minutes. How can i go ahead and add the polling in this case. I do not want to hard code sleep in this case.

Below is my piece of code

*** Settings ***

Suite Setup          Connect To DB
Suite Teardown       Disconnect From DB

*** Test Cases ***
TC1
    [Tags]  Debug
    log to console  Test1
    Submit The Job
    sleep  5 minutes
    ${queryResults}=  DB.query  SELECT status FROM job_table WHERE job_id=1;
    Verify Other Table Values

The two keywords which i can suggest is

Run Keyword and Return Status

wait until keyword succeeds

I just modified your code little bit , to make it more explanatory

*** Settings ***

*** Test Cases ***
TC1
    [Tags]  Debug
    log to console  Test1
    ${success} =  Run Keyword and Return Status  Submit The Job      #Code will not switch to next keyword untill this keyword return the satus as True or False
    log  ${success}
    wait until keyword succeeds  2x  200ms  Submit The Job     #This Kw will run the KW 2 times if  KW fails   while waiting 200ms after each result

*** Keywords ***
Submit The Job
    Sleep  5s

More details about these keywords can be found from Built in KW

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM