简体   繁体   中英

How to extract basePath with pathParameters with RestAssured

So I am using RestAssured to test some endpoints and pulling the test result into an Allure report.

I am currently trying to fill the report with useful information about each test case, like the endopoint pinged. To extract the url I tried using the following:

    RequestSpecification requestSpec = RestAssured.given().spec(Request.getRequestSpecification());
    QueryableRequestSpecification queryRequest = SpecificationQuerier.query(requestSpec);
    String retrieveURI = queryRequest.getBaseUri();
    System.out.println("Base URI is : "+retrieveURI);
    String retrievePath = queryRequest.getBasePath();
    System.out.println("Base PATH is : "+retrievePath);

where the Request.getRequestSpecification() returns a RequestSpecification build with RequestSpecBuilder .

the thing is my basePath is something like /info/{unitId}/something the value here is filled with a pathParameter once built. but the block String retrievePath = queryRequest.getBasePath(); System.out.println("Base PATH is: "+retrievePath);

returns my basepath with {unitId} in it instead of the actual path parameter passed.

Is there a way to extract the basePath of a RestAssured request with the pathParameter within it?

note, I know there is.log().uri() but this outputs the info in the counsole and I need it in a variable to send it to the Allure report.

To anyone this might help, QueryableRequestSpecification actually has a .getURI() method that wil essentially return the full uri with the pathParameters in it:

RequestSpecification requestSpec = RestAssured.given().spec(Request.getRequestSpecification());
QueryableRequestSpecification queryRequest = SpecificationQuerier.query(requestSpec);
String retrieveURI = queryRequest.getURI()
System.out.println("Full URI is : "+retrieveURI);

I use intelliJ on windows and for some reason the method was showing up red in my IDE

point of reference https://javadoc.io/doc/io.rest-assured/rest-assured/3.1.1/io/restassured/specification/QueryableRequestSpecification.html#getURI--

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM