RobotFramework调试库和交互式外壳
项目描述
简介
Robotframework-DebugLibrary是RobotFramework的调试库,也可以用作交互式外壳(REPL)。
安装
使用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 并在测试文件中调用 Debug 或 Debug 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 时忘记了关键字名称,可以使用 libs 或 ls 命令列出导入的库和内置库,以及使用 keywords <lib name> 或 k 命令列出库中的关键字。
rfdebug 接受任何 pybot 参数,但默认情况下,rfdebug 禁用了所有日志记录,使用 -l None -x None -o None -L None -r None。
逐步调试
DebugLibrary 自 2.1.0 版本开始支持逐步调试。您可以使用 step/s、next/n、continue/c、list/l 和 longlist/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 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c8e135c7561721d36210d6f59a09b7538064367e82d8a3be67cb87088cf9cba7 |
|
MD5 | ce8c5ea441437c7a194889a97833a912 |
|
BLAKE2b-256 | fdb3c5fa5fb8e0786efacc30a16f9ae62d90d838516c2dea08ad2733d679bd66 |
robotframework_debuglibrary-2.5.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a2bfb2636ead7be440c224317891b4b406a9a71d84b26924031ccf3791a00b96 |
|
MD5 | 8d504f238e7c1daf075da386d3e1fede |
|
BLAKE2b-256 | 733294f7b214f9bbbbf4d461e44a58533a7bf144477df43d3d741fe57f5a5143 |