• “我这一生都是坚定不移的唯物主义者,唯有你,我希望有来生。”

  • Author only
  • Author only
  • import io.restassured.builder.ResponseBuilder;
    import io.restassured.filter.Filter;
    import io.restassured.filter.FilterContext;
    import io.restassured.http.ContentType;
    import io.restassured.response.Response;
    import io.restassured.specification.FilterableRequestSpecification;
    import io.restassured.specification.FilterableResponseSpecification;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import java.lang.String;
    import java.util.Base64;
    import static org.hamcrest.Matchers.*;
    import static io.restassured.RestAssured.given;
    //作业2:利用filter完成对 http://jenkins.testing-studio.com:9001/base64base64.json 的解密
    //Filter的机制given + when -> filter -> alter request -> server -> origin response -> filter -> alter response -> then
    public class homework_filter{
    public static Filter decodeFilter=new Filter() {
    @Override
    public Response filter(FilterableRequestSpecification req, FilterableResponseSpecification res, FilterContext filterContext) {
    Response response=filterContext.next(req, res);
    String decode1 = new String(Base64.getDecoder().decode(response.body().asString().trim().replace("\n",""))).trim();
    String decode2 = new String(Base64.getDecoder().decode(decode1)).trim();
    Response responseNew=new ResponseBuilder().clone(response)
    .setBody(decode2)
    .setContentType(ContentType.JSON)
    .build();
    return responseNew;
    }
    };
    @Test
    public void decodeByFilter(){
    given().log().all()
    //.proxy(8080)
    .filter(decodeFilter)
    .auth().basic("hogwarts", "123456")
    .when().log().all().header("USER", "CBr2")
    .get("http://jenkins.testing-studio.com:9001/base64base64.json")
    .then().statusCode(200).body("data.items.quote.name[0]", equalTo("上证指数"));
    }
    }
  • @Test
    //作业1:完成github的oauth2的认证测试用例,https://api.github.com/search/repositories
    public void ZuoYe1_20190105(){
    given()
    .auth().oauth2("5c26cf104c6bd81ea430d82386dce0f6b6c58dc6")
    .when()
    .param("q","CBr2")
    .get("https://api.github.com/search/repositories").prettyPeek()
    .then().statusCode(200);
    }
  • @Test
    //作业五:http://jenkins.testing-studio.com:8080/job/AllureDemo/api/json 编写json schema校验用例
    public void ZuoYe5(){
    given().
    when()
    .get("https://testerhome.com/api/v3/topics.json")
    .then()
    .statusCode(200)
    .body(matchesJsonSchema(new File("D:\\霍格沃兹课程\\RestAssuredDemo\\ZuoYe5.json")));
    }
  • @Test
    //作业四:http://jenkins.testing-studio.com:8080/job/AllureDemo/api/xml 判断构建号>16并且节点名字等于build的job的url地址
    public void ZuoYe4(){
    given()
    .when().get("http://jenkins.testing-studio.com:8080/job/AllureDemo/api/xml")
    .then()
    .statusCode(200)
    .body("freeStyleProject.build.findAll{it.number.toInteger()>16}.url",hasItem("http://jenkins.testing-studio.com:8080/job/AllureDemo/18/"));
    }
  • @Test
    //作业三:找出来testerhome帖子回复数大于等于6的所有帖子数是不是等于8
    public void ZuoYe3(){
    given()
    .when()
    .get("https://testerhome.com/api/v3/topics.json")
    .then().statusCode(200)
    .body("topics.findAll{it.replies_count>6}.size()",equalTo(8));
    //curl 'https://testerhome.com/api/v3/topics.json' |grep -oE "replies_count[^,]*"查看帖子回复数,[^,]*表示0个或多个不为,的字符
    }
  • @Test
    //作业二:编写post测试用例,登陆雪球,输入错误的用户名密码即可
    public void zuoye2(){
    given()
    // .proxy(8080)
    .param("username","CBr2")
    .param("password","123")
    .when().post("https://xueqiu.com/snowman/login")
    .then()
    .log().all()
    .statusCode(302);
    }
  • @Test
    //作业一:编写测试用例,实现发起get请求,搜索“霍格沃兹 测试学院”,断言状态码是否正确
    public void zuoye1Get(){
    given()
    .log().all()
    // .proxy(8080)
    .param("wd","霍格沃兹 测试学院")
    .param("ie","utf-8")
    .get("https://www.baidu.com/s")
    .then()
    .log().all()
    .statusCode(200);
    }