SeleniumLibrary Screenshot on Failure with python

Hi,

We use Robot Framework and SeleniumLibrary for most of our testing. Recently we started exploring using python more specially for building more complex keywords. We noticed that when these keywords fail, even when they fail when calling SeleniumLibrary keywords, they do not log screenshots.

As an example:
When implemented with Robot Framework:

When implemented with Python:

The logging still happens but no screenshot is taken at failure. Reading through the code, it seems the handler in SeleniumLibrary doesn’t trigger since it’s not technically a SeleniumLibrary keyword that failed. Any ideas on how we can still get screenshots on failure even when calling SeleniumLibrary keywords in a python library?

Maybe you need to ensure your keywords in python library use try/except and call Capture Screenshot when failing.

Run on failure functionally is built by using Robot Framework dynamic library API. Therefore if you directly call methods implementing keywords, you are bypassing this feature and you need to implement this by yourself. Luckily it’s easy to do, example by using Python decorator Decorators in Python - GeeksforGeeks

Yeah, this was the way and @aaltat 's answer with this Try/Catch did to the trick. Thanks!

That did the trick. Thanks for the answer! Had to extend from the DynamicCore so i can define my own handling for run_keyword.

1 Like