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.

解决方案

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.

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).

Using the logging API

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

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.

Calling built-in keywords

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")

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 ** to affect the log level. For example, to print a warning you can do:

print "*WARN* Danger Will Robinson"

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写机器人插件_从Python写入机器人框架控制台相关推荐

  1. python写网页插件_用python 实现activex网页控件

    首先,这个东东貌似只有windows上才能实现,所以,需要部署windows下的相关环境 1.需要安装python 2.安装python的win32com的lib,下载地址: 3.安装本地的web容器 ...

  2. python写chrome插件_用VueJS写一个Chrome浏览器插件

    浏览器基本已经天下大统了,放眼望去都是Chromium的天下.那么,能写一个浏览器插件也算是一种回报率不错的技能. 基本知识 浏览器插件官方的说法叫扩展程序,允许你为浏览器增加各种功能,但不需要深入研 ...

  3. python写魔兽世界脚本_用python bat写软件安装脚本 + HM NIS Edit自动生成软件安装脚本...

    2019-03-11更新:原来NSIS脚本也可以禁用64位文件操作重定向的! 1.在安装脚本的开始处定义 LIBRARY_X64. !include "MUI.nsh" !incl ...

  4. python写mysql脚本_使用python写一个监控mysql的脚本,在zabbix web上加上模板

    使用python写一个监控mysql的脚本,在zabbix web上加上模板: ##先使用MySQLdb的接口关联数据库. [root@cml python]# cat check_Mysql_cus ...

  5. python写一个类方法_重写python脚本,在脚本的每个类中注入一个方法 - python

    假设我有一个python模块foo.py,其中包含: class Foo(object): def __init__(self): pass 接下来,我想解析此脚本,并在每个类中注入一个方法,然后将其 ...

  6. python 写一个计算器_用 Python 写个计算器

    首页 专栏 python 文章详情 0 用 Python 写个计算器 Python小二 发布于 56 分钟前 我们常见的计算辅助工具有两种,一种是古人发明的算盘,另一种就是我们现代人发明的计算器,与算 ...

  7. python写爬虫教程_用Python写爬虫程序基础教程(一)

    最近身边朋友都在讨论股市是不是牛市要来了吧? 如果想自己做一个股市收盘价前三十名的涨跌幅度,又不用每天去点击网页浏览,用Python写个爬虫程序来做是不是超棒der 环境建置 安装Python 安装P ...

  8. 用python写shell脚本_应用python编写shell脚本

    今天同事叫我编写一个shell脚本.话说,虽然我受*nix的影响甚深,但是对于*nix里随处可见的sh脚本却是讨厌之极.为什么讨厌呢?首先是因为sh脚本那莫名其妙的语法,感觉就像随写随扔的程序,完全没 ...

  9. python写采集程序_用python写的一个wordpress的采集程序

    在学习python的过程中,经过不断的尝试及努力,终于完成了第一个像样的python程序,虽然还有很多需要优化的地方,但是目前基本上实现了我所要求的功能,先贴一下程序代码: 具体代码如下: #! /u ...

最新文章

  1. 不出家门也能喝上原汁原味的泰国国汤——冬阴功汤
  2. vscode快捷操作
  3. 郑州军办计算机学校,郑州市国防科技学校2019级新生开启军训模式
  4. OpenCV之邻域运算之最值滤波
  5. Your shell has not been properly configured to use 'conda activate'
  6. LeetCode之Count and Say
  7. thymeleaf if判断_Thymeleaf入门——入门与基本概述
  8. centos7 开机启动文件路径_centos7定时运行python脚本
  9. java判断闰年代码_根据输入的年份判断是否是闰年?(在JAVA用if-else)
  10. SpringCloud 之客户端负载均衡策略
  11. leetcode 合并两个有序数组
  12. 系统优化怎么做-开篇
  13. 中国人民大学计算机系孙辉,张静(中国人民大学信息学院计算机系讲师)_百度百科...
  14. 反病毒引擎设计(一):绪论 本文来自:剑盟反病毒技术门户(www.janmeng.com)
  15. 数组旋转(上下对称,主对角线对称)
  16. ThinkPHP 配置详解
  17. k3 审核流程图_K3单据使用解释及流程图明细
  18. rust键位失灵_用Rust写操作系统(四)——竞争条件与死锁
  19. Python:教你如何写一个测量网速的小工具
  20. ChinaSoft 论坛巡礼 | 面向可解释人工智能的软件工程方法与技术论坛

热门文章

  1. Nhibernate学习的第一天
  2. Thinkphp列表搜索排序-----查
  3. 各式各样的极品程序员 你属于哪一种
  4. 运行VS2012出现“未找到与约束....”的解决方法
  5. 采用cookie简单实现文章顶/踩功能
  6. Google发布Chrome 8
  7. php如何获取js中的内容_解析PHP中的Javascript提取
  8. Python爬虫实战源码合集(持续更新)
  9. 高通平台framework,hal,kernel打开log
  10. 集成Android免费语音合成功能(在线、离线、离在线融合),有这一篇文章就够了(离线)