Search code examples
robotframework

How to add Info to custom keyword Log


In Robot Framework, when you create a custom keyword using the *** Keyword *** section of .robot file, is there a way to print an INFO message in the log file? I've tried using BuiltIn.Log keyword, but it creates a new keyword section where the INFO is written.

I want to get INFO in custom keyword this way: Info in Keyword execution

Info in Keyword execution

But currently, my only option is: Info inside BuiltIn.Log definition

Info inside BuiltIn.Log definition

Is there a way to add INFO directly to my custom keyword without using Python API?


Solution

  • To my knowledge what you are attempting, is unfortunately not doable. This way of embedding messages can be done by the robot.logger or Python's logging api - More info in the Robot Framework User Guide

    However in addition to using the Log keyword, you may alleviate the need by first adding a documentation string on your keywords - the first line is always shown in the Documentation section of the keyword. Additionally by enabling Trace on the log file you'll get at least the Arguments and Return values shown on each keyword.

    The Documentation is added with the [Documentation] tag similar to

    Custom Keyword
        [Documentation]    This string is shown completely until I leave at least
        ...    One empty row.
        ...
        ...    This is shown only in the library documentation file.
    

    And logging modes are changed with a launch option -L or --loglevel, to enable Trace mode, simply add the option when launching your robot.

    robot -t TestName -s SuiteName -L TRACE .\Path\to\Tests