8

In Robot Framework, there is a keyword Run Keyword And Ignore Error.

From the manual:

Runs the given keyword with the given arguments and ignores possible error.

This keyword returns two values, so that the first is either 'PASS' or 'FAIL', depending on the status of the executed keyword. The second value is either the return value of the keyword or the received error message. See Run Keyword And Return Status. If you are only interested in the execution status.

The keyword name and arguments work as in Run Keyword. See Run Keyword If for a usage example.

In which situations is this keyword useful?

If I want to continue my test after a failed keyword, I use Run Keyword And Continue On Failure, in this case I can see in the test report that there was a failed keyword in the test (I don't see it using Run Keyword And Ignore Error). If I need a status of the executed keyword (and want to continue my test if this keyword failed), I use Run Keyword And Return Status.

So what are the cases which cannot be covered with either Run Keyword And Continue On Failure or Run Keyword And Return Status?

1
  • If I have the following: Should Contain Match ${result} [STOP} Could I use the above line with the Run Keyword And Continue On Failure and if it can be done, how would I write the code for it? Jun 5, 2018 at 18:45

4 Answers 4

3

I have used it when doing an If statement, actually in the documentation that you pasted It says exactly that!

The keyword name and arguments work as in Run Keyword. See Run Keyword If for a usage example.

So that would be a good place to see an example of it use

Run keyword if is a keyword for starting if statements:

Runs the given keyword with the given arguments, if condition is true.

And an example:

|${status} | ${value}= | Run Keyword And Ignore Error | My Keyword
| Run Keyword If | '${status}' == 'PASS' Some Action arg ELSE Another Action

1
  • 1
    Well, at least they admit themselves that Instead of Run Keyword And Ignore Error you can also use Run Keyword And Return Status. :D
    – Embedded
    Jan 12, 2018 at 9:00
2

I use Run Keyword and Ignore Error for test setup that is not an essential part of the test.

For example, I may need to delete an object that may or may not be there. It can be easier to just say:

| Run Keyword and Ignore Error | Delete Object | Potential-Object-Name |

1

In a technical sense Run Keyword And Ignore Error is no different from the other two. However, to me the value is in the name of the keyword itself and how it expresses human intention.

Even though you could technically prevent test failure by using Run Keyword And Return Status it would not be as clear as Run Keyword And Ignore Error 12 months after you've written the code, or when some new person comes in and reads the code for the first time.

5
  • Why would I have intention to ignore an error without any further actions?
    – Embedded
    Dec 12, 2017 at 9:58
  • On Stack Overflow I've provided a answer regarding thes same keywords. The reason you may want to use it to capture that there is a failure and want to perform a specific cleanup before entering a more generic teardown Dec 12, 2017 at 10:07
  • But this keyword does not capture a failure, it ignores it completely. Run Keyword And Continue On Failure captures a failure (the test case is marked as failed), Run Keyword And Return Status helps to capture a failure - depending on status you can run different keywords. Run Keyword And Ignore Error does nothing what could be useful for the further test run.
    – Embedded
    Dec 12, 2017 at 10:21
  • This would be useful to create a failure message that descibes the functional error using the keyword Fail Some Functional Message or create a warning Log Some Functional Message level=WARN instead of the technical message that you would otherwise generate. Dec 12, 2017 at 11:47
  • Honestly, I don't get your idea. How would it help me? What are additional possibilities which this keyword gives me and which I cannot easily achieve without using other keywords?
    – Embedded
    Dec 12, 2017 at 12:33
1

In which situations is this keyword useful?

This keyword is useful in a negative scenario: For example you have a login_keyword that succeeded with the proper credentials and fails with wrong one. You have to test that if the user doesn't login with 3 unsuccessful attempts with wrong credential then block the user with the appropriate message on the fourth try. So you are making a 4 loops with unsuccessful login and if you use:

Run Keyword And Continue On Failure | login_keyowrd | @{wrongCredentials}

After the loop finishes and you successfully assert that the user is blocked with the appropriate message the test will be marked as failed in the report, despite the assert of the last step is passed.

If you use Run Keyword And Ignore Error | login_keyowrd | @{wrongCredentials} Then the test will be marked as a PASSED as it is expected to the scenario.

You can complete the scenario of course as stated in the accepted answer:

|${status} | ${value}= | Run Keyword And Ignore Error | login_keyowrd |
Run Keyword If | '${status}' == 'PASS' | Some Action arg | ELSE | Another Action |

But this is one step more instead of using the keyword that you are asking in the question.

Hope it's more clear now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.