Java跨session實(shí)現(xiàn)token接口測試過程圖解
這套框架的報(bào)告是自己封裝的
一般token會在登錄接口返回結(jié)果中呈現(xiàn),從代碼層面獲取token的方式有很多種,我是使用jsonpath這個(gè)json路徑語言去匹配token所在路徑的key值
沒有使用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>
接口測試神器:https://github.com/wiztools/rest-client
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. XML在語音合成中的應(yīng)用2. HTTP協(xié)議常用的請求頭和響應(yīng)頭響應(yīng)詳解說明(學(xué)習(xí))3. 不要在HTML中濫用div4. ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫金額)的函數(shù)5. .NET Framework各版本(.NET2.0 3.0 3.5 4.0)區(qū)別6. jscript與vbscript 操作XML元素屬性的代碼7. HTML5實(shí)戰(zhàn)與剖析之觸摸事件(touchstart、touchmove和touchend)8. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)9. ASP基礎(chǔ)入門第四篇(腳本變量、函數(shù)、過程和條件語句)10. XML入門的常見問題(三)
