Skip to content

Instantly share code, notes, and snippets.

@aslakhellesoy
Created November 14, 2012 16:01
Show Gist options
  • Save aslakhellesoy/4072962 to your computer and use it in GitHub Desktop.
Save aslakhellesoy/4072962 to your computer and use it in GitHub Desktop.
How to embed text into your cucumber-jvm report with Java
import cucumber.api.Scenario;
public class MyStepdefs {
private Scenario scenario;
@Before
public void before(Scenario scenario) {
this.scenario = scenario;
}
@Given("^I have (\\d+) cukes in my belly$")
public void cukes_in_my_belly(int cukes) {
scenario.write("This goes into the report(s)\n");
}
}
@cpyle0819
Copy link

Aslak,

I'm using cucumber-jvm and outputting standard cucumber html reports. After implementing your above solution, the html report only shows information before the scenario.write statement. Everything after the write statement, and the write statement itself, is completely gone. The output in the console displays as expected. Any idea what's happening?

EDIT:
I was trying to write to the scenario in the @before method. I think this was causing the issue. However, I would like my write statement to appear before everything else. Is there a simple way to accomplish this?

Thanks,
Corey

@jeremyjjbrown
Copy link

Which @before is this? I'm using org.junit.Before and getting a null.

@hex0cter
Copy link

@jeremyjjbrown, I believe it should be:

import cucumber.api.Scenario;
import cucumber.api.java.Before;

@rohandora
Copy link

Nice code snippet,but this embeds text at the step level,is there a way to embed text at scenario level?.
Eg:I would like to embed DeviceName(On which the Scenario ran) along with the Scenario Name.

@ankigure22
Copy link

Hi ,
I am also facing the same issue. I would like to pass some text information inside @before block but I am getting Null pointer exception in json formatter. Is there any way to pass text inside @before method.
import cucumber.api.Scenario;
import cucumber.api.java.Before;

Code snippet
@before("@Firefox")
public void localFF() throws Exception {

            scenario.write( "Browser Name : Firefox Browser" );
            driver = browserHelper.launchBrowser( "firefox" );

@Githraine
Copy link

Hi, we are using Cucumber ruby, and Scenario.write is undefined. Do you know if there is anything comparable for ruby?

@loki-tailor
Copy link

Hi, any updates on this issue, coz even I'm facing the same problem .. !!

@brabenetz
Copy link

There is a very weird implementation of this write method (throws away my message, and prints "message".... ):
https://github.com/serenity-bdd/serenity-cucumber/blame/master/src/main/java/net/serenitybdd/cucumber/SerenityReporter.java#L717

but this seams to work:

StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(message));
StepEventBus.getEventBus().stepFinished();

@chetand24
Copy link

Is this still applicable? I am also not able to get the output in the report. Do we have any other way to write custom message to cucumber report?

@kwbhatti
Copy link

Thanks a bunch, the above code snippet worked for me. I am also able to see it in my html report.

@anilreddy
Copy link

How can i do it in ruby?

@sgrillon14
Copy link

is it possible write a text in report with custom css?

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