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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

小强找BUG   2021-04-21 我要评论

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

一般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

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们