Robotframework-Database-Library icon indicating copy to clipboard operation
Robotframework-Database-Library copied to clipboard

Smart wait for "check if exists" / "row count" assertion keywords

Open amochin opened this issue 1 year ago • 0 comments

The assertion keywords like "Check if (not) exists" or "row count" would currently immediately fail if the intended check fails - which is basically as expected. However, in real life it's often needed to wait, until some data appears / disappears in the DB - which takes some time. This is typically solved with a high level keyword, which repeats the assertion multiple times (with a pause) until the assertion is passed or the timeout is reached. Example:

Wait Row Present In Database
    [Arguments]    ${SQL}    ${Should Be Present}=True    ${Timeout}=2 Seconds
    ${done}=    Set Variable    ${False}
    WHILE    not $done    limit=${Timeout}
        ${results}=    Query    ${SQL Anfrage}
        IF    ${Should Be Present}
            ${done}=    Evaluate    len($results) > 0
        ELSE
            ${done}=    Evaluate    len($results) < 1
        END
        IF    not $done
            Sleep    0.1s
        END
    END
    RETURN    ${results}

It would be nice to include such kind of smart waiting directly in the library keywords.

amochin avatar Feb 13 '24 09:02 amochin