SoapUI Groovy读取Excel + 数据给REST API + Assert Json
2016-11-17 20:11
721 查看
目录:
前言
SoapUI 设置REST Rquest请求
Groovy 读取Excel传给TestCase设置的Properties
Script Assertion解析Json
总结
一. 前言
学习groovy语言:
精通 Groovy
学习SoapUI使用:
SoapUI 测试REST API(接口测试)
手把手教你接口自动化测试 – SoapUI & Groovy
二. SoapUI 设置REST Rquest请求
请求接口:
https://sh-market.ruifusoft.com/app/v1/quote/user/query/stockdetail?marketcode=hk&stockcode=00001&graph_tab_index=0&k_not_refresh=0&stock_type=010104&request_id=1478768235224
TestCase设置Properties:
项目结构:
设置REST Rquest请求:
三. Groovy 读取Excel传给TestCase设置的Properties
Excel文档:百度网盘
Groovy脚本:
四. Script Assertion解析Json
Script Assertion:
如下图:
五. 总结
SoapUI执行http请求达到200以上就导致客户端很卡,查下CPU使用情况,居高不下80%,只能命令行执行命令,不会导致客户端卡顿,SoapUI命令行方式运行
相对比Python而言,SoapUI实在不行,建议大家还是自己用Python写,百度网盘中有Python版本,可以参考一下 百度网盘
欢迎加QQ群 -> 阳台测试 -> 239547991(群号)
前言
SoapUI 设置REST Rquest请求
Groovy 读取Excel传给TestCase设置的Properties
Script Assertion解析Json
总结
一. 前言
学习groovy语言:
精通 Groovy
学习SoapUI使用:
SoapUI 测试REST API(接口测试)
手把手教你接口自动化测试 – SoapUI & Groovy
二. SoapUI 设置REST Rquest请求
请求接口:
https://sh-market.ruifusoft.com/app/v1/quote/user/query/stockdetail?marketcode=hk&stockcode=00001&graph_tab_index=0&k_not_refresh=0&stock_type=010104&request_id=1478768235224
TestCase设置Properties:
项目结构:
设置REST Rquest请求:
三. Groovy 读取Excel传给TestCase设置的Properties
Excel文档:百度网盘
Groovy脚本:
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; ArrayList result = new ArrayList(); File file = new File("C:/Users/timen.xu/Desktop/SoapUI/List of CAS securities_C.xls"); POIFSFileSystem poifsFileSystem = new POIFSFileSystem(new FileInputStream(file)); HSSFWorkbook hssfWorkbook = new HSSFWorkbook(poifsFileSystem); HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0); for(int i=6;i<=hssfSheet.getLastRowNum();i++) { HSSFRow row = hssfSheet.getRow(i); if(null == row) continue; HSSFCell cell = row.getCell(1); if(null==cell) continue; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC: result.add(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_STRING: result.add(cell.getStringCellValue()); break; case HSSFCell.CELL_TYPE_BOOLEAN: result.add(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_FORMULA: result.add(" "); break; case HSSFCell.CELL_TYPE_BLANK: result.add(" "); break; case HSSFCell.CELL_TYPE_ERROR: result.add(" "); break; default: result.add(" "); break; } } def deal(Result_excel){ if (Integer.valueOf(Result_excel) < 10) { Result_excel = "0000" + Result_excel; }else if (Integer.valueOf(Result_excel) < 100) { Result_excel = "000" + Result_excel; }else if (Integer.valueOf(Result_excel) < 1000) { Result_excel = "00" + Result_excel; }else if (Integer.valueOf(Result_excel) < 10000) { Result_excel = "0" + Result_excel; } return Result_excel; } for (int i = 0; i < result.size(); i++) { testRunner.testCase.setPropertyValue("stock_name", deal(result.get(i).toString().substring(0, result.get(i).toString().length()-2))); testRunner.runTestStepByName("CASRequest"); }
四. Script Assertion解析Json
Script Assertion:
import net.sf.json.JSONSerializer Object responseObj = JSONSerializer.toJSON(messageExchange.responseContent) def data = responseObj.get("data").get("208") assert data == 1 : "错误信息如下 : "
如下图:
五. 总结
SoapUI执行http请求达到200以上就导致客户端很卡,查下CPU使用情况,居高不下80%,只能命令行执行命令,不会导致客户端卡顿,SoapUI命令行方式运行
相对比Python而言,SoapUI实在不行,建议大家还是自己用Python写,百度网盘中有Python版本,可以参考一下 百度网盘
欢迎加QQ群 -> 阳台测试 -> 239547991(群号)
相关文章推荐
- 用JSON-server模拟REST API(二) 动态数据
- FLASK (CURRENCY)汇率换算api JSON数据读取显示实现
- RESTEasy通过ApacheAPI或JavaAPI进行TEXT、XML、JSON数据交换
- Httpclient 请求带Authorization(授权)的REST API 返回JSON数据
- Using JAX-RS (Jersey) to build a JPA/JAXB-backed JSON REST API
- Using JAX-RS (Jersey) to build a JPA/JAXB-backed JSON REST API
- 使用Ext.Extend:使用Ext的JsonReader读取本地数据实现grid分页
- 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 上接稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 提供JSON REST API的国内天气预报
- 稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- Ext读取Json数据
- java读取json数据方法
- Js循环读取JSON数据
- ExtJs读取Json数据中类型为DateTime的数据
- Grid读取json数据
- silverlight动态读取txt文件/解析json数据/调用wcf示例
- C#中读取json数据。
- Windows Mobile 6.5 Widget - 读取JSON数据-转
- jofc2 API生成json数据