????????JSON??API??????????
?????????????????json????????API????????????????Σ?
????·queryParamters: ?????β???????????????URL??????????????????URL???棿?????????
????·pathParameters: ?????????????????????д??????????????????????URL?е??????//????
????·method?????????????д?????????????????????????get/post/delete/put??
????·resourceURL????????д??????????????????λ??
????·contentType???????????д??????????contentType??application/json????????д???????????д
????·headers???????????д???????????????????д?????????header??????????????????
????·body?? ??????????body???????????д??????????д????????JSON??????(?????????д???????????????)
????????????????????????????д??????????????????д?????????????????
????{
????"queryParameters":["userCode"?? "password" ]??
????"pathParameters":["ticketId"??"userId"]??
????"method":"POST"??
????"resourceURL":"/login"??
????"contentType":"application/x-www-form-urlencoded"??
????"headers":{"tokenId":"1234567432"??"Authorization":"890998776"} "body":"com.abcd.ddsf" }
???????????????API??JAVA??
????????????????????API??JAVA????????????????μ????飺 - ???????????BaseWebService - ????????????API?????????????????? - ??????????API????JSON?????·?? - ???BaseWebService???????
????public class LoginAPI extends BaseWebService { private final static String loginAPIDescriptionPath = "servicedescription/loginapi.json"; public LoginAPI(RequestData data) { super(loginAPIDescriptionPath?? data);
????}
????}
???????????????????
????????????????????excel????????????????????????????????img
??????????????????? RequestData.queryParameters(usercode)?? ???queryParameter?????key???usercode??value??????????????????????????
?????????????body????????excel??????У??е???????????RequestData.body??????????JSON?????????????JSON???????
?????????pathParameter???????RequestData.pathParameters(${key})??${key}??????pathParameter??????
???????????????????????????Test??resource???????棬?????????????????檔
????????????????
???????????????? - ????Dataprovider - ???????????
????@DataProvider(name="login_data") public Iterator getLoginData(Method m) throws InvocationTargetException?? Exception?? IOException {
????Map clazzMap = new HashMap();
????clazzMap.put("RequestData"?? RequestData.class); // build???????????????????????λ?? Iterator y= ExcelHelper.build("testcase/login/loginapitest.xls").loadExcelDataToIterator(clazzMap); return y;
????} @Test(dataProvider = "login_data") public void testLoginAPITes(RequestData data){
????LoginAPI api = new LoginAPI(data);
????api.execute(); //?????????? System.out.println(api.getResponse()); //????????????????200??302??401??500 ....... System.out.println(api.getResponse().getStatusCode()); //??????????? System.out.println(api.getResponse().getBody().toString()); //????????header???? System.out.println(api.getResponse().getHeaders()); //????????????????????? }
?????????????????????????????????????????????????????????????????????????????Щ????.
????API????????
????·API?? ??????apis??????
????·JSON?? ??????resource??servicedescription????
????·????????????? ??????resource??testcase???????£?????????????????????API?????
????·?????? ??????test??????