Search code examples
seleniumrobotframework

How to run something after every step in Robot Framework


I'd like to check something after every step in a test case in Robot Framework. I am including a dummy example to represent what I am referring for:

*** Test Cases ***
Order From Somewhere
    [Tags]  whatever tags here
    Step1
    #Grab Exception
    Step2
    #Grab Exception
    Step3
    #Grab Exception
    Step4
    #Grab Exception
    Step5
    #Grab Exception
    Step6
    #Grab Exception
    Step7

I assume there is some way to have '#Grab Exception' executed after every Step, but in a nice way.

Thanks for your help in advance.


Solution

  • You can define your own keyword to do that, for example:

    *** Test Cases ***
    Test Special Keywords
        Special Keyword    Sleep    5 seconds
        Special Keyword    Log    <b>This is another keyword</b>    HTML
    
    *** Keywords ***
    Special Keyword
        [Arguments]    ${kw}    @{arguments}
        Run Keyword    ${kw}    @{arguments}
        Grab Exception
    
    Grab Exception
        Log    Called <i>Grab Exception</i>    HTML