0
votes

I want to show the http status code and response in serenity report. I am using the cucumber plus java and serenity framework. Please find below my code.

Feature file
Feature: Get Google address

Scenario: Predit google Address
Given API is set up

Then I get the Http status code and response

Step definition file:

@Given("^API is set up$")
public void setUp() {

}

@Then("^I get the Http status code and response$")

Serenity BDD Report

Given API is set up
SUCCESS

Then I get the status code and response
SUCCESS

2

2 Answers

0
votes

You can define global variable in your framework and use it as you can see in the custom reporting Tutorial of Serenity.

report.customfields.user = ${API_RESPONSE_CODE}
0
votes

If you use the net.serenitybdd.cucumber.CucumberWithSerenity Runner:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(...)

then you can use this helper method:

import net.thucydides.core.steps.ExecutedStepDescription;
import net.thucydides.core.steps.StepEventBus;
import org.apache.commons.lang3.StringUtils;

public static void showMessage(final String message) {
    String escapedMessage = message;
    escapedMessage = StringUtils.replace(escapedMessage, "|", "|");
    escapedMessage = StringUtils.replace(escapedMessage, " ", " ");
    escapedMessage = StringUtils.replace(escapedMessage, "_", "_");
    StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(escapedMessage));
    StepEventBus.getEventBus().stepFinished();
}

This will print any message on the Serenity-Report of the current Step-Execution


For your special case you can use serenity-rest-assured

    SerenityRest.given()
            .contentType("application/json")
            .header("Content-Type", "application/json")
            .body("{...}")
            .when().post("/...")
            .getStatusCode();

It generates a button into the serenity report where all details of the Requests are shown.
See the last Screenshot on the Article: https://www.blazemeter.com/blog/restful-api-testing-using-serenity-and-rest-assured-a-guide/