您的位置:首页技术文章
文章详情页

Java跨session实现token接口测试过程图解

【字号: 日期:2022-09-03 11:48:25浏览:40作者:猪猪

这套框架的报告是自己封装的

一般token会在登录接口返回结果中呈现,从代码层面获取token的方式有很多种,我是使用jsonpath这个json路径语言去匹配token所在路径的key值

Java跨session实现token接口测试过程图解

Java跨session实现token接口测试过程图解

没有使用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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持好吧啦网。

标签: Java
相关文章: