Robotframework - is there a way to check value with 'should not conatin' and continue if it fails?

Viewed 117

I'm generating an output from a command and i want to check for potential 4 errors, before continuing

example

should not contain ${output} error1 msg=you have error 1

should not contain ${output} error2 msg=you have error 2

should not contain ${output} error3 msg=you have error 3

should not contain ${output} error4 msg=you have error 4

Currently when error1 matches true the function fails and aborts, a.k.a fatal error I want it to continue running, even if error 1 is met there may be also error 3 or more a.k.a i want it to "fail" not to "fatal error"

is there any way to do that?/use some other means maybe?

2 Answers

One of these keywords should be what you need:

Run Keyword And Continue On Failure

Run Keyword And Return Status

Example 1

Run Keyword And Continue On Failure  should not contain   ${output}   error1 msg=you have error 1

Example 2

${status}  Run Keyword And Return Status  should not contain   ${output}   error1 msg=you have error 1

You've got a couple options:

  1. Run Keyword and Return Status - Will give you back the status (PASS/FAIL Boolean), but also simply ignore the error.
  2. Run Keyword and Ignore Error - Will give you both the status ('PASS'/'FAIL' String) and the value of the error, as well as ignoring it.
*** Keyword ***
Demonstrate Run Keyword and Return Status VS Ignore Error

    ${some_text}=   Set Variable   What does the fox say?

    ${status}=  Run Keyword And Return Status  Should Not Contain   ${some_text}   fox
    Run Keyword If  not ${status}   Log    \nReturned an error   console=yes
    # Outputs `Returned an Error`


    # You can also get the error along with the status by using `Run Keywork and Ignore Error`
    ${status}  ${value}=  Run Keyword And Ignore Error  Should Not Contain   ${some_text}   fox
    Log     ${status}    console=yes  # Outputs `FAIL`
    Log     ${value}    console=yes   # Outputs `'What does the fox say?' contains 'fox'`

    ${status}  ${value}=  Run Keyword And Ignore Error  Should Not Contain   ${some_text}   fox     msg=Custom Error
    Log     ${status}    console=yes  # Outputs `FAIL`
    Log     ${value}    console=yes   # Outputs `Custom Error: 'What does the fox say?' contains 'fox'`

You can find the example source here: https://github.com/FormulatedAutomation/StupidRobotTricks/blob/main/error-handling/tasks.robot#L11

Related