??????????????
????????????XML????н??й???
??????httpClient????????httpUtils??????
?????????????????????testNg??????????TestNG??????????????xml????????case??
???????????????????????????ReportNG ????????Maven
???????????
??????ù????eclipse??maven
??????????????jar????dom4j??reportng??testng
??????????httpUtils??xmlUtil???????????dom4j????CookieStore?????
?????????????
????1???????

????2?????????????

????3????????????

????4????????????

?????????????
????1?????????

????1.1 ????????XML????н??й???
??????????????????????????????????page??rows??mapRole.xml????????
????<?xml version="1.0" encoding="UTF-8"?>
????<map>
????<bean beanName="GetRole">
????<!--Locator lists -->
????<locator name="page" value="1"></locator>
????<locator name="rows" value="10"></locator>
????</bean>
????</map>
????1.2 ??????xmlUtil??????????XML????????????jar??dom4j
????1.2.1 xmlUtil??readXMLDocument??????????HashMap<String?? String>
????public static HashMap<String?? String>  readXMLDocument(String beanName??String xmlName){
????}
????????xmlName(xml?????????)?? ????beanName(xml????н???????)??
????1.3 ??????CookieUtil?????????CookieStore????cookie
????1.3.1 CookieUtil????setCookieStore??????????CookieStore
????public  CookieStore setCookieStore(HttpResponse httpResponse) {
????}
????1.4 ??httpClient????????httpUtils????????get.post??put??delete????
????1.4.1 httpUtils??post??????????£?
????public CloseableHttpResponse post(String url?? Map<String?? String> params??CloseableHttpClient httpclient??CookieStore cookieStore){
????}
????2?????????
????2.1 ????????????????ResponseBean??
????????ResponseBean??????status??statusCode??contentType??body??url??method??cookies
????2.2 ?????????????????ReponseUtil??????
????ReponseUtil????????????????????CloseableHttpResponse ?????ResponseBean
????public ResponseBean setResponseBean(CloseableHttpResponse httpResponse) {
????}
????3??????????
?????????????????????testNg???? ???????TestNG??????????????xml????????case
????3.1 ????case???
public class GetRoleTest {
static CookieStore cookieStore ;
static CookieUtil cookieUtil=new CookieUtil() ;
CloseableHttpClient client;
HttpUtils httpUtils=HttpUtils.getInstance();
@Parameters({ "url"?? "objBean" ??"statusCode"??"xmlName"})
@BeforeSuite
/*
* ????????????JSESSIONID????CookieStore??
* */
public  void TestLoginIn(String url ??String objBean?? String statusCode??String xmlName) {
Map<String??String> params=xmlUtil.readXMLDocument(objBean??xmlName);
client = HttpClients.createDefault();
CloseableHttpResponse httpResponse= httpUtils.post(url?? params?? client?? cookieStore);
//cookieUtil.printResponse(httpResponse);
cookieStore=cookieUtil.setCookieStore(httpResponse);
}
@Parameters({ "url"?? "objBean" ??"statusCode"??"body"??"xmlName"})
@Test(priority = 2)
public  void TestGetRole(String url ??String objBean?? String statusCode??String body??String xmlName) {
Map<String??String> params=xmlUtil.readXMLDocument(objBean??xmlName);
client = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
CloseableHttpResponse httpResponse= httpUtils.post(url?? params?? client?? cookieStore);
ResponseBean rb=new ReponseUtil().setResponseBean(httpResponse);
//        add Assert
Assert.assertEquals("OK"?? rb.getStatus());
Assert.assertEquals(statusCode?? rb.getStatusCode());
Assert.assertEquals(true?? rb.getBody().contains(body));
}
@AfterSuite
public void closeClient(){
try {
// ?????????????
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
????[?] ???API?????????ζ??У??Cookie????????????ζ?????е??????????Cookie