testNg自动化,读取excel的数据

时间:2021-08-08 14:43:25

自己写了一个testng执行excel用例的小程序,主要是运行.xlsx的,需要支持xls可以自己扩展,分享一下。下载地址:http://yun.baidu.com/share/link?shareid=3811093173&uk=925574576&third=0

需要引用的jar包有(demo里面也有这些jar包):

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPUAAABUCAIAAADVk+Z5AAAHyUlEQVR4nO2dz0/cRhTH/SfwLxQKZ/4ebv0HkmOU2yJxioii0FCohCJxiBRuYSnqAmlVJHopESEcNumhLL9SIu0uy7LgXcMS94DYuJ434zfj2Wev/T6KLDP7/ObZfv564vGTHf+eQqHgM0y2cHprxvmN33Cn9HB9bmztp9HS7OivM6Orz0dWno0Unw4vTw/vlB6a9c4wCpxoE3usz419vW18vf73tv337cVf3fra7Zel7snPNwfT63NjlJEwOSE5/f7x+9XnI788Gy4+HV6e/o71m+kHpPq9f1J/PFvaP201r7zmlXd9fd286uyfth7PlvZP6pSRMDnBUL8LcmSbbO1Wpl9tHVXdWrPdcjstt9P2vJbrVZvto6o7/Wpra7cSZ09833eciMvVuSfSQGEm2shaxB6DPiOD0do1BsTwqMnyWJHfiyvbr9+Wj2vuWavT7njtjnfbvW53vLOLzknNff22vLiybRYMklBuRdpgXCl8atkwfcJcv7+5cFBOphY2ft85Pqq61Wbn0u1cftPvzmHV/Vy9nFrY0AzeHCv5rU7WoISLjVrdMcZY0G9kfj948qba7Kyu7wyNT7x4uXrWaA2NT7S9bq/lT8n4RDZgEHMFvPurzSL7Av3I4gHDCwm5QX6r9z3YEV8wIWLpt3ju79rFpe/7PxSW6i1vaHyiUW0MjU+02t3e8q7lj3f/SKMU7vWYu78CjKX6MhANwD9DiWglYPAgcGaD0Ol39vJb3Qjmt3gfMAvY2E/eoBt/P3jy5kvDffFy9W400ri6GRqfOL+66bXIxie+pfzGWCK94fMbuaLuTmbJ+R0J3fOTqYWN3959ql149ZZXb13f//PqLa924X2uNhT/v5SNd0NnPfI2LdqI9pF+QCchb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D6D6l+c30DQwzd/E78+gazp7PgrKHuJmAk8f1omTEG0M3PW6lv0E0Fg0sicpPg1Lfdrhnr0L1fZaW+QStj1G9ZGPeCd8j5nTgW9BuZ31a+3xDsS/YWUSgw8G0hcStxw8hIrIxPRD9ihKAZgyGWfov5kVR9g2zpQ0kWMy+1rgR1RwqHYoozBtDpN3F++3KhTXN++8KdipM7DnTj777WN4D5LYYna9EyoNdvjBMGhO75iZXvN4BjUz8qv7X0W5R88AqxYgO2OxCKgBkF5vpNWd9gl7SlS9riyRJ0Rzbx7zekTQvTFk8mMdTvIFzfwKQWFg8my1jQb4ZJLaTjE65vYIghHZ9wfQNDTHL6zfUNTP8h1W+ub2CIoZvf6ev3G8DJQspHy5iH2bZsepbaUeYPuvl5gu83aM3DW0R3Ej6ODaMF3ftVBN9vSHN+y+zj+GEioXs/Nub3G8QV8T4ue1EJ9Aa2gJ5Djc7/UQSg2BfZr0hXmL2I7C4PxNJv8Uz3tb4heP7ERh/Kb7sravCZZEW/QWMxxXMOnX7HyW8fOp1m+a2QZ9lWPiJdtJLJen778r3IOXTj7/j1DRb1G2OjMEa2y2xo9DsypDxA9/zEuL5BHE2CS1GbRakGGx0IsV+FhMt6l5kFWwxswHbZXuQcc/0e3PqGbMDpi4HuGCVe35ANWJu1MNTvIFzfwKSW/wCEsDFoysAHVgAAAABJRU5ErkJggg==" alt="" />

1、读取excel

excel的数据放入List<Map<String, String>>中。这里,不包括excel第一条数据,因为第一条数据要作为map的key值。

excel格式:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA5MAAACiCAIAAABTQw5LAAAbc0lEQVR4nO2dzY7kzFKG65J6VepbAYFAIBAIBOIOWLHou5nFbEZi0xv2B8RBTY8+8SMEQogLmIVZNKfGbWeGI+xwOjLyeRQaVbnS6Zx4I9NvuVxdt78BAAAAAOiB25ev3w7GL//2n0RfgWpp4vXlafr73yISxOvL0+XlRPgGKy0J7zrC5vOW9T9GCIFqaeL15Wn6h98mEgTONV+w0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QNPGkHBfwuYT5zoiYcsRrCBlGpAyH2jaGBLuS9h84lxHJGw5ghWkTANS5gNNG0PCfQmbz5/O9T4D55qbsOUIVpAyDUiZDzRtDAn3JWw+bw/bOvejevOKc+2RsOUIVpAyDUiZDzRtDAn3JWw+ca4jErYcwQpSpgEp84GmjSHhvoTNJ851RMKWI1hByjQgZT7QtDEk3Jew+eQ+1xEJW45gBSnTgJT5QNPGkHBfwubzk3O1XnDFuXZK2HIEK0iZBqTMB5o2hoT7Ejaf3C0wImHLEawgZRqQMh9o2hgS7kvYfOJcRyRsOYIVpEwDUuYDTRtDwn0Jm0+c64iELUewgpRpQMp8oGljSLgvYfPJN7RGJGw5ghWkTANS5gNNG0PCfQmbT379dUTCliNYQco0IGU+0LQxJNyXsPnEuY5I2HIEK0iZBqTMB5o2hoT7Ejaf/wdT/Vkb5BQvQAAAAABJRU5ErkJggg==" alt="" />

package com.milan.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ReadExcel { public static List<Map<String, String>> readXlsx(String fileName) { XSSFWorkbook xssfWorkbook=null;
try {
xssfWorkbook = new XSSFWorkbook(fileName);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 循环工作表Sheet
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
// 循环行Row
XSSFRow rowTitleRow =xssfSheet.getRow(0);
for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
XSSFRow xssfRow = xssfSheet.getRow(rowNum); if (xssfRow == null) {
continue;
}
Map<String, String> map = new HashMap<String, String>();
// 循环列Cell
for (int cellNum = 0; cellNum <rowTitleRow.getLastCellNum(); cellNum++) {
XSSFCell xssfCell = xssfRow.getCell(cellNum);
XSSFCell xssfCellTitleCell = rowTitleRow.getCell(cellNum);
map.put(getValue(xssfCellTitleCell), getValue(xssfCell));
}
list.add(map); }
return list;
}
@SuppressWarnings("static-access")
private static String getValue(XSSFCell xssfCell) {
if (xssfCell ==null){return ""; }
if (xssfCell.getCellType() == xssfCell.CELL_TYPE_BOOLEAN) {
return String.valueOf(xssfCell.getBooleanCellValue());
} else if (xssfCell.getCellType() == xssfCell.CELL_TYPE_NUMERIC) {
return String.valueOf(xssfCell.getNumericCellValue());
} else {
return String.valueOf(xssfCell.getStringCellValue());
}
}
}

2、解析excel的数据

   aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHsAAABKCAIAAAAUg7wgAAACa0lEQVR4nO2Z0U7bMBSG/Uhc7V2GNjENMQ2BmPYSu+jbcMENl7zCpgmVVhUwTUUIwRuEiyOqqMlxjk+dv3b5P/2qGsex3S/BCU5oCJawuH9hkKFxuPFfBEtofn+UXE32FvdLJlfOLy57y0PzZ19C4yjjfz9JaBxl/PqzhMZRxqcHEhpHGb/5Iinc+IcOWx+S1/j8q6Rw4yI9slladOOLQ0lFxgt3PWT89khC4yjjd98kVRivZRKPGv/3XVKF8bUvJUc3/v9YQuMo48sTSUXGq4hu/OFUQuMo449nksKNV3TPHDL+9ENSuPHqoht//imhcZDxq8neKucXl8zYCat3zNPZfGvvt3cRzSeNjwWNo3EaDyGEELrldjZvoVL8xo2FEWi8TbLx8IbWU3evdtp2+0zkMS6b7c/+Rus0nnc8xRkvkNKNd2u2iTTSRKemSCPd8tVm/JC1yt3N+OAHJ9JePMbts4FFcW9TkRLtu7ZrwzqWYSdJz/yskjR0baDGE9N0rsHey9DRo8V4pN84+Z8Ojdeg1kikcbvB9iGOHn1/mkbGvXNmNN67l8Zjxt2/P97mYLXUOpZxFjGPazNau3ytwuD82FseOcTSqTZUyyGD/VrIua6S1LdjrLtBzrXD92kwFdX4dDZnkPFc48RCzlmFWKBxNDSOhsbR0DgaGkdD42gSjK8tI/hWFUjaNb7JmhkRkmeVoKyCEiM0jsZpnLrdeJ5VeMPcBKfxEUe069A4Gv/zOPGhGt/6O5H3Fv6XPxYJswrJAo2joXE0NI6GxtHQOBoaR0PjaGgcDY2joXE0NI6GxtHQOBoaR6P5fAXm8WlLjuDdhgAAAABJRU5ErkJggg==" alt="" />excel中,这个字段的值为y表示需要执行测试用例,如果为其他的,则表示不执行。

字段中{$d}开头的表示用例说明。{$p}开头的,表示用例需要的预置参数。比如QQ好友发送消息,但是发送消息需要先登录,所以这里可以放登录的用户名和密码。

package com.milan.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CaseHelper {
//根据excel的map 转换为数组 第一个为 入参 map 第二个为用例说明,第三个参数为执行用例的预置条件
public static Object[] getObjArrByMap(Map<String,String> caseExcelMap){
Map<String,String> caseParam = new HashMap<String,String>();
Map<String,String> caseDesc = new HashMap<String,String>();
Map<String,String> casePreset =new HashMap<String,String>();
CaseInfo ci = new CaseInfo();
for (String key : caseExcelMap.keySet()) {
if (key.indexOf("{$d}")== 0){
caseDesc.put(key.replace("{$d}", ""), caseExcelMap.get(key));
}
else if(key.indexOf("{$p}") == 0){
casePreset.put(key.replace("{$p}", ""), caseExcelMap.get(key));
}
else {
String strValue = caseExcelMap.get(key);
if (!strValue.equals("")){
caseParam.put(key, strValue);
}
}
}
ci.setCaseDesc(caseDesc);
ci.setCaseParam(caseParam);
ci.setCasePreset(casePreset); return new Object[]{ci};
}
///根据excel获取的list转换为 Object[][]
public static Object[][] getObjArrByList(List<Map<String,String>> caseExcelList){
List<Map<String,String>> caseExcuteList = getExcuteList(caseExcelList);
Object[][] objArray = new Object[caseExcuteList.size()][];
for(int i = 0;i<caseExcuteList.size();i++){
objArray[i]=getObjArrByMap(caseExcuteList.get(i));
}
return objArray; }
///赛选出需要执行的用例
private static List<Map<String,String>> getExcuteList(List<Map<String,String>> caseExcelList){
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
for( Map<String,String> m : caseExcelList){
String str = m.get("{$d}isexcute").trim().toLowerCase();
if (str.equals("y")){
list.add(m);
}
}
return list;
} }

3、用例类

用例类有3个属性,分别是参数,用例说明,预置参数。

package com.milan.utils;

import java.util.Map;

public class CaseInfo {
///{$d}isexcute 为y的时候表示需要执行 //用例参数 在excel中知己以字段名开头
private Map<String,String> caseParam;
//用例说明 在excel中以{$d}开头
private Map<String,String> caseDesc;
//用例预置条件 在excel中以{$p}开头
private Map<String,String> casePreset; public Map<String, String> getCaseParam() {
return caseParam;
}
public void setCaseParam(Map<String, String> caseParam) {
this.caseParam = caseParam;
}
public Map<String, String> getCaseDesc() {
return caseDesc;
}
public void setCaseDesc(Map<String, String> caseDesc) {
this.caseDesc = caseDesc;
}
public Map<String, String> getCasePreset() {
return casePreset;
}
public void setCasePreset(Map<String, String> casePreset) {
this.casePreset = casePreset;
} }

4、运行

package com.milan.test;

import java.io.IOException;
import java.util.List;
import java.util.Map; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import com.milan.utils.CaseHelper;
import com.milan.utils.CaseInfo;
import com.milan.utils.ReadExcel; public class MyTest {
protected String caseExcelPath =System.getProperty("user.dir")+"\\excel\\temp.xlsx"; @DataProvider(name = "dataInfo")
protected Object[][] dataInfo1() throws IOException { Object[][] myObj = null;
List<Map<String, String>> list = ReadExcel.readXlsx(caseExcelPath);
myObj = CaseHelper.getObjArrByList(list);
return myObj;
}
@Test(dataProvider="dataInfo")
public void testByExcel_Body(CaseInfo c) throws IOException{
///获取用例说明
System.out.println(c.getCaseDesc());
///获取用例需要的参数
System.out.println(c.getCaseParam());
//获取执行用例需要的前置条件
System.out.println(c.getCasePreset());
} }

5、输出结果:

{caseExpect=1, isexcute=y, caseDesc=发送消息}
{sendname=发送者名称, send=发送消息}
{login=登录字符串}

读取到excel的值之后,就可以自己加断言,自己去请求数据调方法等等。

testng断言失败,继续执行 http://blog.csdn.net/m1011566442/article/details/52084896

testng代码执行  https://www.cnblogs.com/digod/p/6035177.html

public class Test2 {
public static void main(String[] args) {
//DefaultTest defaultTest = new DefaultTest();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{DefaultTest.class});
testNG.run();
}
}