Do not take screenshot on controlled failures

I am a noob/intermediate on Browser Library which is by far the most intuitive and fast Library.
The problem that I am having is the personalization of the screenshot.
Running on default, whenever there is failed keyword, robot framework browser library takes a screenshot. But I want to be able to change this behaviour for controlled keyword failure.
For example:

${pass} ${accept_cookies}= Run Keyword And Ignore Error
… Get Element
… id=footer_tc_privacy_button_3
IF ‘${pass}’ == ‘PASS’ Click ${accept_cookies}

As you can see, this is a controlled failure. There might be cases where the footer element doesn’t exist for whatever reason. I don’t want browser library to take a screenshot on this specific failure.
I don’t want to override the default run_on_failure while importing Browser Library. How can I do that? Can someone please help me?

One option would be something like this ?

${previous kw}=    Register Keyword To Run On Failure    NONE
# your stuff below ...
${pass} ${accept_cookies}= Run Keyword And Ignore Error ... Get Element ... id=footer_tc_privacy_button_3 IF '${pass}' == 'PASS' Click ${accept_cookies}
# your stuff above
Register Keyword To Run On Failure    ${previous kw}

Thanks for the fast response, that’s one way to do it.
will ${previous kw} contain the globally set run_on_failure=Take Screenshot \ fail-screenshot-{index} ? will it mess up the global import configuration?
I’ll try it out.

Works like a charm. Thank you!

1 Like