robotframework学习- logger, keyword, libdoc
robotframework 接口学习1 --robot.run
https://robot-framework.readthedocs.io/en/latest/autodoc/robot.html
robotframework 提供以下命令行入口,
run(): 执行用例的函数
run_cli():函数
rebot():函数
rebot_cli():函数,
libdoc(): 生成库文档模块
testdoc:生成测试用例文档模块
tidy(): 模块
函数导入方式: from robot import run
模块导入方式: from robot.libdoc import libdoc_cli
robot.run(*tests, **options)
运行测试用例的入口,
tests: 为测试用例文件或者目录的路径,和命令行执行robot命令类似
options: 配置和控制执行的选项。可接受的选项大部分和命令行命令robot可接受的选项类似。 除了--pythonpath,
--argumentfile, --help, --verision。
命令行多次给出的选项,可通过列表传递,比如 include = ['tag1', 'tag2']参数, 等效于命令行的 --include tag1 --include tag2。
选项也可以是单个字符串比如 include='tag'
命令行中选项没有给出值,在函数调用时是传递True。 比如--dryrun, 函数对应是 dryrun=True
robot.run()函数的返回码 和命令行robot返回码类似。 0表示用例已执行,且没有critical 用例失败,1-250表示critical用例执行失败的个数。
251-255表示其他状态,相关信息在Guide手册查找。
函数执行的情况
from robot import run
run('path/to/tests.robot')
run('tests.robot', include=['tag1', 'tag2'], splitlog=True)
with open('stdout.txt', 'w') as stdout:
run('t1.robot', 't2.robot', name='Example', log=None, stdout=stdout)
和以下的命令行是等效的
robot path/to/tests.robot
robot --include tag1 --include tag2 --splitlog tests.robot
robot --name Example --log NONE t1.robot t2.robot > stdout.txt
robotframework 接口学习2- robot.libdoc
robot.libdoc.libdoc(library_or_resource, outfile, name='', versrion='', format=none,docformat=none)
example
from robot.libdoc import libdoc
libdoc('MyLibrary.py', 'MyLibraryDoc.html', version='1.0')
可通过以下链接,查询相关命令行操作
https://robotframework-userguide-cn.readthedocs.io/zh_CN/latest/SupportingTools/Libdoc.html
python -m robot.libdoc libraryName outfileName
C:\Users\liuzhipeng\Desktop\RF>python -m robot.libdoc LoggingLibrary.py MyLibraryDoc.html
robotframework 接口学习3 -robot.api.deco.keyword
deco为装饰器decorator的缩写
https://robot-framework.readthedocs.io/en/latest/autodoc/robot.api.html#submodules
robot.api.deco.keyword(name=None, tags=(), types=())
装饰器用于自定义关键字名称,标签,和关键字参数的类型。
name必须是字符串, tags是列表,而types可以是字典(key为参数名称,value为类型), 也可以是列表或元祖,会根据参数的位置去映射
。 指定部分参数的类型也是可以的,
from robot.api.deco import keyword
@keyword(name='Login Via User Panel')
def login(username, password):
# ...
@keyword(name='Logout Via User Panel', tags=['example', 'tags'])
def logout():
# ...
@keyword(types={'length': int, 'case_insensitive': bool})
def types_as_dict(length, case_insensitive=False):
# ...
@keyword(types=[int, bool])
def types_as_list(length, case_insensitive=False):
# ...
@keyword(types=None])
def no_conversion(length, case_insensitive=False):
# ...
robotframework 接口学习4 -robot.api.logger
from robot.api import logger
def my_keyword(arg):
logger.debug('Got argument %s.' % arg)
do_something()
logger.info('is a boring example.')

浙公网安备 33010602011771号