2014-03-26 41 views

回答

0

這不支持。請在issue tracker處作爲問題添加並說明您的使用案例。最接近解決方法的可能是設置一個baseUri。

更新:現在在2.3.2中支持。

0

下面是一個例子,我已經展示瞭如何在全局中設置基本路徑。

import org.testng.annotations.BeforeClass; 
import org.testng.annotations.Test; 
import com.jayway.restassured.builder.RequestSpecBuilder; 
import com.jayway.restassured.http.ContentType; 
import com.jayway.restassured.specification.RequestSpecification; 
import static com.jayway.restassured.RestAssured.*; 

public class RequestSpecificationTest { 

RequestSpecification rspec; 
RequestSpecBuilder build; 

@BeforeClass 
public void requestSpec() { 

build = new RequestSpecBuilder(); 
build.setBaseUri ("https://maps.googleapis.com"); 
build.setBasePath ("maps/api/place/textsearch/json"); 
build.addParam ("query", "restaurants in mumbai"); 
build.addParam ("key", "XYZ"); 

rspec = build.build(); 

} 

@Test 
public void test01() { 

    given() 
    .spec (rspec) 
    .when() 
    .get ("") 
    .then() 
    .contentType (ContentType.JSON) 
    .statusCode (200);  
} 

} 

您也可以按照我的教程就同一主題: Using RequestSpecBuilder in Rest Assured (Code Reuse)

相關問題