自动化实施总结(三)----数据驱动实现
上一篇 /
下一篇 2013-08-02 14:12:57
/ 个人分类:测试总结
本文原始资料和代码来源:郑鸿志的博客
http://www.zhenghongzhi.cn/post/54.html
使用到里面的一个ExcelDataProvider类,但是需要注意的是这个类中的public Object[] next() {}这个方法有一个小缺陷。
/**
* 取下一条数据
*/
public Object[] next() {
Map<String, ArrayList<String>> s = new LinkedHashMap<String, ArrayList<String>>();
boolean ThisIsRange = false;
if (this.getSomeRows) {
this.curlogicRowNo = this.rowidlist.get(0);
this.rowidlist.remove(0);
}
int[] curPhysicalRow = this.logicRows.get(this.curlogicRowNo);
ThisIsRange = (curPhysicalRow[1] - curPhysicalRow[0]) > 0;
for (int i = 0; i < this.columnNum; i++) {
ArrayList<String> temp = new ArrayList<String>();
if (ThisIsRange) {
if (i == 0) {
temp.add(sheet.getRow(curPhysicalRow[0])[i].getContents()
.toString());
} else {
for (int j = curPhysicalRow[0]; j <= curPhysicalRow[1]; j++) {
temp.add(sheet.getRow(j)[i].getContents().toString());
}
}
} else {
if(i>=sheet.getRow(curPhysicalRow[0]).length){
break;
}else{
temp.add(sheet.getRow(curPhysicalRow[0])[i].getContents()==null?"":sheet.getRow(curPhysicalRow[0])[i].getContents()
.toString());
}
}
s.put(this.columnnName[i], temp);
}
Object r[] = new Object[1];
r[0] = s;
this.curlogicRowNo++;
return r;
}
需要按上面修改下,否则如果你的Excel中某一数据列中的值不足时会引起越界异常出现。
以下是使用方法:
//数据池读取
@DataProvider(name = "dataFortestMethod")
public Iterator<Object[]> dataFortestMethod(Method method)
throws IOException, BiffException {
return (Iterator<Object[]>) new ExcelDataProvider(
"./res/parameters.xls", this.getClass().getSimpleName(),
method.getName());
}
//依赖数据提供者
public void
test(Map<String, ArrayList<String>> data) {
driver.get(config.getValue("config.LoginUKURL"));
lc = new Login(data.get("username").get(0).toString(), data
.get("password").get(0).toString(), data.get("status").get(0)
.toString(), true);
assertEquals(driver.getTitle(),
Init.properties.getValue("xxxx"));
home.loginOut.click();
}
相关阅读:
- 数据驱动 (xiong226434, 2007-12-17)
- 自动化测试培训(QTP)(地点:上海) (StudyTech, 2008-5-13)
- 数据驱动加一个简单架构 (limenglei321, 2008-10-30)
- 自动化测试的数据框架 (丛林猎手, 2009-9-03)
- 关于数据驱动和关键字驱动的理解整理 (51testing, 2009-10-23)
- 数据驱动测试 (fishy, 2010-3-24)
- 基于数据驱动的软件自动化测试框架 (fishy, 2010-6-01)
- 功能自动化测试之三层架构 (zzzmmmkkk, 2011-12-25)
- 自动化测试脚本设计 (yubiao584521, 2012-9-07)
- TestNg dataProvider数据提供的两种方法实现 (herryshell, 2013-1-15)
收藏
举报
TAG:
dataProvider
数据驱动