New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serenity + Rest Assured Integration: The "restQuery" in the report doesn't contain Response Body #448

Closed
viktor-klymenko opened this Issue Jun 13, 2016 · 9 comments

Comments

Projects
None yet
2 participants
@viktor-klymenko
Contributor

viktor-klymenko commented Jun 13, 2016

Serenity + Rest Assured Integration: The "restQuery" in the report doesn't contain Response Body - the corresponding field in HTML report is empty. Actually, there are not such field in "restQuery" element of corresponding json generated after test execution.
The request was sent using following code:

given()
                .specification(requests.getRequest(parameter1, parameter2))
                .body(data)
                .log().all()
                .post("server.php");

The baseURI is:
RestAssured.baseURI = "http://www.angularjshub.com";

The basePath is:
.setDefaultBasePath("code/examples/servercalls/01_HTTPService/")

Moreover, field "responseCookies" actually contains headers of response instead of cookies.

Versions:
compile 'net.serenity-bdd:serenity-core:1.1.36'
compile 'net.serenity-bdd:serenity-rest-assured:1.1.36'

@YamStranger

This comment has been minimized.

Show comment
Hide comment
@YamStranger

YamStranger Jun 13, 2016

Member

Helo @viktor-klymenko

Can you add in your code check that response body is not empty? (using then).

About cookies and headers - I will check

Thanks!

Member

YamStranger commented Jun 13, 2016

Helo @viktor-klymenko

Can you add in your code check that response body is not empty? (using then).

About cookies and headers - I will check

Thanks!

@viktor-klymenko

This comment has been minimized.

Show comment
Hide comment
@viktor-klymenko

viktor-klymenko Jun 13, 2016

Contributor

The following code is passed:

then()
                .body(containsString(parameter2))
                .and()
                .body(containsString(parameter2))
                .and()
                .body(containsString(data));

both given() and then() are imported from SerenityRest (import static net.serenitybdd.rest.SerenityRest.*;)

Contributor

viktor-klymenko commented Jun 13, 2016

The following code is passed:

then()
                .body(containsString(parameter2))
                .and()
                .body(containsString(parameter2))
                .and()
                .body(containsString(data));

both given() and then() are imported from SerenityRest (import static net.serenitybdd.rest.SerenityRest.*;)

@viktor-klymenko

This comment has been minimized.

Show comment
Hide comment
@viktor-klymenko

viktor-klymenko Jun 13, 2016

Contributor

Also, this request is sent through Fiddler as a proxy and I see in Fiddler that response actually contains expected body.

Contributor

viktor-klymenko commented Jun 13, 2016

Also, this request is sent through Fiddler as a proxy and I see in Fiddler that response actually contains expected body.

@YamStranger

This comment has been minimized.

Show comment
Hide comment
@YamStranger

YamStranger Jun 13, 2016

Member

I see request and response body are equal in your test. Thanks!

Member

YamStranger commented Jun 13, 2016

I see request and response body are equal in your test. Thanks!

@viktor-klymenko

This comment has been minimized.

Show comment
Hide comment
@viktor-klymenko

viktor-klymenko Jun 14, 2016

Contributor

Actually, they are not fully equal. Let me show you requests and response bodies from Fiddler for this test:
Request URL:
http://www.angularjshub.com:80/code/examples/servercalls/01_HTTPService/server.php?param1=first%20param&param2=second%20param
Request Body:
this is data

Response Body:

POST request received!
param1 = first param
param2 = second param
POST DATA: this is data

So, in this case I expect that HTML report generated after execution of the test will contain value above in "Response Body" field. But actually, this field is empty.

Contributor

viktor-klymenko commented Jun 14, 2016

Actually, they are not fully equal. Let me show you requests and response bodies from Fiddler for this test:
Request URL:
http://www.angularjshub.com:80/code/examples/servercalls/01_HTTPService/server.php?param1=first%20param&param2=second%20param
Request Body:
this is data

Response Body:

POST request received!
param1 = first param
param2 = second param
POST DATA: this is data

So, in this case I expect that HTML report generated after execution of the test will contain value above in "Response Body" field. But actually, this field is empty.

@viktor-klymenko

This comment has been minimized.

Show comment
Hide comment
@viktor-klymenko

viktor-klymenko Jun 17, 2016

Contributor

I've found that Response Body was not written because of Response Type - test server (see above) returns response with Content Type "text/html", which is correpond to enum ContentType.HTML
And this content type is absent in the following method in RestReportingHelper class:

private static boolean shouldRecordResponseBodyFor(Response result) {
        final ContentType type = ContentType.fromContentType(result.contentType());
        return type != null && (ContentType.JSON == type || ContentType.XML == type
                || ContentType.TEXT == type);
    }

It looks like a defect because body with such content type may be required for failures analysis as well as json or xml.

Contributor

viktor-klymenko commented Jun 17, 2016

I've found that Response Body was not written because of Response Type - test server (see above) returns response with Content Type "text/html", which is correpond to enum ContentType.HTML
And this content type is absent in the following method in RestReportingHelper class:

private static boolean shouldRecordResponseBodyFor(Response result) {
        final ContentType type = ContentType.fromContentType(result.contentType());
        return type != null && (ContentType.JSON == type || ContentType.XML == type
                || ContentType.TEXT == type);
    }

It looks like a defect because body with such content type may be required for failures analysis as well as json or xml.

@viktor-klymenko

This comment has been minimized.

Show comment
Hide comment
@viktor-klymenko

viktor-klymenko Jun 17, 2016

Contributor

About cookies and headers - this defect can be reproduced in case if there are no cookies in response. The problem in the following code snippet in net.serenitybdd.rest.utils.RestResponseRecordingHelper#print method:

try (ByteArrayOutputStream output = new ByteArrayOutputStream();
                 PrintStream recordingStream = new PrintStream(output, true, StandardCharsets.UTF_8.toString())) {
                for (final LogDetail detail : logDetail) {
                    try {
                        ResponsePrinter.print(response, response.getBody(), recordingStream, detail, shouldPrettyPrint);
                    } catch (NullPointerException e) {
                        //can be thrown if some field like cookies or headers are empty
                    }
                    recordingStream.flush();
                    String recorded = new String(output.toByteArray(), StandardCharsets.UTF_8);
                    recorded = recorded.replaceAll("^(" +
                            "(Proxy:)|(Body:)|(Cookies:)|(Headers:)|(Multiparts:)|(Request path:)" +
                            ")\\s*\\n*", "");
                    recorded = recorded.replaceAll("^(<none>)", "");
                    recorded = recorded.replaceAll("\n$", "");
                    result.put(detail, recorded);

                }

The variable output is not cleared after first iteration of "for" loop and in case if there were no cookies in response the variable will not be modified in ResponsePrinter.print so the result's item with name "COOKIES" will contain headers captured during previous interation

Contributor

viktor-klymenko commented Jun 17, 2016

About cookies and headers - this defect can be reproduced in case if there are no cookies in response. The problem in the following code snippet in net.serenitybdd.rest.utils.RestResponseRecordingHelper#print method:

try (ByteArrayOutputStream output = new ByteArrayOutputStream();
                 PrintStream recordingStream = new PrintStream(output, true, StandardCharsets.UTF_8.toString())) {
                for (final LogDetail detail : logDetail) {
                    try {
                        ResponsePrinter.print(response, response.getBody(), recordingStream, detail, shouldPrettyPrint);
                    } catch (NullPointerException e) {
                        //can be thrown if some field like cookies or headers are empty
                    }
                    recordingStream.flush();
                    String recorded = new String(output.toByteArray(), StandardCharsets.UTF_8);
                    recorded = recorded.replaceAll("^(" +
                            "(Proxy:)|(Body:)|(Cookies:)|(Headers:)|(Multiparts:)|(Request path:)" +
                            ")\\s*\\n*", "");
                    recorded = recorded.replaceAll("^(<none>)", "");
                    recorded = recorded.replaceAll("\n$", "");
                    result.put(detail, recorded);

                }

The variable output is not cleared after first iteration of "for" loop and in case if there were no cookies in response the variable will not be modified in ResponsePrinter.print so the result's item with name "COOKIES" will contain headers captured during previous interation

@YamStranger

This comment has been minimized.

Show comment
Hide comment
@YamStranger
Member

YamStranger commented Jun 18, 2016

@viktor-klymenko Thanks a lot!

@YamStranger

This comment has been minimized.

Show comment
Hide comment
@YamStranger

YamStranger Jun 21, 2016

Member

It seems that this bug is solved

Member

YamStranger commented Jun 21, 2016

It seems that this bug is solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment