Java跨session实现token接口测试过程图解
这套框架的报告是自己封装的
一般token会在登录接口返回结果中呈现,从代码层面获取token的方式有很多种,我是使用jsonpath这个json路径语言去匹配token所在路径的key值
没有使用testng.xml的情况下调试testCase,需要设置一下dependsOnMethods,否则token将无法传递给其他test步骤
附上TestUtil.getToken()方法:
//获取返回的token ,使用JsonPath获取json路径 public static HashMap<String,String> getToken(CloseableHttpResponse closeableHttpResponse,String jsonPath) throws Exception{ HashMap<String,String> responseToken = new HashMap<String, String>(); String responseString = EntityUtils.toString( closeableHttpResponse.getEntity(),'UTF-8'); ReadContext ctx = JsonPath.parse(responseString); String Token = ctx.read(jsonPath); //'$.EFPV3AuthenticationResult.Token' if(null == Token||''.equals(Token)){ new Exception('token不存在'); } responseToken.put('x-ba-token',Token); return responseToken; }
maven地址
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-client --><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-client</artifactId><version>7.6.1</version></dependency>
接口测试神器:https://github.com/wiztools/rest-client
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持好吧啦网。
相关文章:
1. Springboot web项目打包实现过程解析2. 关于springboot 中使用httpclient或RestTemplate做MultipartFile文件跨服务传输的问题3. python 网络编程要点总结4. Python 利用flask搭建一个共享服务器的步骤5. Python Django 后台管理之后台模型属性详解6. ASP.NET Core 5.0中的Host.CreateDefaultBuilder执行过程解析7. 利用php来自动调用不同服务器上的flash8. asp.net core 中的Jwt(Json Web Token)的使用详解9. vue+element+oss实现前端分片上传和断点续传10. 详解CSS伪元素的妙用单标签之美
