接口测试进阶课程中的相关代码

RestAssured基本使用


import io.restassured.response.Response;
import org.junit.*;

import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;


public class Demo {
    @Test
    public void baidu(){
        given()
            .log().all()
            .queryParam("wd", "mp3")
        .when()
            .get("http://www.baidu.com/s")
        .then()
            .log().all()
            .statusCode(200)
            .body("html.head.title", equalTo("mp3_百度搜索"));
    }

    @Test
    public void xueqiu(){
        useRelaxedHTTPSValidation();
        given()
            .log().all()
            .header("X-Requested-With", "XMLHttpRequest")
            .formParam("username", "15600534760")
            .formParam("password", "xxxxxx")
        .when()
            .post("https://xueqiu.com/snowman/login")
        .then()
            .log().all()
            .statusCode(200)
            .body("error_description", equalTo("用户名或密码错误"))
    }

    @Test
    public void xueqiu2(){


        useRelaxedHTTPSValidation();
        given()
            .log().all()
            .header("X-Requested-With", "XMLHttpRequest")
            .body("remember_me=true&username=15600534760&password=xxx&captcha=")
        .when()
            .post("/snowman/login")
        .then()
            .log().all()
            .statusCode(200)
            .body("error_description", equalTo("用户名或密码错误"));
    }

    @Before
    public void before() {

    }
    @BeforeClass
    public static void beforeClass(){
        baseURI="https://xueqiu.com/";
    }

}