- 在此记录下之前开发web版ride的过程中,遇到了python执行robot脚本的问题。
直接创建TestSuit类
- 通过python脚本生成Robot Framework 里面的TestSuite,并执行以下逻辑: 123456789from robot.api import TestSuitets = 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()
robot文件转TestSuite
- 也可以从robot 文件生产TestSuite 123from robot.api import TestSuiteBuildersuite = TestSuiteBuilder().build('path/to/activate_skynet.robot')
执行结果逻辑
run方法可以返回结果,也可以读取一些执行的用例,用例状态等结果
123456789result = suite.run(critical='smoke', output='skynet.xml')assert result.return_code == 0assert result.suite.name == 'Activate Skynet'test = result.suite.tests[0]assert test.name == 'Should Activate Skynet'assert test.passed and test.criticalstats = result.suite.statisticsassert stats.critical.total == 1 and stats.critical.failed == 0当然这样结果里面的内容还是有限的,特别是没有关键字执行的message,那么就需要导入另外一个类ExecutionResult
123456from robot.result import ExecutionResultresult = ExecutionResult(outputxml)for case in result.suite.tests:for kw in case.keywords:print kw.name, kw.messages, kw.passed, kw.starttime)
生成HTML报告
|
|