• 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>

     
  • 相关阅读:
    SDWebImage 原理及使用问题
    iOS沙盒目录
    java基础知识积累总结
    切片原型[start:stop:step]
    select嵌套问题
    Numpy:字符串转为数值型、日期型;日期型转为数值型
    数据标准化处理(简单整理)
    Numpy:自定义复合数据类型
    Numpy:数组创建 numpy.arrray() , numpy.arange()、np.linspace ()、数组基本属性
    Numpy:使用索引、切片提取一维数组、多维数组内数据
  • 原文地址:https://www.cnblogs.com/zgq123456/p/12614451.html
Copyright © 2020-2023  润新知