Python - 生成Robot Framework 类
2016-07-19 20:21
549 查看
Python - 生成Robot Framework 类
Max.Bai
2016-07-19
2016-07-19
最近在写一个web版的RIDE,用到了python执行robot脚本的问题,现做一个记录
当然这样结果里面的内容还是有限的,特别是没有关键字执行的message,那么就需要导入另外一个类ExecutionResult
# Report and xUnit files can be generated based on the result object.
ResultWriter(result).write_results(report='skynet.html', log=None)
# Generating log files requires processing the earlier generated output XML.
ResultWriter('skynet.xml').write_results()
参考:https://robot-framework.readthedocs.io/en/3.0/autodoc/robot.running.html#examples
Max.Bai
2016-07-19
Python - 生成Robot Framework 类
Max.Bai2016-07-19
最近在写一个web版的RIDE,用到了python执行robot脚本的问题,现做一个记录
直接创建TestSuit类
用python脚本生成Robot Framework 里面的TestSuite,并执行from robot.api import TestSuite ts = TestSuite('test') ts.resource.imports.library('Selenium2Library') ts.resource.imports.resource('d:/temp/flows.robot') tc = ts.tests.create('case') tc.keywords.create('Open Browser', args=[u'url=http://www.baidu.com', u'browser=gc']) tc.keywords.create('Go to', args=[u'url=http://tieba.baidu.com']) tc.keywords.create(u'\u5546\u54c1\u8be6\u60c5\u9875\u968f\u673a\u9009\u62e9\u5546\u54c1', args=[]) ts.run()
文件转TestSuite
也可以从robot 文件生产TestSuitefrom robot.api import TestSuiteBuilder suite = TestSuiteBuilder().build('path/to/activate_skynet.robot')
执行结果
run方法可以返回结果,也可以读取一些执行的用例,用例状态等结果result = suite.run(critical='smoke', output='skynet.xml') assert result.return_code == 0 assert result.suite.name == 'Activate Skynet' test = result.suite.tests[0] assert test.name == 'Should Activate Skynet' assert test.passed and test.critical stats = result.suite.statistics assert stats.critical.total == 1 and stats.critical.failed == 0
当然这样结果里面的内容还是有限的,特别是没有关键字执行的message,那么就需要导入另外一个类ExecutionResult
from robot.result import ExecutionResult result = ExecutionResult(outputxml) for case in result.suite.tests: for kw in case.keywords: print kw.name, kw.messages, kw.passed, kw.starttime)
生成Html Report
rom robot.api import ResultWriter# Report and xUnit files can be generated based on the result object.
ResultWriter(result).write_results(report='skynet.html', log=None)
# Generating log files requires processing the earlier generated output XML.
ResultWriter('skynet.xml').write_results()
参考:https://robot-framework.readthedocs.io/en/3.0/autodoc/robot.running.html#examples
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法