REST Assured 系列汇总 之 REST Assured 15 - RequestSpecification Call Http方法
上一篇我们已经了解了Rest Aassured中Request Specification,对于初学者最大的疑惑就是有多种试方式执行相同的行为。
下面的例子是RequestSpecification多种方式调用http 方法
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
public class DifferentWaysOfCallingHttpMethodsOnRequestSpecifications {
public static void main(String[] args) {
// Creating request specification using given()
RequestSpecification request1= RestAssured.given();
// Setting Base URI
request1.baseUri("https://restful-booker.herokuapp.com");
// Setting Base Path
request1.basePath("/booking");
// We can directly call http verbs on RequestSpecification
Response res1= request1.get();
System.out.println(res1.asString());
// We can also pass RequestSpecification reference variable in overloaded given() method
Response res2 = RestAssured.given(request1).get();
System.out.println(res2.asString());
// We can also pass RequestSpecification using spec() method
Response res3 = RestAssured.given().spec(request1).get();
System.out.println(res3.asString());
}
}