0

First question: I have a API GET request which contains path parameters, query parameters and headers, and I'd like to put my request url as a string variable, how can I achieve it?

Second quesiton: How to pass pathParams to a string variable? I've studied how to pass path parameters, but all examples get("http://some_url/{path}"), I'd like to put the url as a String.

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

how to get with url+{id}? not get the http string?

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

1 Answers1

0

Simple way to avoid rework is using the below code .

/*
 * 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();
Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41