跳至主要内容

RobotFramework调试库和交互式外壳

项目描述

简介

Robotframework-DebugLibrary是RobotFramework的调试库,也可以用作交互式外壳(REPL)。

Maintainability Test Coverage test Latest version Support robotframework versions Support python versions PyPI Downloads License

安装

使用pip进行安装

pip install robotframework-debuglibrary

注意:2.0版本与python 2不兼容

DebugLibrary >= 2.0.0仅支持Python 3.x版本。如果您仍在使用python 2.7,请使用DebugLibrary < 2.0.0

pip install 'robotframework-debuglibrary<2'

使用

您可以将此作为库使用,导入 DebugLibrary 并在测试文件中调用 DebugDebug If 关键字,如下所示

*** Settings ***
Library         DebugLibrary

** test case **
SOME TEST
    # some keywords...
    Debug
    # some else...
    ${count} =  Get Element Count  name:div_name
    Debug If  ${count} < 1

或者,您也可以独立运行它作为 RobotFramework 命令行界面

$ rfdebug
[...snap...]
>>>>> Enter interactive shell
> help
Input Robotframework keywords, or commands listed below.
Use "libs" or "l" to see available libraries,
use "keywords" or "k" to see the list of library keywords,
use the TAB keyboard key to autocomplete keywords.

Documented commands (type help <topic>):
========================================
EOF  continue  docs  help  keywords  libs  ll        n     pdb  selenium
c    d         exit  k     l         list  longlist  next  s    step
> log  hello
> get time
< '2011-10-13 18:50:31'
> # use TAB to auto complete commands
> BuiltIn.Get Time
< '2011-10-13 18:50:39'
> import library  String
> get substring  helloworld  5  8
< 'wor'
> # define variables as you wish
> ${secs} =  Get Time  epoch
# ${secs} = 1474814470
> Log to console  ${secs}
1474814470
> @{list} =  Create List    hello    world
# @{list} = ['hello', 'world']
> Log to console  ${list}
['hello', 'world']
> &{dict} =  Create Dictionary    name=admin    email=admin@test.local
# &{dict} = {'name': 'admin', 'email': 'admin@test.local'}
> Log  ${dict.name}
> # print value if you input variable name only
> ${list}
[u'hello', u'world']
> ${dict.name}
admin
> # start a selenium server quickly
> help selenium
Start a selenium webdriver and open url in browser you expect.

        s(elenium)  [<url>]  [<browser>]

        default url is google.com, default browser is firefox.
> selenium  google.com  chrome
# import library  SeleniumLibrary
# open browser  http://google.com  chrome
< 1
> close all browsers
> Ctrl-D
>>>>> Exit shell.

交互式命令行界面支持自动补全 robotframework 关键字和命令。尝试输入 BuiltIn 然后按 <TAB> 键感受它。历史记录将保存在默认的 ~/.rfdebug_history 或者在环境变量 RFDEBUG_HISTORY 定义的任何文件中。

如果您在使用 rfdebug 时忘记了关键字名称,可以使用 libsls 命令列出导入的库和内置库,以及使用 keywords <lib name>k 命令列出库中的关键字。

rfdebug 接受任何 pybot 参数,但默认情况下,rfdebug 禁用了所有日志记录,使用 -l None -x None -o None -L None -r None

逐步调试

DebugLibrary 自 2.1.0 版本开始支持逐步调试。您可以使用 step/snext/ncontinue/clist/llonglist/ll 来逐步跟踪和查看代码,就像在 pdb 中一样。

$ robot some.robot
[...snap...]
>>>>> Enter interactive shell
> l
Please run `step` or `next` command first.
> s
.> /Users/xyb/some.robot(7)
-> log to console  hello
=> BuiltIn.Log To Console  hello
> l
  2         Library  DebugLibrary
  3
  4         ** test case **
  5         test
  6             debug
  7 ->          log to console  hello
  8             log to console  world
> n
hello
.> /Users/xyb/some.robot(8)
-> log to console  world
=> BuiltIn.Log To Console  world
> c
>>>>> Exit shell.
world

注意:当前逐步调试不支持 FOR 循环。

提交问题

错误和增强功能在 问题跟踪器 中跟踪。

在提交新问题之前,检查是否已报告相同的错误或增强功能总是个好主意。如果是,请向现有问题添加您的评论,而不是创建一个新问题。

开发

如果您想在本地开发和运行 DebugLibrary,可以使用

$ python DebugLibrary/shell.py tests/step.robot

shell.py 是通过子进程调用 robot 的,所以它会中断 Python 调试功能。如果您想在 vsCode、pdb 等工具中调试,应该运行

$ python -m robot tests/step.robot

如果您要运行测试,请先安装依赖包,然后执行测试

$ python -m pip install setuptools
$ python setup.py develop
$ python setup.py test

由于 RF 控制了 stdout,调试信息可以通过

import sys
print('some information', file=sys.stdout)

许可

此软件根据 New BSD License 许可。有关完整许可文本,请参阅顶级发行目录中的 LICENSE 文件。

项目详情


下载文件

下载适合您平台的项目文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

robotframework-debuglibrary-2.5.0.tar.gz (18.4 kB 查看哈希值)

上传时间 源代码

构建分发

robotframework_debuglibrary-2.5.0-py3-none-any.whl (19.2 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面