Java跨session實(shí)現(xiàn)token接口測試過程圖解
這套框架的報(bào)告是自己封裝的
一般token會在登錄接口返回結(jié)果中呈現(xiàn),從代碼層面獲取token的方式有很多種,我是使用jsonpath這個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. SSM框架JSP使用Layui實(shí)現(xiàn)layer彈出層效果2. IntelliJ IDEA導(dǎo)入jar包的方法3. 刪除docker里建立容器的操作方法4. IntelliJ IDEA導(dǎo)出項(xiàng)目的方法5. PHP下對緩沖區(qū)的控制6. 如果你恨一個程序員,忽悠他去做iOS開發(fā)7. 在Django中預(yù)防CSRF攻擊的操作8. java使用xfire搭建webservice服務(wù)的過程詳解9. IDEA調(diào)試源碼小技巧之辨別抽象類或接口多種實(shí)現(xiàn)類的正確路徑10. Jquery使用原生AJAX方法請求數(shù)據(jù)
