7.测试用例参数用json格式一行存储,通过fastson解析后调用
</dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency>
用例文件改造
代码改造
package com.alibaba.autotest_v2; import java.io.IOException; import java.util.Map; import java.util.Set; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import com.alibaba.fastjson.JSONObject; import com.alibaba.utils.ExcelUtil2; import com.alibaba.utils.HttpUtils; import com.alibaba.utils.ReadCasePath; public class SearchStarsv5 { @Test(dataProvider = "datas") public void test1(String parameters) throws Exception { String url = "http://apis.juhe.cn/fapig/zodiac/query"; Map<String, String> params = (Map) JSONObject.parse(parameters); System.out.println("通过jsonobject 转化后输出的变量params是" + params); String res = HttpUtils.dopost(url, params); System.out.println(res); } @DataProvider public Object[][] datas() throws EncryptedDocumentException, InvalidFormatException, IOException { String excellpath = ReadCasePath.readExcellPath(); int[] rows = { 2, 3 }; int[] cells = { 5 }; Object[][] datas = ExcelUtil2.datas(excellpath, rows, cells); return datas; }; public static void main(String[] args) { String paremters = "{\"key\": \"6d43e98f74c283db936d0e3b742ebde0\",\"keyword\": \"兔\"}"; Map<String, String> params = (Map<String, String>) JSONObject.parse(paremters); Set<String> keys = params.keySet(); for (String key : keys) { System.out.println("KEY=" + key + "," + "value=" + params.get(key)); } System.out.println(params); } }
jiapengchu
posted on 2022-03-15 10:39 jiapengchu 阅读(71) 评论(0) 编辑 收藏 举报