本文是一个完整的使用maven配置的selenium webdriver工程,主要实现了自动化测试发送邮件的功能。
第一部分:参数化
package com.cplatform.training.parameter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ParameterByExcel {
//创建getParameterFromExcel方法,根据行和列获取excel中表格的内容
public String getParameterFromExcel(File excelFile,int rowNum,int colNum) {
//定义String对象,用于存取读取到的excel表格中的内容,便于返回
String str="";
//定义一个工作簿
Workbook rwb = null;
//定义一个Cell
Cell cell = null;
// 创建输入流
try {
InputStream stream = new FileInputStream(excelFile);
// 获取Excel文件对象
rwb = Workbook.getWorkbook(stream);
// 获取文件的指定工作表 默认的第一个
Sheet sheet = rwb.getSheet(0);
//通过行和列定位需要读取的单元格,并且赋值给str
cell = sheet.getCell(colNum,rowNum);
str = cell.getContents();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("~~~FileNotFoundException~~~");
}catch (BiffException e) {
// TODO Auto-generated catch block
System.out.println("~~~BiffException~~~");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("~~~IOException~~~");
}
return str;
}
}
|