In Robot Framework log.html, I want to log the command output that I am executing from a python file . As shown in the attached screenshot of log.html, now I am not able to see the command output. Simple it prints or logs as PASS.
My Robot File:
*** Settings ***
Library test
*** Test cases ***
check
test
Python Keyword:
def test():
cmd = ' net test" '
output = os.popen(cmd).read()
match1 = re.findall('.* (successfully).*',output)
mat1 = ['successfully']
if match1 == mat1:
print "PASS::"
Can anyone guide me on this please?
If you want the output of the command to appear in your log, there are three ways to do it: using the print statement, using the logging API, or using the built in log keyword. These methods are all documented in the robot framework users guide.
Of the three, the logging API is arguably the best choice.
You're already using this method. This is documented in the user guide, in a section named Logging information:
... methods can also send messages to log files simply by writing to the standard output stream (stdout) or to the standard error stream (stderr) ...
Example:
def test():
cmd = ' net test" '
output = os.popen(cmd).read()
match1 = re.findall('.* (successfully).*',output)
mat1 = ['successfully']
if match1 == mat1:
print "output: " + output
There is a public API for logging, also documented in the user guide in a section named Public API for logging:
Robot Framework has a Python based logging API for writing messages to the log file and to the console. Test libraries can use this API like logger.info('My message') instead of logging through the standard output like print 'INFO My message'. In addition to a programmatic interface being a lot cleaner to use, this API has a benefit that the log messages have accurate timestamps.
Example:
from robot.api import logger
def test():
...
logger.info("output: " + output)
Finally, you can also use the built-in log keyword. Using the built in keywords is documented in the user guide in a section titled Using BuiltIn Library.
Test libraries implemented with Python can use Robot Framework's internal modules, for example, to get information about the executed tests and the settings that are used. This powerful mechanism to communicate with the framework should be used with care, though, because all Robot Framework's APIs are not meant to be used by externally and they might change radically between different framework versions.
Example:
from robot.libraries import BuiltIn
...
def test():
...
BuiltIn().log("this is a debug message", "DEBUG")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With