在实际写testcase的时候会使用unittest框架,但是在sikuli中需要使用它提供的command来运行,位于/Applications/SikuliX.app/run,使用-r参数指定要运行的sikuli文件,然后再使用 --args参数将想传给这个sikuli文件的参数附在后面:

sudo /Applications/SikuliX.app/run -r testcases/runner_html.sikuli --args report:[test report file, a html file] cases:[case id list] build:[build_id]

而且为了能直接输出html的测试报告,使用了HTMLTestRunner来运行一个testsuite,具体代码如下:

 import sys
import os
import re
import unittest lib = os.path.join(os.path.expanduser("~"), "mac_auto")
if lib not in sys.path:
sys.path.append(lib) from global_config import * if path_of_site_packages not in sys.path:
sys.path.append(path_of_site_packages) from htmloutput.html_test_runner import HTMLTestRunner report_file = None
test_case_ids = None
build = None
for arg in sys.argv[1:]:
if arg.startswith("report:"):
report_file = arg.split(":")[1]
print "test result file is " + report_file
if arg.startswith("cases:"):
test_case_ids = arg.split(":")[1].split(",")
if arg.startswith("build:"):
build = arg.split(":")[1] # It'll load all test caes in current folder if no test case indicated
if test_case_ids is None or len(test_case_ids) == 0:
print "Loading all test cases in current folder"
test_case_module_names = [re.sub("\.sikuli$", "", i) for i in os.listdir(
os.path.join(test_home_path, "testcases")) if i.startswith("test_case")]
else:
test_case_module_names = ["test_case_{0}".format(i) for i in test_case_ids] test_case_modules = []
for i in test_case_module_names:
print "Importing module " + i
test_case_modules.append(__import__(i, globals(), locals(), [], -1)) suite = None
if len(test_case_modules) >= 1:
suite = unittest.TestLoader().loadTestsFromModule(test_case_modules[0])
for m in test_case_modules[1:]:
suite.addTests(unittest.TestLoader().loadTestsFromModule(m)) outfile = open(report_file, "w")
runner = HTMLTestRunner(stream=outfile, verbosity=2, title='OSX Test Report', build=build) print "Start running test"
runner.run(suite)

上面的代码将搜索testcases目录下以test_case开头的sikuli文件,将其动态导入到testloader中运行。

另外也对HTMLTestRunner做了一下改变,让其能输出指定的build信息。

在命令行中输入如下命令,将运行所有testcases目录下得测试用例,并输出结果到test_result.html:

sudo /Applications/SikuliX.app/run -r testcases/runner_html.sikuli --args report:test_result.html build:your_build_id

输出的html显示如下信息:

python有个优秀的测试工具叫nose,它扩展了unittest的功能,使得其更加易用,我们也可以在sikuli写成的testcase上使用nose的标签标记我们的testmethod,然后使用nose.core.run来在sikuli文件运行测试,代码如下:

 import sys
import os lib = os.path.join(os.path.expanduser("~"), "mac_auto")
if lib not in sys.path:
sys.path.append(lib)
import global_config if global_config.path_of_site_packages not in sys.path:
sys.path.append(global_config.path_of_site_packages)
import nose
from htmloutput.html_for_nose import HtmlOutput build = None
for arg in sys.argv[1:]:
if arg.startswith("--build="):
build = arg.split("=")[1]
sys.argv.remove(arg) args = sys.argv[1:]
print args nose.core.run(argv=args, addplugins=[HtmlOutput(title='OSX Test Report', build=build)])

默认nose输出的是一个xunit的testresult,可以方便的在jenkins上解析出来。这里我加了一个nose的plugin,使其可以输出html的测试结果,使用的是一个对HTMLTestRunner.py的修改版本,位于github的这里:

https://github.com/openstack-infra/nose-html-output/blob/master/htmloutput/htmloutput.py

将上面的代码存为一个sikuli文件,命名为runner_nose.sikuli,然后使用下面的命令运行标记为BVT的所有测试:

sudo /Applications/SikuliX.app/run -r testcases/runner_nose.sikuli --args -v --with-xunit --xunit-file=result.xml --attr=BVT --build=your_build_id

上输出的是一个xunit的测试结果,也可以使用下面的命令输出一个html的结果:

sudo /Applications/SikuliX.app/run -r testcases/runner_nose.sikuli --args -v --with-html-output --html-out-file=result.html --attr=BVT --build=your_build_id

最新文章

  1. winform异步系统升级—BackgroundWorker
  2. TensorFlow中与卷积核有关的各参数的意义
  3. Android Tips – 填坑手册
  4. 【Cocos2d-Js基础教学(6)网络层(弱联网)的封装及使用】
  5. 12.PHP内核探索:PHP的FastCGI
  6. 锋利的Jquery解惑系列(一)------基本概念大锅炖
  7. Orchard站点性能优化-预热
  8. 警惕 MySql 更新 sql 的 WHERE 从句中的 IN() 子查询时出现的陷阱
  9. Android下QQ空间查看大图特效
  10. Unity游戏程序员面试题及解答
  11. 一:Redis的7个应用场景
  12. Java 到底是值传递还是引用传递
  13. 一个很不错的支持Ext JS 4的上传按钮
  14. python&django 实现页面中关联查询小功能(中级篇)
  15. c提高第三次作业
  16. Recurrent Neural Network[survey]
  17. Mysql初级第二天(wangyun)
  18. 通过PMP考试
  19. 【CF605E】Intergalaxy Trips(贪心,动态规划)
  20. PAC 自动代理

热门文章

  1. Unity Shader实现描边效果
  2. docker 摆渡镜像脚本
  3. linux下常用的基本设置与操作C语言实现
  4. 给JavaScript文件传入参数的几种方法
  5. 【转】 Pro Android学习笔记(八七):了解Handler(1):组件和线程
  6. uptime命令查看系统启动时间和运行时间、查看linux系统负载
  7. tree指令
  8. AngularJS:API
  9. Adobe Flash 无法正常使用
  10. PowerDesignerPDM中搜寻表名或字段名