How can I limit a keyword's execution time without failing?

  • I am testing an API on a server. When I close the connection from another external computer to that server it takes some amount of time to complete. I want to limit the amount of time my test waits for disconnection to complete, but I need to continue with the next test keyword. Short of cutting my test suite into 2 consecutive test cases, is there some way to tell Robot Framework to allow my keyword t seconds to complete and then to continue along?

    I have tried to use a timeout, but that causes the test to fail and I need it to continue. I am not using Selenium since this is an API test.

  • You Can use Wait Until Keyword Succeeds keyword . like:

    Wait Until Keyword Succeeds  5x    4s   click Element   xpath=........

    Here 5x is how many times you want to execute your action and 4s is your time duration, how frequently you want to wait until next try.

    Any Many More usage below -

    *** Settings ***
    Library           ExampleLibrary
    Library     3
    *** Variables ***
    ${HELLO}          Used to test that variable name, not value, is shown in arguments
    *** Test Cases ***
    Fail Because Timeout exceeded
        [Documentation]    FAIL GLOB: Keyword 'Fail Until Retried Often Enough' failed after retrying for 100 milliseconds. The last error was: Still ? times to fail!
        Wait Until Keyword Succeeds    0.1 seconds    50ms    Fail Until Retried Often Enough
    *** Keywords ***    
    User Keyword
        ${value} =    Fail Until Retried Often Enough    From User Keyword
        [Return]    ${value}
    Wait Until Inside User Keyword
        Wait Until Keyword Succeeds    3.99 seconds    0.1    Fail Until Retried Often Enough
    Timeouted UK with Wait Until KW
        [Arguments]    ${timeout}
        [Timeout]    ${timeout}
        Wait Until Keyword Succeeds    100ms    10ms    Fail    Error in timeouted UK
    Access Nonexisting Variable
        Log    ${nonexisting}
        Fail    Should NEVER be executed
    Access Initially Nonexisting Variable
        Log    ${created after accessing first time}
        [Teardown]    Set Test Variable    ${created after accessing first time}    created in keyword teardown
    Pass with first Try
        Wait Until Keyword Succeeds    2 minutes    30 seconds    Log    ${HELLO}
    Pass With Some Medium Try
        Wait Until Keyword Succeeds    ${42}    2 milliseconds    Fail Until Retried Often Enough

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2