zoukankan      html  css  js  c++  java
  • java 跨session token接口测试

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

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

    按 Ctrl+C 复制代码
    按 Ctrl+C 复制代码

    没有使用testng.xml的情况下调试testCase,需要设置一下dependsOnMethods,否则token将无法传递给其他test步骤

    附上TestUtil.getToken()方法:

    复制代码
     1 //获取返回的token ,使用JsonPath获取json路径
     2     public static HashMap<String,String> getToken(CloseableHttpResponse closeableHttpResponse,String jsonPath) throws Exception{
     3         HashMap<String,String> responseToken = new HashMap<String, String>();
     4         String responseString = EntityUtils.toString( closeableHttpResponse.getEntity(),"UTF-8");
     5         ReadContext ctx = JsonPath.parse(responseString);
     6         String Token = ctx.read(jsonPath); //"$.EFPV3AuthenticationResult.Token"
     7         if(null == Token||"".equals(Token)){
     8             new Exception("token不存在");
     9         }
    10  
    11         responseToken.put("x-ba-token",Token);
    12         return responseToken;
    13     }
    复制代码

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

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

    按 Ctrl+C 复制代码
    按 Ctrl+C 复制代码

    没有使用testng.xml的情况下调试testCase,需要设置一下dependsOnMethods,否则token将无法传递给其他test步骤

    附上TestUtil.getToken()方法:

    复制代码
     1 //获取返回的token ,使用JsonPath获取json路径
     2     public static HashMap<String,String> getToken(CloseableHttpResponse closeableHttpResponse,String jsonPath) throws Exception{
     3         HashMap<String,String> responseToken = new HashMap<String, String>();
     4         String responseString = EntityUtils.toString( closeableHttpResponse.getEntity(),"UTF-8");
     5         ReadContext ctx = JsonPath.parse(responseString);
     6         String Token = ctx.read(jsonPath); //"$.EFPV3AuthenticationResult.Token"
     7         if(null == Token||"".equals(Token)){
     8             new Exception("token不存在");
     9         }
    10  
    11         responseToken.put("x-ba-token",Token);
    12         return responseToken;
    13     }
    复制代码
     
    来源:清风软件测试
     
     
    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>

     
  • 相关阅读:
    在 easyui中获取form表单中所有提交的数据 拼接到table列表中
    easyui中清空table列表中数据
    easyui中加载table列表数据 第一次有数据第二次没有数据问题
    jsp中将一个jsp引入另一个jsp指定位置
    maven项目修改名称后,打包名称和现在名称不一致
    动态sql
    日期转化类 ,日期格式处理
    easyui中权限分配和添加 前后端代码
    ubuntu14.04下播放器SMplayer的安装
    C++的 new 和 detele
  • 原文地址:https://www.cnblogs.com/zgq123456/p/12614451.html
Copyright © 2011-2022 走看看