线下课第二期_接口测试_20180415

参考连接

http://static.javadoc.io/io.rest-assured/xml-path/3.0.7/io/restassured/path/xml/XmlPath.html
http://static.javadoc.io/io.rest-assured/json-path/3.0.7/io/restassured/path/json/JsonPath.html

参考代码

import org.junit.Test;

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

public class Demo {
    @Test
    public void testJson(){
        when().get("http://127.0.0.1:8000/testerhome.json")
        .then()
            .body("store.book.category", hasItems("reference"))
            .body("store.book[0].author", equalTo("Nigel Rees"))
            .body("store.book.find { book -> book.price == 8.95f }.price", equalTo(8.95f))
        ;
    }

    @Test
    public void testXML(){
        when().get("http://192.168.31.99:8000/testerhome.xml")
        .then()
            .body("shopping.category.item[0].name", equalTo("Chocolate"))
            .body("shopping.category.item.size()", equalTo(5))
            .body("shopping.category.findAll { it.@type == 'groceries' }.size()",equalTo(1))
            .body("shopping.category.item.findAll { it.price == 20 }.name",equalTo("Coffee"))
            .body("**.findAll { it.price == 20 }.name",equalTo("Coffee"))
        ;

    }
}

    public static  void loginXueqiu(){
        code=given()
                .header("User-Agent", "Xueqiu Android 10.2")
                .queryParam("_t", "1GENYMOTIONed534efb6ff44bbdae1e9192253f9a1a.2087663213.1523770568272.1523772396164")
                .queryParam("_s", "cdf894")
                .cookie("u", "2087663213")
                .cookie("xq_a_token","2c1b28b8a33f1d4f0474feaa11afd9200952cbd6")
                .formParam("grant_type", "password")
                .formParam("telephone", "15600534760")
                .formParam("password", "e10adc3949ba59abbe56e057f20f883e")
                .formParam("areacode", "86")
                .formParam("captcha", "")
                .formParam("client_id", "JtXbaMn7eP")
                .formParam("client_secret", "txsDfr9FphRSPov5oQou74")
                //.formParam("sid", "1GENYMOTIONed534efb6ff44bbdae1e9192253f9a1a")
                .when().post("/provider/oauth/token")
                .then()
                .log().all()
                .statusCode(400)
                //.body("error_code", equalTo("20082"))
                .extract().path("error_code");

        System.out.println(code);
    }

让Jenkins的html报告展示完整,需要在Jenkins系统管理的脚本命令行里开启权限
参考资料:https://wiki.jenkins.io/display/JENKINS/Configuring+Content+Security+Policy

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

jenkins shell执行命令

ls
which java
java -version
which mvn
mvn -version


mvn test ||:
mvn site
mvn surefire-report:report
find target

作业1

练习下基本的断言机制,json和xml的断言,以及find断言

作业2

演练下接口之间的传值

作业3

把接口测试的demo代码上传到github,并在jenkins里面创建job运行,出一份测试结果,包括测试趋势图,做完截图回帖。参考

下节课预告

  • filter机制
  • dubbo接口
  • 封装复用
  • swagger
  • 自动生成接口测试用例
关闭