0

第一个问题:我有一个 API GET 请求,其中包含路径参数、查询参数和标头,我想将我的请求 url 作为字符串变量,我该如何实现?

第二个问题:如何将 pathParams 传递给字符串变量?我研究过如何传递路径参数,但是所有的例子都是get(" http://some_url/ {path}"),我想把url作为一个String。

像 String url = " http://my/request/url ",

如何使用 url+{id}?没有得到http字符串?

    given()
          .contentType(ContentTypeJSON).
    with()
      .pathParams("id", "1").
    when()
      .get("http://my/request/url/{id}").
    then()
      .assertThat().
          .statusLine("HTTP/1.1 200 OK");
4

1 回答 1

0

避免返工的简单方法是使用以下代码。

/*
 * We can parameterize it using baseURI and basePath and send a request to get a customer using ID      
 */
        RestAssured.baseURI = "http://parabank.parasoft.com/";
        RestAssured.basePath = "parabank/services/bank/customers";

        //also we can use a path parameter for the same request

        given().contentType(ContentType.JSON).pathParam("customers", "12212").when().get("{customers}/").then().statusCode(200).log().all();
于 2019-12-05T14:28:09.180 回答