Search code examples
selenium-webdriverrobotframework

Robot Framework - capture screenshot when any keyword fails (not only selenium keywords)


I'm making automated tests cases with mix of selenium and builtin keywords in Robot Framework.

I have made the:

Register Keyword To Run On Failure Screenshot On Failure

which overwrites the default behavior to create selenium-screenshot-index.png (I needed other names). Everything works fine if the keyword failing is part of the selenium library. If not (let's say custom or builtin one) the screenshot is not taken.
Is there a way, to register the keyword to run on any failure in any keyword?


Solution

  • Well, depending on your actual goal solution could be quite simple or require a little bit of python programming.

    1. Simple solution. I would say that taking one screenshot in test teardown if test case failed is enough in most of the cases.
    2. Writing custom listener interface that would grab instance of library (Selenium, OS) and depending on keyword status would take action.