简体   繁体   中英

Get XML result from HTML using RESTAssured

I am facing some situation where I thought the things will be pretty trivial, as usual not so much.

I am fetching a GET call to a site, which returns the result as HTML, with a lot of

RequestSpecification requestSpecification = initRequest()
            .basePath("myPathHere");

    Response response = requestSpecification.get().then().contentType(ContentType.HTML)
            .extract().response();

so far everything Is ok, but then when I try to convert that to XML it gives me empty result.

I tried

XmlPath htmlPath = new XmlPath(CompatibilityMode.XML, response.getBody().asString());

also

XmlPath htmlPath = new XmlPath(CompatibilityMode.HTML, response.getBody().asString());

I checked google on the matter is very chaotic, that should be quite easy, but why its not?

Try this:

RequestSpecification requestSpecification = initRequest()
                                              .basePath("myPathHere");

XmlPath htmlPath = requestSpecification
                      .get()
                      .xmlPath();

Or this:

RequestSpecification requestSpecification = initRequest()
                                              .basePath("myPathHere");

XmlPath htmlPath = requestSpecification
                      .get()
                      .then()
                      .extract()
                         .path('');

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