从Python写入机器人框架控制台 [英] Write to robot framework console from Python

查看:124
本文介绍了从Python写入机器人框架控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用python的新手,我想向您寻求帮助,向我展示如何将Python中的消息打印到机器人框架控制台中。

I am a newbie using python and I wanted to ask for your help in showing me how can I print messages from Python into robot framework console.

推荐答案

python函数可以通过多种方式将信息发送到机械手日志或控制台。这些都记录在《机器人框架》用户指南的记录信息

There are several ways for a python function to send information to the robot logs or to the console. These are all documented in the Robot framework user's guide, in the section titled Logging information.

最干净的方法是使用日志记录API ,它提供了用于各种日志记录的专门功能。例如,要将信息发送到控制台,您可以使用 logger.console(message)

The cleanest way is to use the logging API, which gives specialized functions for various kinds of logging. For example, to send information to the console you would use logger.console(message).

此处是使用此方法的库文件:

Here is a library file that uses this method:

# ExampleKeywords.py
from robot.api import logger
def write_to_console(s):
    logger.console(s)

您可以通过以下方式使用该库:

You can use this library in the following manner:

*** Settings ***
| Library | ExampleKeywords.py

*** Test Cases ***
| Use a custom keyword to write to the console
| | Write to console | Hello, world

这只会出现在控制台中,并且不会显示在日志中。如果您希望信息显示在日志中,则可以使用记录器方法 info 警告调试跟踪。要记录错误,您只需抛出异常即可。

This will appear in the console only, and will not show up in the logs. If you want the information to show up in the logs you can use logger methods info, warn, debug, or trace. To log an error you would simply throw an exception.

还有其他方法为您的自定义关键字将信息发送到日志。例如,您可以获取对BuiltIn库的引用,然后直接调用 log 登录到控制台关键字,如下所示:

There are other ways for your custom keywords to send information to the logs. For example, you can get a reference to the BuiltIn library, and directly call the log or log to console keywords like this:

from robot.libraries.BuiltIn import BuiltIn
def write_to_console(s):
    BuiltIn().log_to_console("Hello, world")



使用打印语句



最后,您可以使用打印语句将信息写入日志(但不仅限于控制台)。您可以在字符串前加上 *< level> * 来影响日志级别。例如,要打印警告,您可以执行以下操作:

Using print statements

Finally, you can write information to the logs (but not only to the console) using print statements. You can prefix the string with *<level>* to affect the log level. For example, to print a warning you can do:

print "*WARN* Danger Will Robinson"



摘要



使用API​​可以说是记录信息的最佳方法从您的关键字。但是,这是一个相当新的API,仅从Robot Framework 2.6起可用,因此,如果您使用的是旧版本的Robot,则可能需要使用其他技术之一。

Summary

Using the API is arguably the best method to log information from your keywords. However, this is a fairly new API only available since Robot Framework 2.6, so if you are using an older version of Robot you may need to use one of the other techniques.

这篇关于从Python写入机器人框架控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆