Commit c3ea6688 by shuai

testGitLab20181015

parent 2e4bac5f
......@@ -63,13 +63,14 @@
<target name="testoutput" depends="runtest">
<!--
<java classname="com.offcn.TestUnti.Mail" classpath="${basedir}/bin">
<sysproperty key="file.encoding" value="UTF-8" />
<classpath>
<pathelement location="lib/javax.mail.jar" />
</classpath>
</java>
<!--
ui自动化测试报告部分
<xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html ">
......
package com.offcn.TestUnti;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.testng.annotations.Test;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.StringTokenizer;
public class Mail {
public static void main(String[] args) {
try {
Mail.POP3();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test
public static void mailToAll(){
try {
Mail.POP3();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 发件人的 邮箱 和 密码(替换为自己的邮箱和密码)
public static String myEmailAccount = "53055975@qq.com";
public static String myEmailPassword = "mpphitfeaxcqcbdg";
// 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般格式为: smtp.xxx.com
// 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
public static String myEmailSMTPHost = "smtp.qq.com";
// 收件人邮箱(替换为自己知道的有效邮箱)
// public static String receiveMailAccount = "liyongyu@offcn.com";//rmscrum.list@finupgroup.com
public static String receiveMailAccount = "yaoshuai@offcn.com";//rmscrum.list@finupgroup.com
public static void POP3() throws Exception {
// 1. 创建参数配置, 用于连接邮件服务器的参数配置
Properties props = new Properties(); // 参数配置
props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
props.setProperty("mail.host", myEmailSMTPHost); // 发件人的邮箱的 SMTP 服务器地址
props.setProperty("mail.smtp.auth", "true"); // 请求认证,参数名称与具体实现有关
props.setProperty("mail.stmp.port", "465"); // 端口
// 2. 根据配置创建会话对象, 用于和邮件服务器交互
Session session = Session.getDefaultInstance(props);
session.setDebug(true); // 设置为debug模式, 可以查看详细的发送 log
// 3. 创建一封邮件
MimeMessage message = createMimeMessage(session, myEmailAccount, receiveMailAccount);
// 4. 根据 Session 获取邮件传输对象
Transport transport = session.getTransport();
// 5. 使用 邮箱账号 和 密码 连接邮件服务器
// 这里认证的邮箱必须与 message 中的发件人邮箱一致,否则报错
transport.connect(myEmailAccount, myEmailPassword);
// 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
transport.sendMessage(message, message.getAllRecipients());
// 7. 关闭连接
transport.close();
}
/**
* 创建一封只包含文本的简单邮件
*
* @param session 和服务器交互的会话
* @param sendMail 发件人邮箱
* @param receiveMail 收件人邮箱
* @return
* @throws Exception
*/
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail) throws Exception {
// 1. 创建一封邮件
MimeMessage message = new MimeMessage(session);
// 2. From: 发件人
message.setFrom(new InternetAddress(sendMail, "定时任务-接口自动化测试报告", "UTF-8"));
// 3. To: 收件人(可以增加多个收件人、抄送、密送)
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "", "UTF-8"));
String overview=ReadHtml.readFile_("overview.html");
// System.out.println(overview);
String TestTitle="";
String TestResule="";
boolean isTrue=overview.contains("100.00%");
int start=overview.indexOf("<td class=\"passRate\">");
System.out.println(start);
String Percentage=overview.substring(start+22, start+41);
System.out.println(Percentage);
if(isTrue){
message.setRecipients(MimeMessage.RecipientType.CC, parseAddress("onlyTest"));
}else{
message.setRecipients(MimeMessage.RecipientType.CC, parseAddress("all"));
}
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("wufeifei66504@offcn.com", "", "UTF-8"));
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("liyongyu@offcn.com", "", "UTF-8"));
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("lihong60540@offcn.com", "", "UTF-8"));
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("yangfan60144@offcn.com", "", "UTF-8"));
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("lifeifei58407@offcn.com", "", "UTF-8"));
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("tangqingsong@offcn.com", "", "UTF-8"));
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("zhouyeheng@offcn.com", "", "UTF-8"));
// message.setRecipient(MimeMessage.RecipientType.CC, new InternetAddress("zhanghua54164@offcn.com", "", "UTF-8"));
// 4. Subject: 邮件主题
Date date=new Date();
String time=new SimpleDateFormat("yyyyMMdd").format(date);
message.setSubject("小雨直播自动化测试报告-"+time, "UTF-8");
/*
* 下面是邮件内容的创建:
*/
// message.setContent("定时任务--小雨直播接口自动化测试", "text/html;charset=UTF-8");
// 5. 创建图片"节点"
// MimeBodyPart image = new MimeBodyPart();
// // 读取本地文件
// DataHandler dh = new DataHandler(new FileDataSource("src\\mailTestPic.png"));
// // 将图片数据添加到"节点"
// image.setDataHandler(dh);
// // 为"节点"设置一个唯一编号(在文本"节点"将引用该ID)
// image.setContentID("mailTestPic");
//
// 6. 创建文本"节点"
MimeBodyPart text = new MimeBodyPart();
// 获取邮件内容原位置
// String overview=ReadHtml.readFile_("overview.html");
//// System.out.println(overview);
//
// String TestTitle="";
// String TestResule="";
//
// boolean isTrue=overview.contains("100.00%");
// int start=overview.indexOf("<td class=\"passRate\">");
// System.out.println(start);
// String Percentage=overview.substring(start+22, start+41);
// System.out.println(Percentage);
// System.out.println("isTrue="+isTrue);
if(isTrue){
TestTitle=" <font size='6' color='#00FF00'>本次测试通过率:"+Percentage+"</font></br></br> ";
}else{
TestTitle=" <font size='6' color='#FF0000'>本次测试通过率:"+Percentage+"</font> </br></br>";
TestResule=ReadHtml.readFile_("suite1_test1_results.html");
}
// 这里添加图片的方式是将整个图片包含到邮件内容中, 实际上也可以以 http 链接的形式添加网络图片+ReadHtml.readFile_("suite1_test1_results.html")
text.setContent(TestTitle+"</br></br>"+ReadHtml.readFile_("overview.html")+"</br></br>"+TestResule, "text/html;charset=UTF-8");
//
// // 7. (文本+图片)设置 文本 和 图片"节点"的关系(将 文本 和 图片"节点"合成一个混合"节点")
// MimeMultipart mm_text_image = new MimeMultipart();
// mm_text_image.addBodyPart(text);
// mm_text_image.addBodyPart(image);
// mm_text_image.setSubType("related"); // 关联关系
//
// // 8. 将 文本+图片 的混合"节点"封装成一个普通"节点"
// // 最终添加到邮件的 Content 是由多个 BodyPart 组成的 Multipart, 所以我们需要的是 BodyPart,
// // 上面的 mailTestPic 并非 BodyPart, 所有要把 mm_text_image 封装成一个 BodyPart
// MimeBodyPart text_image = new MimeBodyPart();
// text_image.setContent(mm_text_image);
MimeBodyPart attachment2 = new MimeBodyPart();
if(ZipUtils.ZipTestResult()){
DataHandler dh2 = new DataHandler(new FileDataSource("F:\\gitCangKu\\Api_auto_test\\test-output\\html\\测试报告详细资料.zip"));
attachment2.setDataHandler(dh2);
attachment2.setFileName("测试报告详细资料.zip");
// // 9. 创建附件"节点"
// MimeBodyPart attachment3 = new MimeBodyPart();
// MimeBodyPart attachment4 = new MimeBodyPart();
// MimeBodyPart attachment5 = new MimeBodyPart();
// MimeBodyPart attachment6 = new MimeBodyPart();
// MimeBodyPart attachment7 = new MimeBodyPart();
// // 读取本地文件
// DataHandler dh2 = new DataHandler(new FileDataSource("test-output\\html\\index.html"));
// DataHandler dh3 = new DataHandler(new FileDataSource("test-output\\html\\overview.html"));
// DataHandler dh4 = new DataHandler(new FileDataSource("test-output\\html\\reportng.css"));
// DataHandler dh5 = new DataHandler(new FileDataSource("test-output\\html\\reportng.js"));
// DataHandler dh6 = new DataHandler(new FileDataSource("test-output\\html\\suite1_test1_results.html"));
// DataHandler dh7 = new DataHandler(new FileDataSource("test-output\\html\\suites.html"));
// // 将附件数据添加到"节点"
// attachment2.setDataHandler(dh2);
// attachment3.setDataHandler(dh3);
// attachment4.setDataHandler(dh4);
// attachment5.setDataHandler(dh5);
// attachment6.setDataHandler(dh6);
// attachment7.setDataHandler(dh7);
// // 设置附件的文件名(需要编码)
// attachment2.setFileName("index.html");
// attachment3.setFileName("overview.html");
// attachment4.setFileName("reportng.css");
// attachment5.setFileName("reportng.js");
// attachment6.setFileName("suite1_test1_results.html");
// attachment7.setFileName("suites.html");
}
// 10. 设置(文本+图片)和 附件 的关系(合成一个大的混合"节点" / Multipart )
MimeMultipart mm = new MimeMultipart();
mm.addBodyPart(text);
mm.addBodyPart(attachment2); // 如果有多个附件,可以创建多个多次添加
// mm.addBodyPart(attachment3); // 如果有多个附件,可以创建多个多次添加
// mm.addBodyPart(attachment4); // 如果有多个附件,可以创建多个多次添加
// mm.addBodyPart(attachment5); // 如果有多个附件,可以创建多个多次添加
// mm.addBodyPart(attachment6); // 如果有多个附件,可以创建多个多次添加
// mm.addBodyPart(attachment7); // 如果有多个附件,可以创建多个多次添加
mm.setSubType("mixed"); // 混合关系
// 11. 设置整个邮件的关系(将最终的混合"节点"作为邮件的内容添加到邮件对象)
message.setContent(mm);
//设置邮件的发送时间,默认立即发送
message.setSentDate(new Date());
return message;
}
public static InternetAddress[] parseAddress(String personnel){
String addr="";
if("all".equals(personnel)){
addr="wufeifei66504@offcn.com;wenshuang@offcn.com;wangzhuang66685@offcn.com;liyongyu@offcn.com;lihong60540@offcn.com;"
+ "yangfan60144@offcn.com;lifeifei58407@offcn.com;tangqingsong@offcn.com;"
+ "zhouyeheng@offcn.com;zhanghua54164@offcn.com";
}else{
addr="wufeifei66504@offcn.com;wenshuang@offcn.com;wangzhuang66685@offcn.com;liyongyu@offcn.com";
}
StringTokenizer token = new StringTokenizer(addr, ";");
InternetAddress[] addrArr = new InternetAddress[token.countTokens()];
int i = 0;
while (token.hasMoreTokens()){
try{
addrArr[i] = new InternetAddress(token.nextToken().toString());
}catch (AddressException e1){
e1.printStackTrace();
return null;
}
i++;
}
return addrArr;
}
}
\ No newline at end of file
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