美文网首页
HttpClient + Java 接口测试

HttpClient + Java 接口测试

作者: 嫩牛_软件测试_笔记 | 来源:发表于2018-09-27 15:41 被阅读0次

    项目结构如下:

    image.png

    相关代码:

    HttpClientAPI.java

    import java.util.HashMap;
    import java.util.Map;
    import java.util.Map.Entry;
    
    import org.apache.commons.lang.StringUtils;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpDelete;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.client.methods.HttpPut;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.params.CoreConnectionPNames;
    import org.apache.http.util.EntityUtils;
    
    //告诉编译器忽略指定的警告,不用在编译完成后出现警告信息。
    @SuppressWarnings("deprecation")
    public class HttpClientAPI {
    
        public static void main(String[] args) {
        }
    
        /**
         * 返回接口页面的json (body)
         */
        private String apiUrl;
        private HttpClient client = null;
        private StringEntity entity = null;
        private HttpResponse response = null;
        private String method = "";
        private String path = "";
        private String param = "";
        private String fragment;
        private int code;
        private static String body;
        private String requestBody;
        private Map<String, String> headers = new HashMap<String, String>();
    
        private StringBuffer sb = new StringBuffer();
    
        public HttpClientAPI(String apiUrl, String method) {
    
            this.apiUrl = apiUrl;
            this.method = method;
        }
    
        public String path(String path) {
    
            this.path = path.trim();
            return this.path;
        }
    
        public void param(String key, String value) {
    
            if (!StringUtils.isBlank(this.param)) {
                this.param += "&";
            }
            this.param += key.trim() + "=" + value.trim();
        }
    
        public void fragment(String info) {
    
            sb.append(info);
        }
    
        public void headers(String key, String value) {
    
            this.headers.put(key.trim(), value.trim());
        }
    
        public void body(String requestBody) {
    
            this.requestBody = requestBody.trim();
        }
    
        public boolean sendRequest() {
    
            boolean flag = false;
            try {
    
                client = new DefaultHttpClient();
    
                client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 600000);
                client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 600000);
    
                if (!StringUtils.isBlank(path)) {
                    apiUrl += path;
                }
    
                if (!StringUtils.isBlank(param)) {
                    apiUrl += "?" + param;
                }
    
                if (!StringUtils.isBlank(fragment)) {
                    apiUrl += "#" + fragment;
                }
    
                if (!StringUtils.isBlank(requestBody)) {
                    entity = new StringEntity(requestBody);
                }
                if (method.equalsIgnoreCase("GET")) {
                    HttpGet get = new HttpGet(apiUrl);
                    if (!this.headers.isEmpty()) {
                        for (Entry<String, String> header : headers.entrySet()) {
                            get.addHeader(header.getKey(), header.getValue());
                        }
                    }
                    response = client.execute(get);
                } else if (method.equalsIgnoreCase("POST")) {
                    HttpPost post = new HttpPost(apiUrl);
                    if (!this.headers.isEmpty()) {
                        for (Entry<String, String> header : headers.entrySet()) {
                            post.addHeader(header.getKey(), header.getValue());
                        }
                    }
                    post.setEntity(entity);
                    response = client.execute(post);
                } else if (method.equalsIgnoreCase("PUT")) {
                    HttpPut put = new HttpPut(apiUrl);
                    if (!this.headers.isEmpty()) {
                        for (Entry<String, String> header : headers.entrySet()) {
                            put.addHeader(header.getKey(), header.getValue());
                        }
                    }
                    put.setEntity(entity);
                    response = client.execute(put);
                } else if (method.equalsIgnoreCase("DELETE")) {
                    HttpDelete delete = new HttpDelete(apiUrl);
                    if (!this.headers.isEmpty()) {
                        for (Entry<String, String> header : headers.entrySet()) {
                            delete.addHeader(header.getKey(), header.getValue());
                        }
                    }
                    response = client.execute(delete);
    
                }
                HttpEntity entity = response.getEntity();
                body = EntityUtils.toString(entity);
    
            } catch (Exception e) {
            }
    
            int code = response.getStatusLine().getStatusCode();
            this.code = code;
            if (response != null)
                flag = true;
    
            client.getConnectionManager().shutdown();
            return flag;
        }
    
        public String getResponseBody() {
            return body;
        }
    
        public int getResponseCode() {
            return code;
        }
    
    
    }
    

    JsonBodyAssert.java

    import base.RanzhiDriver;
    import com.google.gson.Gson;
    import com.google.gson.reflect.TypeToken;
    import jxl.Cell;
    import jxl.Workbook;
    import jxl.read.biff.BiffException;
    import jxl.write.Label;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;
    import jxl.write.WriteException;
    
    import java.io.File;
    import java.io.IOException;
    import java.lang.reflect.Type;
    import java.util.ArrayList;
    import java.util.List;
    
    //告诉编译器忽略指定的警告,不用在编译完成后出现警告信息。
    @SuppressWarnings("deprecation")
    public class JsonBodyAssert {
    
        public static void main(String[] args) throws IOException,BiffException,WriteException {
    
            String locationId = null;
            String locationName = null;
            String locationCountry = null;
            String locationPath = null;
            String locationTimezone = null;
            String locationTimezone_offset = null;
            String nowText = null;
            String nowCode = null;
            String nowTemperature = null;
            String last_update = null;
    
    
            // 拼接apiUrl (其中baseUrl,city,language参数都取自excel表“1.输入”页内容)
            String excelFilePath = "src/main/java/data/testXinZhi.xls";
            JxlExcelUtil excel = new JxlExcelUtil();
    
            // 将sheet1中第一行数据复制到 sheet2 & sheet3 中第一行
            excel.WriteSheet1ToSheet2(excelFilePath);
    
            StringBuilder apiUrl = excel.WhileReadExcel(excelFilePath);
            System.out.println("  ---------------------待测所有接口---------------------  " + "\n" + apiUrl);
    
            String[] strs = apiUrl.toString().split("\n");
            for (int i = 0; i < strs.length; i++) {
                String apiUrlx = strs[i];
                System.out.println("  ++++++++++++++++++++ 开始执行如下接口 ++++++++++++++++++++  " + "\n" + apiUrlx);
    
                RanzhiDriver driver = new RanzhiDriver("");
                driver.navigateAndMaximize(apiUrlx);
    
                HttpClientAPI hca = new HttpClientAPI(apiUrlx, "GET");
                if (hca.sendRequest()) {
                    System.out.println("[接口实际返回结果] " + hca.getResponseBody());
                    System.out.println("[接口实际返回状态码] " + hca.getResponseCode());
                }
    
                if (hca.getResponseCode()==200) {
    
                    /**
                     * 解析body内容
                     * 可以对json中的字段值进行断言
                     */
                    Gson gson = new Gson();
                    Picc p1 = gson.fromJson(hca.getResponseBody(), Picc.class);
                    //            System.out.println("results = " + gson.toJson(p1.getResults()) + "\n");
    
                    Type listType = new TypeToken<ArrayList<Results>>() {}.getType();
                    ArrayList<Results> results = gson.fromJson(gson.toJson(p1.getResults()), listType);
                    for (Results r : results) {
                        locationId = r.getLocation().getId();
                        locationName = r.getLocation().getName();
                        locationCountry = r.getLocation().getCountry();
                        locationPath = r.getLocation().getPath();
                        locationTimezone = r.getLocation().getTimezone();
                        locationTimezone_offset = r.getLocation().getTimezone_offset();
                        nowText = r.getNow().getText();
                        nowCode = r.getNow().getCode();
                        nowTemperature = r.getNow().getTemperature();
                        last_update = r.getLast_update();
    
                        driver.quit();
                    }
    
                    try {
                        Workbook wb = Workbook.getWorkbook(new File(excelFilePath));
                        WritableWorkbook book = Workbook.createWorkbook(new File(excelFilePath), wb);
                        WritableSheet sheet = book.getSheet("3.实际结果");
    
                        String[] params = {locationId, locationName, locationCountry, locationPath, locationTimezone,
                                locationTimezone_offset, nowText, nowCode, nowTemperature, last_update};
                        for (int x = 0; x < params.length; x++) {
                            Label label = new Label(x, i + 1, params[x]);
                            sheet.addCell(label);
                            System.out.println(params[x]);
                        }
                        book.write();
                        book.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
    
                else if (hca.getResponseCode() != 200){
                    driver.quit();
                }
    
                // 循环比对sheet1 vs sheet2中的相应cell中的数据,若一致,sheet3 OK ; 否则 NG
                try {
                    Workbook wb = Workbook.getWorkbook(new File(excelFilePath));
                    WritableWorkbook book = Workbook.createWorkbook(new File(excelFilePath), wb);
    
                    WritableSheet sheet1 = book.getSheet(1);
                    WritableSheet sheet2 = book.getSheet(2);
                    WritableSheet sheet3 = book.getSheet(3);
                    int columnum = sheet1.getColumns();
                    int rownum = sheet1.getRows();
    
                    for(int x=1;x<rownum;x++)
                    {
    //                获取sheet中所有内容
                        for (int j = 0; j < columnum; j++) {
                            Cell cellN1 = sheet1.getCell(j, x);
                            Cell cellN2 = sheet2.getCell(j, x);
                            String result1 = cellN1.getContents();
                            String result2 = cellN2.getContents();
    
                            if (result1 == result2){
                                Label label = new Label(j, x, "OK");
                                sheet3.addCell(label);
                            }
    
                            else if(result1 != result2){
                                Label label = new Label(j, x, "NG");
                                sheet3.addCell(label);
                            }
    
                        }
                    }
                    book.write();
                    book.close();
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    
          /**
         * 以下:定义一个序列化的Bean (body)
         */
        public static class Picc {
            private List<Results> results;
    
            private List<Results> getResults() {
                return results;
            }
    
            public void setResults(List<Results> results) {
                this.results = results;
            }
        }
    
        public static class Results {
            private Location location;
            private Now now;
            private String last_update;
    
            private Location getLocation() {
                return location;
            }
    
            public void setLocation(Location location) {
                this.location = location;
            }
    
            private Now getNow() {
                return now;
            }
    
            public void setNow(Now now) {
                this.now = now;
            }
    
            private String getLast_update() {
                return last_update;
            }
    
            public void setLast_update(String last_update) {
                this.last_update = last_update;
            }
        }
    
        public static class Location {
            private String id;
            private String name;
            private String country;
            private String path;
            private String timezone;
            private String timezone_offset;
    
            public String getId() {
                return id;
            }
    
            public void setId(String id) {
                this.id = id;
            }
    
            public String getName() {
                return name;
            }
    
            public void setName(String name) {
                this.name = name;
            }
    
            public String getCountry() {
                return country;
            }
    
            public void setCountry(String country) {
                this.country = country;
            }
    
            public String getPath() {
                return path;
            }
    
            public void setPath(String path) {
                this.path = path;
            }
    
            public String getTimezone() {
                return timezone;
            }
    
            public void setTimezone(String timezone) {
                this.timezone = timezone;
            }
    
            public String getTimezone_offset() {
                return timezone_offset;
            }
    
            public void setTimezone_offset(String timezone_offset) {
                this.timezone_offset = timezone_offset;
            }
    
        }
    
        public static class Now {
            private String text;
            private String code;
            private String temperature;
    
            private String getText() {
                return text;
            }
    
            public void setText(String text) {
                this.text = text;
            }
    
            public String getCode() {
                return code;
            }
    
            public void setCode(String code) {
                this.code = code;
            }
    
            public String getTemperature() {
                return temperature;
            }
    
            public void setTemperature(String temperature) {
                this.temperature = temperature;
            }
        }
    
    
    }
    

    Excel 准备的接口数据:

    image.png

    运行代码后,生成的效果如下:

    image.png

    运行代码生成的日志如下:

    "C:\Program Files\Java\jdk1.8.0_121\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.4\lib\idea_rt.jar=7189:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\Users\tester\IdeaProjects\JerseyJSONExample\target\classes;C:\Users\tester\IdeaProjects\JerseyJSONExample\poi-3.5-FINAL.jar;C:\Users\tester\IdeaProjects\JerseyJSONExample\poi-3.5-FINAL_2.jar;C:\Users\tester\.m2\repository\com\sun\jersey\jersey-server\1.9\jersey-server-1.9.jar;C:\Users\tester\.m2\repository\asm\asm\3.1\asm-3.1.jar;C:\Users\tester\.m2\repository\com\sun\jersey\jersey-core\1.9\jersey-core-1.9.jar;C:\Users\tester\.m2\repository\com\sun\jersey\jersey-client\1.9\jersey-client-1.9.jar;C:\Users\tester\.m2\repository\com\sun\jersey\jersey-json\1.9\jersey-json-1.9.jar;C:\Users\tester\.m2\repository\org\codehaus\jettison\jettison\1.1\jettison-1.1.jar;C:\Users\tester\.m2\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar;C:\Users\tester\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-impl-2.2.3-1.jar;C:\Users\tester\.m2\repository\javax\xml\bind\jaxb-api\2.2.2\jaxb-api-2.2.2.jar;C:\Users\tester\.m2\repository\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;C:\Users\tester\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.8.3\jackson-core-asl-1.8.3.jar;C:\Users\tester\.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.8.3\jackson-mapper-asl-1.8.3.jar;C:\Users\tester\.m2\repository\org\codehaus\jackson\jackson-jaxrs\1.8.3\jackson-jaxrs-1.8.3.jar;C:\Users\tester\.m2\repository\org\codehaus\jackson\jackson-xc\1.8.3\jackson-xc-1.8.3.jar;C:\Users\tester\.m2\repository\commons-lang\commons-lang\2.5\commons-lang-2.5.jar;C:\Users\tester\.m2\repository\org\apache\httpcomponents\httpcore\4.4.6\httpcore-4.4.6.jar;C:\Users\tester\.m2\repository\org\apache\httpcomponents\httpclient\4.5.3\httpclient-4.5.3.jar;C:\Users\tester\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\tester\.m2\repository\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;C:\Users\tester\.m2\repository\commons-io\commons-io\2.5\commons-io-2.5.jar;C:\Users\tester\.m2\repository\commons-beanutils\commons-beanutils\1.8.0\commons-beanutils-1.8.0.jar;C:\Users\tester\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\tester\.m2\repository\net\sf\ezmorph\ezmorph\1.0.6\ezmorph-1.0.6.jar;C:\Users\tester\.m2\repository\com\google\code\gson\gson\2.8.2\gson-2.8.2.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-java\3.4.0\selenium-java-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-api\3.4.0\selenium-api-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\3.4.0\selenium-chrome-driver-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-edge-driver\3.4.0\selenium-edge-driver-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\3.4.0\selenium-firefox-driver-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\3.4.0\selenium-ie-driver-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-opera-driver\3.4.0\selenium-opera-driver-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\3.4.0\selenium-remote-driver-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-safari-driver\3.4.0\selenium-safari-driver-3.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\selenium-support\3.4.0\selenium-support-3.4.0.jar;C:\Users\tester\.m2\repository\cglib\cglib-nodep\3.2.4\cglib-nodep-3.2.4.jar;C:\Users\tester\.m2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;C:\Users\tester\.m2\repository\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar;C:\Users\tester\.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar;C:\Users\tester\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.22\cssparser-0.9.22.jar;C:\Users\tester\.m2\repository\com\google\guava\guava\21.0\guava-21.0.jar;C:\Users\tester\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\tester\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.26\htmlunit-2.26.jar;C:\Users\tester\.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.26\htmlunit-core-js-2.26.jar;C:\Users\tester\.m2\repository\net\sourceforge\htmlunit\neko-htmlunit\2.25\neko-htmlunit-2.25.jar;C:\Users\tester\.m2\repository\org\apache\httpcomponents\httpmime\4.5.3\httpmime-4.5.3.jar;C:\Users\tester\.m2\repository\org\eclipse\jetty\jetty-io\9.4.1.v20170120\jetty-io-9.4.1.v20170120.jar;C:\Users\tester\.m2\repository\org\eclipse\jetty\jetty-util\9.4.1.v20170120\jetty-util-9.4.1.v20170120.jar;C:\Users\tester\.m2\repository\net\java\dev\jna\jna\4.1.0\jna-4.1.0.jar;C:\Users\tester\.m2\repository\net\java\dev\jna\jna-platform\4.1.0\jna-platform-4.1.0.jar;C:\Users\tester\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\tester\.m2\repository\com\codeborne\phantomjsdriver\1.4.0\phantomjsdriver-1.4.0.jar;C:\Users\tester\.m2\repository\org\seleniumhq\selenium\htmlunit-driver\2.26\htmlunit-driver-2.26.jar;C:\Users\tester\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;C:\Users\tester\.m2\repository\org\eclipse\jetty\websocket\websocket-api\9.4.3.v20170317\websocket-api-9.4.3.v20170317.jar;C:\Users\tester\.m2\repository\org\eclipse\jetty\websocket\websocket-client\9.4.3.v20170317\websocket-client-9.4.3.v20170317.jar;C:\Users\tester\.m2\repository\org\eclipse\jetty\jetty-client\9.4.3.v20170317\jetty-client-9.4.3.v20170317.jar;C:\Users\tester\.m2\repository\org\eclipse\jetty\jetty-http\9.4.3.v20170317\jetty-http-9.4.3.v20170317.jar;C:\Users\tester\.m2\repository\org\eclipse\jetty\websocket\websocket-common\9.4.3.v20170317\websocket-common-9.4.3.v20170317.jar;C:\Users\tester\.m2\repository\xalan\serializer\2.7.2\serializer-2.7.2.jar;C:\Users\tester\.m2\repository\xalan\xalan\2.7.2\xalan-2.7.2.jar;C:\Users\tester\.m2\repository\xerces\xercesImpl\2.11.0\xercesImpl-2.11.0.jar;C:\Users\tester\.m2\repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;C:\Users\tester\.m2\repository\org\testng\testng\6.8\testng-6.8.jar;C:\Users\tester\.m2\repository\org\beanshell\bsh\2.0b4\bsh-2.0b4.jar;C:\Users\tester\.m2\repository\com\beust\jcommander\1.27\jcommander-1.27.jar;C:\Users\tester\.m2\repository\org\yaml\snakeyaml\1.6\snakeyaml-1.6.jar;C:\Users\tester\.m2\repository\org\apache\commons\commons-csv\1.4\commons-csv-1.4.jar;C:\Users\tester\.m2\repository\com\relevantcodes\extentreports\2.41.2\extentreports-2.41.2.jar;C:\Users\tester\.m2\repository\org\jsoup\jsoup\1.8.3\jsoup-1.8.3.jar;C:\Users\tester\.m2\repository\org\xerial\sqlite-jdbc\3.8.11.1\sqlite-jdbc-3.8.11.1.jar;C:\Users\tester\.m2\repository\org\freemarker\freemarker\2.3.23\freemarker-2.3.23.jar;C:\Users\tester\.m2\repository\org\mongodb\mongodb-driver\3.0.4\mongodb-driver-3.0.4.jar;C:\Users\tester\.m2\repository\org\mongodb\bson\3.0.4\bson-3.0.4.jar;C:\Users\tester\.m2\repository\org\mongodb\mongodb-driver-core\3.0.4\mongodb-driver-core-3.0.4.jar;C:\Users\tester\.m2\repository\com\sun\mail\javax.mail\1.5.6\javax.mail-1.5.6.jar;C:\Users\tester\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\tester\.m2\repository\us\codecraft\webmagic-core\0.5.3\webmagic-core-0.5.3.jar;C:\Users\tester\.m2\repository\us\codecraft\xsoup\0.3.1\xsoup-0.3.1.jar;C:\Users\tester\.m2\repository\org\assertj\assertj-core\1.5.0\assertj-core-1.5.0.jar;C:\Users\tester\.m2\repository\org\slf4j\slf4j-api\1.7.6\slf4j-api-1.7.6.jar;C:\Users\tester\.m2\repository\org\slf4j\slf4j-log4j12\1.7.6\slf4j-log4j12-1.7.6.jar;C:\Users\tester\.m2\repository\com\jayway\jsonpath\json-path\0.8.1\json-path-0.8.1.jar;C:\Users\tester\.m2\repository\net\minidev\json-smart\1.1.1\json-smart-1.1.1.jar;C:\Users\tester\.m2\repository\com\alibaba\fastjson\1.1.37\fastjson-1.1.37.jar;C:\Users\tester\.m2\repository\us\codecraft\webmagic-extension\0.5.3\webmagic-extension-0.5.3.jar;C:\Users\tester\.m2\repository\redis\clients\jedis\2.0.0\jedis-2.0.0.jar;C:\Users\tester\.m2\repository\commons-pool\commons-pool\1.5.5\commons-pool-1.5.5.jar;C:\Users\tester\.m2\repository\mysql\mysql-connector-java\6.0.6\mysql-connector-java-6.0.6.jar;C:\Users\tester\.m2\repository\org\json\json\20160810\json-20160810.jar;C:\Users\tester\.m2\repository\log4j\log4j\1.2.12\log4j-1.2.12.jar;C:\Users\tester\.m2\repository\org\apache\poi\poi\3.15\poi-3.15.jar;C:\Users\tester\.m2\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar;C:\Users\tester\.m2\repository\net\sourceforge\jexcelapi\jxl\2.6.12\jxl-2.6.12.jar;C:\Users\tester\.m2\repository\org\jetbrains\annotations\15.0\annotations-15.0.jar" JsonBodyAssert
      ---------------------待测所有接口---------------------  
    https://api.seniverse.com/v3/weather/now.json?key=d4r9cdzkyh337k5n&location=深圳&language=en&unit=c
    https://api.seniverse.com/v3/weather/now.json?key=d4r9cdzkyh337k5n&location=湖口&language=zh-Hans&unit=c
    https://api.seniverse.com/v3/weather/now.json?key=d4r9cdzkyh337k5n&location=九江&language=zh-Hans&unit=c
    
      ++++++++++++++++++++ 开始执行如下接口 ++++++++++++++++++++  
    https://api.seniverse.com/v3/weather/now.json?key=d4r9cdzkyh337k5n&location=深圳&language=en&unit=c
    Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 30559
    Only local connections are allowed.
    log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
    log4j:WARN Please initialize the log4j system properly.
    九月 27, 2018 3:32:57 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
    信息: Detected dialect: OSS
    [接口实际返回结果] {"results":[{"location":{"id":"WS10730EM8EV","name":"Shenzhen","country":"CN","path":"Shenzhen,Shenzhen,Guangdong,China","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"now":{"text":"Cloudy","code":"4","temperature":"28"},"last_update":"2018-09-27T15:05:00+08:00"}]}
    [接口实际返回状态码] 200
    WS10730EM8EV
    Shenzhen
    CN
    Shenzhen,Shenzhen,Guangdong,China
    Asia/Shanghai
    +08:00
    Cloudy
    4
    28
    2018-09-27T15:05:00+08:00
      ++++++++++++++++++++ 开始执行如下接口 ++++++++++++++++++++  
    https://api.seniverse.com/v3/weather/now.json?key=d4r9cdzkyh337k5n&location=湖口&language=zh-Hans&unit=c
    Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 33728
    Only local connections are allowed.
    九月 27, 2018 3:33:10 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
    信息: Detected dialect: OSS
    [接口实际返回结果] {"status":"You don't have access to data of this city.","status_code":"AP010006"}
    [接口实际返回状态码] 403
      ++++++++++++++++++++ 开始执行如下接口 ++++++++++++++++++++  
    https://api.seniverse.com/v3/weather/now.json?key=d4r9cdzkyh337k5n&location=九江&language=zh-Hans&unit=c
    Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 3136
    Only local connections are allowed.
    九月 27, 2018 3:33:20 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
    信息: Detected dialect: OSS
    [接口实际返回结果] {"results":[{"location":{"id":"WT62ZWSX5CM0","name":"九江","country":"CN","path":"九江,九江,江西,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"now":{"text":"多云","code":"4","temperature":"24"},"last_update":"2018-09-27T15:05:00+08:00"}]}
    [接口实际返回状态码] 200
    WT62ZWSX5CM0
    九江
    CN
    九江,九江,江西,中国
    Asia/Shanghai
    +08:00
    多云
    4
    24
    2018-09-27T15:05:00+08:00
    
    Process finished with exit code 0
    

    相关文章

      网友评论

          本文标题:HttpClient + Java 接口测试

          本文链接:https://www.haomeiwen.com/subject/wubeoftx.html