Search code examples
pythonrobotframeworkrobots.txt

How to store response in variable in ROBOT framework


I am trying to store the response of built-in in a variable but I am getting None as a response whats the proper way of storing value

    ${item} =         Page Should Contain    The login hasfailed.
    Log To Console    ${item}

Expected

I need the value of Page Should Contain The login has failed. i.e True or False is it possible?


Solution

  • That is because Page Should Contain has no return value. You can achieve your goal with Run Keyword And Ignore Error from builtin library.

    test 
        ${result}=    Run Keyword And Ignore Error    Page Should Contain    The login hasfailed.
        Log    ${result}
    

    And since version 5.0 of robot framework try and except has been introduced

    test 
        TRY
            Page Should Contain    The login hasfailed.
            Set Test Variable    ${item}    ${TRUE}
        EXCEPT
            Log    keyword failed
            Set Test Variable    ${item}    ${FALSE}
        END
        Log    ${item}