How can a test called by Robot Framework return information to the console

南笙酒味 提交于 2019-12-04 03:51:44
Pekka Klärck

Since you are using Python you have two simple possibilities:

  1. Write your messages to the stderr. These messages are written both to Robot's log file and to the console. A limitation is that the messages end up to the console only after the keyword you are executing finishes. A bonus is that this approach works also with Java based libraries.

  2. Write your messages to sys.__stdout__ in Python. Robot only intercepts sys.stdout and sys.stderr and leaves sys.__stdout__ (and sys.__stderr__) alone (as all well behaving Python programs should). These messages only end up to the console, but you can write them also to sys.stdout to get them also to the log file.

You can use the robot.api library. This is the document for the library

https://robot-framework.readthedocs.org/en/latest/_modules/robot/api/logger.html

Have your lib return a string, then use Set Test Message to display it.

My Test Case  [Documentation]  display data returned from lib call
  ${r} =  mylib.libfunc  arg=param
  Set Test Message  libfunc returned ${r}

ref: http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html#Set%20Test%20Message

Updates:

  1. new link: http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Test%20Message
  2. new Log To Console command outputs to console in real time (i.e. during test execution, as opposed to Set Test Message which outputs only at the end of the test case.)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!