Skip to content

ReplaceRunKeywordIf

Replace Run Keyword If keyword calls with IF expressions.

Disabling the formatter

ReplaceRunKeywordIf is included in the default formatters, but it can be also run separately with:

robocop format --select ReplaceRunKeywordIf

You can also disable it:

robocop format --configure ReplaceRunKeywordIf.enabled=False
*** Keywords ***
Keyword
    Run Keyword If  ${condition}
    ...  Keyword  ${arg}
    ...  ELSE IF  ${condition2}  Keyword2
    ...  ELSE  Keyword3
*** Keywords ***
Keyword
    IF    ${condition}
        Keyword    ${arg}
    ELSE IF    ${condition2}
        Keyword2
    ELSE
        Keyword3
    END

Any return value will be applied to every ELSE/ELSE IF branch.

*** Keywords ***
Keyword
    ${var}  Run Keyword If  ${condition}  Keyword  ELSE  Keyword2
*** Keywords ***
Keyword
    IF    ${condition}
        ${var}    Keyword
    ELSE
        ${var}    Keyword2
    END

Run Keywords inside Run Keyword If will be split into separate keywords.

*** Keywords ***
Keyword
    Run Keyword If  ${condition}  Run Keywords  Keyword  ${arg}  AND  Keyword2
*** Keywords ***
Keyword
    IF    ${condition}
        Keyword    ${arg}
        Keyword2
    END

Run Keyword If that assigns values but does not provide a default branch will receive ELSE branch with Set Variable:

    *** Keywords ***
    Keyword
        ${var}  Run Keyword If  ${condition}  Keyword
*** Keywords ***
Keyword
    IF    ${condition}
        ${var}    Keyword
    ELSE
        ${var}    Set Variable    ${None}
    END