溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Java跨session怎么實(shí)現(xiàn)token接口測試

發(fā)布時間:2021-03-11 16:51:03 來源:億速云 閱讀:163 作者:TREX 欄目:編程語言

本篇內(nèi)容主要講解“Java跨session怎么實(shí)現(xiàn)token接口測試”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Java跨session怎么實(shí)現(xiàn)token接口測試”吧!

這套框架的報(bào)告是自己封裝的

一般token會在登錄接口返回結(jié)果中呈現(xiàn),從代碼層面獲取token的方式有很多種,我是使用jsonpath這個json路徑語言去匹配token所在路徑的key值

Java跨session怎么實(shí)現(xiàn)token接口測試

Java跨session怎么實(shí)現(xiàn)token接口測試

沒有使用testng.xml的情況下調(diào)試testCase,需要設(shè)置一下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>

到此,相信大家對“Java跨session怎么實(shí)現(xiàn)token接口測試”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI