2

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.

4
  • 1
    Put some code in order to be more clear what you want to achieve.
    – chesthar
    Commented Sep 4, 2019 at 21:36
  • Try with this robotframework.org/robotframework/latest/libraries/… Commented Sep 5, 2019 at 19:20
  • 1
    I did try both Run Keyword And Ignore Error and Run Keyword And Expect Error. None of these keywords can prevent a timeout from failing my test case.
    – DDay
    Commented Sep 6, 2019 at 14:25
  • I see, I did not try it before with timeouts. But sadly it does not work then. Maybe you could implement your own timeout mechanism with a python wrapper that won't fail the execution. Commented Sep 7, 2019 at 19:29

1 Answer 1

4

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           FailUntilSucceeds.py    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
1
  • I did not see Wait Until Keyword Succeeds at first so I did not try it. I did try just using a loop of defined size (the same sort of strategy) and that worked okay. Using this keyword works well. Thanks Kartik.
    – DDay
    Commented Sep 17, 2019 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.