当前位置: 首页 > news >正文

浙江网站建设今日要闻新闻

浙江网站建设,今日要闻新闻,抚顺网站建设推荐,杭州公布疫情流调情况一、创建一个apicases.xlsx放入到eclipse的resource里面&#xff0c;然后refresh刷新一下 二、在pom.xml文件中加入poi和testng的mvn repository、然后在eclipse的对应目录下放入features和plugins&#xff0c;重启eclipse就可以看到testNG了 <!--poi excel解析 --><d…

一、创建一个apicases.xlsx放入到eclipse的resource里面,然后refresh刷新一下

二、在pom.xml文件中加入poi和testng的mvn repository、然后在eclipse的对应目录下放入features和plugins,重启eclipse就可以看到testNG了

        <!--poi excel解析 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.15</version></dependency><!-- https://mvnrepository.com/artifact/org.testng/testng --><dependency><groupId>org.testng</groupId><artifactId>testng</artifactId><version>6.9.8</version><scope>test</scope></dependency>

三、封装一个读取Excel表格的工具类

package com.duoceshi.test;import java.io.InputStream;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;;public class ExcelUtil1 {public static Object[][] readExcel1(String excelPath) throws Exception {InputStream is = null;Workbook workbook = null;try {is = ExcelUtil1.class.getResourceAsStream(excelPath);workbook = WorkbookFactory.create(is);Sheet sheet = workbook.getSheetAt(0);  //获取到具体的sheet//通过sheet获取行数int lastRowNum = sheet.getLastRowNum();Object[][] allData = new Object[lastRowNum][];  //创建二维数组存Excel表格数据System.out.println(lastRowNum);for (int i = 1; i <= lastRowNum; i++) {Row row = sheet.getRow(i);int lastColumn = row.getLastCellNum();Object[] objects = new Object[lastColumn];for (int j = 0; j < lastColumn; j++) {Cell cell = row.getCell(j, MissingCellPolicy.CREATE_NULL_AS_BLANK);cell.setCellType(CellType.STRING);  //把cell当成字符串处理String value = cell.getStringCellValue();System.out.println(value);objects[j] = value;}allData[i-1] = objects;}return allData;} catch (Exception e) {e.printStackTrace();} finally {is.close();workbook.close();}return null;}public static void main(String[] args) throws Exception {readExcel1("/apicases.xlsx");}}

四、通过testng创建一个testng类,引入@DataProvider数据提供者

package com.duoceshi.test;import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;import com.alibaba.fastjson.JSON;/*** 读取Excel表格数据 做数据驱动* * @author 多测师王sir**/
public class LoginTest1 {@DataProviderpublic Object[][] dp() throws Exception {Object[][] allData = ExcelUtil1.readExcel1("/apicases.xlsx");for (int i = 0; i < allData.length; i++) {Object[] objects = allData[i];for (int j = 0; j < objects.length; j++) {Object object = objects[j];System.out.println(object);}}return allData;}@SuppressWarnings("unchecked")@Test(dataProvider = "dp")public void loginTest(String url, String requestBody, String result) throws Exception {List<NameValuePair> allData = new ArrayList<NameValuePair>();LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();map = JSON.parseObject(requestBody, map.getClass());  //把字符串转换为map类型Set<String> ketSet = map.keySet();for (String key : ketSet) {String value =  map.get(key);allData.add(new BasicNameValuePair(key, value));}String requestBodyStr = URLEncodedUtils.format(allData, "utf-8");String baseUrl = url + "?" + requestBodyStr;CloseableHttpClient client =  HttpClients.createDefault();HttpPost httpPost = new HttpPost(baseUrl);CloseableHttpResponse reponseStr = client.execute(httpPost);HttpEntity httpEntity =  reponseStr.getEntity();String responseEntity = EntityUtils.toString(httpEntity);//对响应文本进行断言Assert.assertTrue(responseEntity.contains(result));System.out.println(responseEntity);}
}

五、运行输出结果:

{"code":"200","msg":"登录成功!","model":{}}
{"code":"400","msg":"登录密码不正确!","model":{}}

http://www.tj-hxxt.cn/news/119783.html

相关文章:

  • 网站优化插件谷歌香港google搜索引擎入口
  • 内部网站如何做创意营销新点子
  • 动态网站开发主流软件常见的搜索引擎有哪些?
  • 网站注销主体注销放心网站推广优化咨询
  • 怎样做网站表白网站备案是什么意思
  • 做一个招聘信息的网站 用什么做网站的软件广告引流推广平台
  • 教育网站 模板网络推广平台有哪些?
  • 凤台县美丽乡村建设网站在线客服系统平台有哪些
  • 江门小程序制作百度网站快速优化
  • 门户网站建设管理情况自查报告seo价格查询公司
  • 竖导航网站2021年十大热点事件
  • 桐城市住房与建设网站惠州网站推广排名
  • 松江做移动网站设计注册网站的免费网址
  • 朔州做网站的公司网络推广员怎么做
  • 企业网站开发报价表北京云无限优化
  • 商务网站开发课程体会营销网络营销
  • 惠州seo建站免费发布软文广告推广平台
  • 网站上的办公网站怎么做新东方烹饪学校学费一年多少钱
  • 接私活做网站要不要签合同百度链接收录提交入口
  • php网站开发实例教程传智网站关键词快速排名软件
  • 温州网站建设推广百度学术论文官网入口
  • 怎么让网站绑定域名访问哪些平台可以免费推广
  • 网站建设综合训练长沙网络营销推广公司
  • 广州十大室内设计公司排名seo算法是什么
  • 台州做网站建设网站seo关键词优化排名
  • 定制家具价格seo关键词优化服务
  • 襄阳做网站的独立站建站平台有哪些
  • 青海营销网站建设服务关键字搜索引擎
  • 企业网站怎么做百度怎么建免费网站
  • 做团购的家居网站有哪些软文投放平台有哪些?