Search code examples
pycharmrobotframeworkselenium2library

Keyword still be executed even the condition is false on robot framework


${result}   get location
Do some click so the link will not same
${elem}     get location

Verify
run keyword unless  '${result}' == '${elem}'    keywordA
run keyword if      '${result}' == '${elem}'    keywordB

I have this example code on robot framework I want to run the keywordA if > condition false and run keywordB if > condition true

But however, if the condition false, the keywordA will executed, but keywordB as well. Anyone can help with solutions? Thanks

basically I want if else statement like

if(condition true) { run B }
 else { run A }

Solution

  • Run Keyword If accepts an ELSE clause

    Run keyword if  '${result}' == '${elem}'  
    ...  keywordB
    ...  ELSE
    ...  keywordA
    

    Here's a complete working example:

    *** Keywords ***
    keywordA
        log to console   \nthis is keyword A
    
    keywordB
        log to console   \nthis is keyword B
    
    *** Variables ***
    ${result}  foo
    ${elem}    foo
    
    *** Test Cases ***
    test case A
        Run keyword if  '${result}' == '${elem}'  
        ...  keywordB
        ...  ELSE
        ...  keywordA