Commit c3ea6688 by shuai

testGitLab20181015

parent 2e4bac5f
...@@ -63,13 +63,14 @@ ...@@ -63,13 +63,14 @@
<target name="testoutput" depends="runtest"> <target name="testoutput" depends="runtest">
<!--
<java classname="com.offcn.TestUnti.Mail" classpath="${basedir}/bin"> <java classname="com.offcn.TestUnti.Mail" classpath="${basedir}/bin">
<sysproperty key="file.encoding" value="UTF-8" />
<classpath> <classpath>
<pathelement location="lib/javax.mail.jar" /> <pathelement location="lib/javax.mail.jar" />
</classpath> </classpath>
</java> </java>
<!--
ui自动化测试报告部分 ui自动化测试报告部分
<xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html "> <xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html ">
......
package com.offcn.TestUnti;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class ReadHtml {
public static void main(String[] args) {
try {
readFile_("overview.html");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String readFile_(String htmlfilename)throws IOException{
File directory = new File(".");
String sourceFile = directory.getCanonicalPath() +File.separator+"test-output"+File.separator+"html"+File.separator+htmlfilename;
FileInputStream fis = new FileInputStream(sourceFile);
byte[] buf = new byte[1024];
int len = 0;
StringBuffer sb=new StringBuffer();
while((len=fis.read(buf))!=-1)
{
sb.append(new String(buf,0,len));
// System.out.println(new String(buf,0,len));
}
fis.close();
// System.out.println(sb);
return sb.toString();
}
}
package com.offcn.TestUnti;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* ZipUtils
* @author ZENG.XIAO.YAN
* @date 2017年11月19日 下午7:16:08
* @version v1.0
*/
public class ZipUtils {
private static final int BUFFER_SIZE = 2 * 1024;
/**
* 压缩成ZIP 方法1
* @param srcDir 压缩文件夹路径
* @param out 压缩文件输出流
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure)
throws RuntimeException{
long start = System.currentTimeMillis();
ZipOutputStream zos = null ;
try {
zos = new ZipOutputStream(out);
File sourceFile = new File(srcDir);
compress(sourceFile,zos,sourceFile.getName(),KeepDirStructure);
long end = System.currentTimeMillis();
System.out.println("压缩完成,耗时:" + (end - start) +" ms");
} catch (Exception e) {
throw new RuntimeException("zip error from ZipUtils",e);
}finally{
if(zos != null){
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 压缩成ZIP 方法2
* @param srcFiles 需要压缩的文件列表
* @param out 压缩文件输出流
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
public static void toZip(List<File> srcFiles , OutputStream out)throws RuntimeException {
long start = System.currentTimeMillis();
ZipOutputStream zos = null ;
try {
zos = new ZipOutputStream(out);
for (File srcFile : srcFiles) {
byte[] buf = new byte[BUFFER_SIZE];
zos.putNextEntry(new ZipEntry(srcFile.getName()));
int len;
FileInputStream in = new FileInputStream(srcFile);
while ((len = in.read(buf)) != -1){
zos.write(buf, 0, len);
}
zos.closeEntry();
in.close();
}
long end = System.currentTimeMillis();
System.out.println("压缩完成,耗时:" + (end - start) +" ms");
} catch (Exception e) {
throw new RuntimeException("zip error from ZipUtils",e);
}finally{
if(zos != null){
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 递归压缩方法
* @param sourceFile 源文件
* @param zos zip输出流
* @param name 压缩后的名称
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws Exception
*/
private static void compress(File sourceFile, ZipOutputStream zos, String name,
boolean KeepDirStructure) throws Exception{
byte[] buf = new byte[BUFFER_SIZE];
if(sourceFile.isFile()){
// 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
zos.putNextEntry(new ZipEntry(name));
// copy文件到zip输出流中
int len;
FileInputStream in = new FileInputStream(sourceFile);
while ((len = in.read(buf)) != -1){
zos.write(buf, 0, len);
}
// Complete the entry
zos.closeEntry();
in.close();
} else {
File[] listFiles = sourceFile.listFiles();
if(listFiles == null || listFiles.length == 0){
// 需要保留原来的文件结构时,需要对空文件夹进行处理
if(KeepDirStructure){
// 空文件夹的处理
zos.putNextEntry(new ZipEntry(name + "/"));
// 没有文件,不需要文件的copy
zos.closeEntry();
}
}else {
for (File file : listFiles) {
// 判断是否需要保留原来的文件结构
if (KeepDirStructure) {
// 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
compress(file, zos, name + "/" + file.getName(),KeepDirStructure);
} else {
compress(file, zos, file.getName(),KeepDirStructure);
}
}
}
}
}
public static void main(String[] args) throws Exception {
/** 测试压缩方法1 */
// FileOutputStream fos1 = new FileOutputStream(new File("c:/mytest01.zip"));
//
// ZipUtils.toZip("D:/log", fos1,true);
/** 测试压缩方法2 */
List<File> fileList = new ArrayList<>();
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\index.html"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\overview.html"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\reportng.css"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\reportng.js"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\suite1_test1_results.html"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\suites.html"));
FileOutputStream fos2 = new FileOutputStream(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\mytest02.zip"));
ZipUtils.toZip(fileList, fos2);
}
public static boolean ZipTestResult(){
List<File> fileList = new ArrayList<>();
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\index.html"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\overview.html"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\reportng.css"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\reportng.js"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\suite1_test1_results.html"));
fileList.add(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\suites.html"));
FileOutputStream fos2=null;
try {
fos2 = new FileOutputStream(new File("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\测试报告详细资料.zip"));
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
ZipUtils.toZip(fileList, fos2);
return true;
}
}
#
#Thu Oct 11 15:15:25 CST 2018
Running_xyzbteacher_password=lqd45xvdfj
Not_edited_xyzbhost_password=abavynqvtr
Running_xyzbassistant_password=vpwrb89wce
Running_xyzbroom_nums=201810110031
Invalid_xyzbstudent_password=wdg7yedjfm
Finished_xyzbroom_nums=201810110032
Enterprise_users=ys557320181011151500
Invalid_xyzbroom_names=ys614058
Finished_xyzbhost_password=nqdv4exoh0
Finished_xyzbteacher_password=rvax9gjxu4
Not_edited_xyzbassistant_password=4zp4zq76h9
Finished_xyzbid=514
Running_xyzbstudent_password=je0g5jy0fd
Business_Administrator=ys822420181011151501
Not_edited_xyzbroom_names=ys733435
Running_xyzbid=513
Not_edited_xyzbid=516
Invalid_xyzbassistant_password=71lkv08wtn
Not_started_xyzbteacher_password=lel9joq2hd
Finished_xyzbstudent_password=byz89wd2cl
Not_edited_xyzbroom_nums=201810110034
Finished_xyzbassistant_password=b9ylk7zncn
Running_xyzbroom_names=ys747215
Not_started_xyzbhost_password=mxo9eml3fe
Not_started_xyzbassistant_password=pwy53bo4c0
Invalid_xyzbhost_password=6plko1n2ty
Invalid_xyzbroom_nums=201810110033
Not_started_xyzbroom_nums=201810110030
Not_started_xyzbstudent_password=2x01j74yfw
Finished_xyzbroom_names=ys299821
Invalid_xyzbid=515
Not_edited_xyzbteacher_password=8nzbxqvvhl
Running_xyzbhost_password=wwox6o0oi4
Invalid_xyzbteacher_password=o5k7nqqpcv
Not_started_xyzbid=512
Not_started_xyzbroom_names=ys707613
Not_edited_xyzbstudent_password=bvavxrgruq
xls=DataAll.xls
sheet=TestCase2
mysql_local_Online=Online
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment