美文网首页java8
接口自动化封装调接口类

接口自动化封装调接口类

作者: info_gu | 来源:发表于2020-06-09 15:18 被阅读0次

    package com.nuanshui.frms.test.utils.http;

    import io.restassured.response.Response;
    import io.restassured.response.ValidatableResponse;

    import java.net.URL;

    import static io.restassured.RestAssured.given;
    import static io.restassured.RestAssured.useRelaxedHTTPSValidation;

    public class RequestUtil {
    public static Response sendpostWithHttp(String surl, String token,String str) throws Exception{
    String msg=null;
    URL url = new URL(surl);
    Response response = given().log().all().
    header("accept", "application/json",
    "token",token).
    contentType("application/json").
    body(str).
    then().
    when().
    post(url);
    response.getBody().prettyPrint();

        return response;
    }
    public static ValidatableResponse sendgetWithHttp(String surl,String token, String str) throws Exception{
        URL url = new URL(surl);
        ValidatableResponse response = given()
                .header("token",token)
                .log().all()
                .queryParam(str)
                .when()
                .get(surl)
                .then()
                .log().all();
        return response;
    }
    public static Response sendpostWithHttps(String surl,String token, String str) throws Exception{
        URL url = new URL(surl);
        useRelaxedHTTPSValidation();
        Response response = given().log().all().
                header("accept", "application/json",
                        "token",token).
                contentType("application/json").
                body(str).
                then().
                statusCode(200).
                when().
                post(url);
        response.getBody().prettyPrint();
        return response;
    }
    public static ValidatableResponse sendgetWithHttps(String surl,String token, String str) throws Exception{
        URL url = new URL(surl);
        useRelaxedHTTPSValidation();
        ValidatableResponse response = given()
                .header("token",token)
                .log().all()
                .queryParam(str)
                .when()
                .get(surl)
                .then()
                .log().all()
                .statusCode(200);
        return response;
    }
    

    }

    相关文章

      网友评论

        本文标题:接口自动化封装调接口类

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