android UiAutomator如何把运行结果写到html文档里
来源:互联网 发布:linux下c语言创建线程 编辑:程序博客网 时间:2024/06/15 15:33
昨天研究了一下如何生成html文件的测试报告,但没有发出来写html文件的代码,经过整理之后,觉得差不多了。发出来供大家参考。
public static void createWebReport(List<String[]> runresult) throws IOException {//这个是页面前面固定的信息String starttext = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>"+"</head><body><h1 style='text-align:center'>android UiAutomator测试报告</h1><p style='text-align:center'>"+getNow()+"测试报告"+"</p>"+"<table border='1' style='table-layout:fixed;font-size:14px;'>"+"<thead>"+"<tr><td width='30px'>编号</td>"+"<td width='120px'>用例名</td>"+"<td width='70px'>运行状态</td>"+"<td width='250px'>错误信息</td>"+"<td width='160px'>错误行Library</td>"+"<td width='160px'>错误行Special</td>"+"<td width='160px'>错误行Case</td><td width='100px'>开始时间</td>"+"<td width='100px'>结束时间</td><td width='100px'>备用列</td></tr>"+"</thead><tbody>";//这里是页面后面固定的信息String endtext = "</tbody></table></body></html>";File file = new File("C:\\Users\\fankaiqiang\\Desktop\\888\\"+getNow()+".html");//新建一个html文档if (!file.exists()) {//判断是否存在,不存在先创建file.createNewFile();}//将运行信息输出到html文档中boolean isClose = false;//写入时用到BufferedWriter bf;FileOutputStream outputStream = new FileOutputStream(file, true);OutputStreamWriter outWriter = new OutputStreamWriter(outputStream);String sheet = "";for (int i = 0; i < runresult.size(); i++) {sheet = sheet + "<tr>";//添加行String[] result = runresult.get(i);//获取用例运行信息for (int j = 0; j < result.length; j++) {if (result[2] == "运行成功") {//运行成功,就用绿色String addtext = "<td style='word-wrap:break-word;word-break:break-all;background-color:paleturquoise'>" + result[j]+ "</td>";sheet = sheet + addtext;} else if (result[2] == "断言错误") {//断言失败,就用黄色String addtext = "<td style='word-wrap:break-word;word-break:break-all;background-color:yellow;'>" + result[j]+ "</td>";sheet = sheet + addtext;} else if (result[2] == "运行错误") {//运行失败就用红色String addtext = "<td style='word-wrap:break-word;word-break:break-all;background-color:red;'>" + result[j]+ "</td>";sheet = sheet + addtext;} else {output("运行信息错误!");}}sheet = sheet + "</tr>";//结束行}bf = new BufferedWriter(outWriter);//写入bf.append(starttext);//写入页面前面的信息bf.append(sheet);//写入报告信息bf.append(endtext);//写入页面后面信息bf.flush();if (isClose) {bf.close();}}
里面用到了一些自己自定义的方法,大家看方法名就知道做什么用了,可以忽略。
阅读全文
0 0
- android UiAutomator如何把运行结果写到html文档里
- 直接把音乐写到android应用程序里
- android UiAutomator利用快速调试生成html文档测试报告
- uiautomator如何编译运行
- 把内容写到文件里
- android UiAutomator如何把log、截图和测试报告放在一起
- Django如何把数据库里的html格式输出到前端
- android uiautomator如何写一个定时任务的方法
- 如何把word文档转换成html
- php中如何把html中的内容生成到word文档
- 如何把图片插入到Excel里
- 如何把session存储到数据库里
- 如何把apk push到systemapp里
- 如何调试 android UIAutomator ?
- 如何把一个现成的exe文件合并到合并到我的程序里?运行时再释放出来?
- 如何实现把web项目的输出流重置,并将打印语句结果写到日志文件
- .py里的结果写到.m中
- 如何把online OCR的结果转换成word文档
- dialog全局显示的两种方式
- 获取properties文件中的value值
- Codeforces Cheap Travel
- csdn如何转载别人的文章
- 搭建本地WordPress开发调试环境
- android UiAutomator如何把运行结果写到html文档里
- 从零开始学习音视频编程技术(十七) 录屏软件开发之音频采集
- 简历不出彩,其实你还可以这样做!
- repo status如何看
- 在docker中使用mysql数据库,在局域网访问
- 常见的linux的基本命令
- 关于BACnet通讯模块在变频器行业的应用
- php数组的合并
- 鼠标右键 左键 滚轮事件