Java跨session實(shí)現(xiàn)token接口測(cè)試過(guò)程圖解
這套框架的報(bào)告是自己封裝的
一般token會(huì)在登錄接口返回結(jié)果中呈現(xiàn),從代碼層面獲取token的方式有很多種,我是使用jsonpath這個(gè)json路徑語(yǔ)言去匹配token所在路徑的key值


沒(méi)有使用testng.xml的情況下調(diào)試testCase,需要設(shè)置一下dependsOnMethods,否則token將無(wú)法傳遞給其他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>
接口測(cè)試神器:https://github.com/wiztools/rest-client
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
@JsonFormat處理LocalDateTime失效的問(wèn)題
這篇文章主要介紹了關(guān)于@JsonFormat處理LocalDateTime失效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
Netty分布式NioEventLoop任務(wù)隊(duì)列執(zhí)行源碼分析
這篇文章主要為大家介紹了Netty分布式NioEventLoop任務(wù)隊(duì)列執(zhí)行源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03
HttpClient的RedirectStrategy重定向處理核心機(jī)制
這篇文章主要為大家介紹了HttpClient的RedirectStrategy重定向處理核心機(jī)制源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10

