自己写了一个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+QCchbQ6th6J1JIDxgHHKNmdCmOu37vPvxZXt0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8f1omTEG0M3PW6lv0E0Fg0sicpPg1Lfdrhnr0L1fZaW+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+w0pLwriNsPnGuIwaqpYnXl6fpH3+HSBA413z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aGBLuS9h84lxHJGw5ghWkTANS5gNNG0PCfQmbz5/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();
}
}

testNg自动化,读取excel的数据的更多相关文章

  1. 上传读取Excel文件数据

    /// <summary> /// 上传读取Excel文件数据 /// 来自http://www.cnblogs.com/cielwater /// </summary> // ...

  2. VC6.0读取Excel文件数据

    啰嗦一下:本人所在公司从事碟式斯特林太阳能发电设备的研发与销售.单台设备图如下: 工作原理如下:整个设备大致可分为五个部分, 1.服务器,负责气象.发电等数据存取,电.网连接等处理: 2.气象站,通过 ...

  3. 利用PHPExcel读取Excel的数据和导出数据到Excel

    PHPExcel是一个PHP类库,用来帮助我们简单.高效实现从Excel读取Excel的数据和导出数据到Excel.也是我们日常开发中,经常会遇到的使用场景.比如有个客户信息表,要批量导出发给同事,我 ...

  4. C#读取Excel的数据,并且以混合模式读取,防止数据类型变更

    /// <summary> /// Read Excel to DataSet /// </summary> /// <param name="filename ...

  5. phpexcel如何读取excel的数据和如何导出数据到excel

    phpexcel如何读取excel的数据和如何导出数据到excel 一.总结 一句话总结:去官网看参考手册和api,或者找中文的博客或者参考手册 1.phpexcel插件如何下载? 其实这些插件不仅可 ...

  6. 项目一:第四天 1、快递员的条件分页查询-noSession,条件查询 2、快递员删除(逻辑删除) 3、基于Apache POI实现批量导入区域数据 a)Jquery OCUpload上传文件插件使用 b)Apache POI读取excel文件数据

    1. 快递员的条件分页查询-noSession,条件查询 2. 快递员删除(逻辑删除) 3. 基于Apache POI实现批量导入区域数据 a) Jquery OCUpload上传文件插件使用 b) ...

  7. 利用 pandas库读取excel表格数据

    利用 pandas库读取excel表格数据 初入IT行业,愿与大家一起学习,共同进步,有问题请指出!! 还在为数据读取而头疼呢,请看下方简洁介绍: 数据来源为国家统计局网站下载: 具体方法 代码: i ...

  8. java后台读取excel模板数据

    /** * 读取EXCEL模板数据 * * @param excelFilePath excel文件路径 * @param dataRowNum 开始读取数据的行数 * @param keyRowNu ...

  9. python读取excel所有数据(cmd界面)

    python读取excel所有数据(cmd界面) cmd界面显示excel数据 代码 import xlrd import os from prettytable import PrettyTable ...

  10. go读取excel表格数据

    go读取excel表格数据 使用工具 github.com/Luxurioust/excelize 百度到的都是使用这个 实际上已经改名了 github.com/360EntSecGroup-Skyl ...

随机推荐

  1. Unity3d 实时折射和反射

    这里只是张贴在实时折射和脚本反思shader, 大约NGUI第一部分请下载. 这个版本的主要缺点是折射平面部Layer必须是water层.假设有专家谁可以摆脱这一个.请记得把代码回该条,谢谢! Wat ...

  2. .NET应用架构设计—再次了解分层架构(现代企业应用分层架构核心设计元素)

    阅读文件夹: 1.背景介绍 2.简要回想下传统三层架构 3.企业级应用分层架构(现代分层架构的基本演变过程) 3.1.服务层中应用契约式设计来解决动态条件不匹配错误(通过契约式设计模式来将问题在线下暴 ...

  3. mysql压力测试

    1.采用 mysqlslap  压力测试 mysqlslap  --defaults-file=/etc/my.cnf --concurrency=200 --iterations=1 --numbe ...

  4. [git] fatal: This operation must be run in a work tree

    正在使用git  init --bare 它的成立裸仓库后,,正在使用git 其他命令将出现fatal:This operation must be run in a work tree 问题,途径: ...

  5. 前端插件@user

    分享一个 @user 前端插件   开源地址:https://github.com/yuezhongxin/Mention.js 插件效果:类似于微博或 github 中 @user 列表效果. 这是 ...

  6. Eclipse 4.4.2 取消空格键代码上屏

    基本是照这个站点来的: 点击打开链接 可是问题不止这些!! 从网上下了SDK, 然后打开之后首先发现没有plugins窗体, 好吧, 先通过Help -> Install New Softwar ...

  7. php_DWZ-JUI中碰到的问题解决方法详解(thinkphp+dwz)

    原文:php_DWZ-JUI中碰到的问题解决方法详解(thinkphp+dwz) 折腾了两天,dwz删除后,数据不能自动刷新,解决方案,直接看图  . 1. 删除.修改状态后无法刷新记录: 在dwz. ...

  8. 打造简易可扩展的jQuery/CSS3 Tab菜单

    原文:打造简易可扩展的jQuery/CSS3 Tab菜单 今天我们利用jQuery和CSS3来打造一款简易而且扩展性强的Tab菜单,这款Tab菜单在切换时也有滑块的效果,先来看看效果图: 由与Tab菜 ...

  9. Atitit.软体guibuttonand面板---通信子系统(范围)-- github 采用....

    Atitit.软体guibuttonand面板---通讯子系统(区)-- github 的使用.... 1. 1.注冊账户以及创建仓库 1 2. 二.在GitHub中创建项目(create a new ...

  10. [ACM] POJ 3061 Subsequence (仿真足)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8403   Accepted: 3264 Descr ...