I get an error message when i try to parse an XML response using REST assured

Mohammad Osama

Iam using this simple function to get and print out the value at an XML response:

@Test

    void validateXMLResponse() {

        String book = RestAssured.given().when()
                .get("https://chercher.tech/sample/api/books.xml")
                .then().extract().path("bookstore.book.title");
        System.out.println(book);

    }

But iam getting this error in the console:

java.lang.ClassCastException: class io.restassured.internal.path.xml.NodeChildrenImpl cannot be cast to class java.lang.String (io.restassured.internal.path.xml.NodeChildrenImpl is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
Semen Arshyn

Since you have more than book node in your xml, you should use corresponding index to define which book's title you want to get. Like this: "bookstore.book[0].title". Or iterate through index to get all the books titles.

    @Test
    public void validateXMLResponse() {
        String book = RestAssured.given().when()
                .get("https://chercher.tech/sample/api/books.xml")
                .then().extract().body().path("bookstore.book[0].title");
        System.out.println(book);
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i extract the SOAP XML Response Tag and Validate it in Rest Assured using TestNG

I get a syntax error when I try to send a discord message

I get this error when I try to install

Why am I getting an error when I try to get a response by id?

In REST Assured, how do I solve UnrecognizedPropertyException when mapping response to an object?

When I try and run pyspark.cmd I get the error message "find: 'version': No such file or directory"

How do I get a better error message when I try to pip install with an incompatible python version?

Why do I get an error message of NoneType object is not callable when I try to call this function?

Python/Terminal - Why am I getting this error message when I try to get user input

Using REST Assured, how can I check if a field is present or not in an array of json objects type of response?

Why do i always get NULL in php response when i try to send some variable using ajax

When I try to parse JSON I get JSONException

Why does audio.buffered.end(0) get an error message when I try to get buffered time

Rest Assured: How do I return JSON response as a String? (Java)

Getting an error when I try to parse data to get values from JSON

Parse REST response message using retrofit and observable

Why I have this error message related to missing MySql when I try to install Ruby GEM bundler? I am using MariaDB

I get error message "runtime error: index out of range [0] with length 0" when I try to start minikube

I get the error when i try get 50% of the image with cropperJS

I get an error when i try apt-get update?

Getting java.lang.AbstractMethodError when I test using REST Assured

Why do I get an error when I try to see my Text using useState?

Why do i get this error when I try installing autopep8 using pip?

Using React Native, I get an error when I try to use a background image

When I try to kick someone on Discord using bot I get an error

Rails, active storage, Error message when I try to attach a photo

PHP page does not load when I try to show an error message

I've got the error message when try to call API function

PHP error message when I try to check a value from database