Taking a screenshot after each keyword on RF tests

I know that I can use the following environment variable to take a screenshot in case of an error on a RF test:

export ROBOT_SELENIUM2LIBRARY_RUN_ON_FAILURE="Capture page screenshot"

I would like to know if it's possible to take a screenshot automatically after each keyword.

Not in a trivial way, AFAIK.

I believe that could be achieved through Robot Framework listener API, which allows to insert hook after every keyword: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-version-2

Registering listeners work according to RF docs when tests is executed using our ./bin/robot (with ./bin/robot-server running the test fixture). In listener it is possible to access the thread local Selenium instance from Selenium2Library and execute its capture screen keyword.

But I cannot guess for sure, how to add that screenshot into robot framework test log. I'm sorry that I'm currently unable to try that myself and write an example.

1 Like