Allure JBehave

Allure JBehave latest version

Generate beautiful HTML reports using Allure Report and your JBehave tests.

Allure Report JBehave Example

How to start

To integrate Allure into an existing JBehave project, you need to:

  1. Add Allure dependencies to your project.
  2. Activate the Allure JBehave plugin.
  3. Designate a location for Allure results storage.

Adding Allure dependencies

XML
<!-- Define the version of Allure you want to use via the allure.version property --> <properties> <allure.version>2.24.0</allure.version> </properties> <!-- Add allure-bom to dependency management to ensure correct versions of all the dependencies are used --> <dependencyManagement> <dependencies> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-bom</artifactId> <version>${allure.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- Add necessary Allure dependencies to dependencies section --> <dependencies> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-jbehave5</artifactId> <scope>test</scope> </dependency> </dependencies>
kts
// Define the version of Allure you want to use via the allureVersion property val allureVersion = "2.24.0" // ... dependencies { // Import allure-bom to ensure correct versions of all the dependencies are used testImplementation(platform("io.qameta.allure:allure-bom:$allureVersion")) // Add necessary Allure dependencies to dependencies section testImplementation("io.qameta.allure:allure-jbehave5") }
Groovy
// Define the version of Allure you want to use via the allureVersion property def allureVersion = "2.24.0" dependencies { // Import allure-bom to ensure correct versions of all the dependencies are used testImplementation platform("io.qameta.allure:allure-bom:$allureVersion") // Add necessary Allure dependencies to dependencies section testImplementation "io.qameta.allure:allure-jbehave5" }

Enabling Allure JBehave plugin

In your Embeddable class (such as a JUnitStories-based class), add the AllureJbehave5 reporter to the configuration object.

Java
import io.qameta.allure.jbehave5.AllureJbehave5; import org.jbehave.core.configuration.Configuration; import org.jbehave.core.configuration.MostUsefulConfiguration; import org.jbehave.core.junit.JUnitStories; import org.jbehave.core.reporters.StoryReporterBuilder; public class Stories extends JUnitStories { @Override public Configuration configuration() { return new MostUsefulConfiguration() .useStoryReporterBuilder(new StoryReporterBuilder() .withReporters(new AllureJbehave5())); } // ... }

Specifying Allure Results location

Allure, by default, saves test results in the project's root directory. However, it is recommended to store your test results in the build output directory.

To configure this, create an allure.properties file and place it in the test resources directory of your project, which is typically located at src/test/resources:

Properties file
#allure.properties allure.results.directory=target/allure-results
Properties file
#allure.properties allure.results.directory=build/allure-results
Properties file
#allure.properties allure.results.directory=build/allure-results

Running tests

Execute your JBehave tests as you normally would. Below are the commands for Gradle and Maven users:

For Gradle:

Bash
./gradlew test
Bash
gradlew test

For Maven:

Bash
./mvnw verify
Bash
mvnw verify

After running the tests, Allure will gather the test execution data and store it in the allure-results directory. You can then generate an HTML report from these results using Allure's reporting tools.

Writing tests

The Allure JBehave adapter extends the standard reporting features of JBehave by providing additional capabilities for crafting more informative and structured tests. This section highlights key enhancements that can be utilized:

Adding Metadata

Allure allows you to enrich your reports with a variety of metadata. This additional information provides context and details for each test, enhancing the report's usefulness. Refer to the metadata reference section for an exhaustive list of what can be added.

Java
import io.qameta.allure.Allure; import org.jbehave.core.annotations.Then; public class JBehaveSteps { @When("I open labels page") public void openLabelsPage() { Allure.description("This test attempts to create a label with specified title"); Allure.label("owner", "John Doe"); Allure.label("severity", "critical"); Allure.link("Website", "https://dev.example.com/"); Allure.issue("AUTH-123", "https://example.com/issues/AUTH-123"); Allure.tms("TMS-456", "https://example.com/tms/TMS-456"); // ... } }

Organize tests

Allure facilitates enhanced navigation in test reports by allowing tests to be organized into hierarchical structures. As explained in the section on Improving navigation in your test report, Allure JBehave supports this feature.

To specify a test's location in the suite-based hierarchy:

Java
import io.qameta.allure.Allure; import org.jbehave.core.annotations.Then; public class JBehaveSteps { @When("I open labels page") public void openLabelsPage() { Allure.label("parentSuite", "Tests for web interface"); Allure.suite("Tests for essential features"); Allure.label("subSuite", "Tests for labels"); // ... } }

Creating Sub-Steps

Allure JBehave enhances test reports by allowing the creation of sub-steps within a single JBehave step, which can be particularly useful in cases where you have a set of actions that are:

  • Sufficiently cohesive to be described as one step in a story file.
  • Intricate enough that they involve several potential failure points.

Allure provides three methods for defining sub-steps:

  1. Annotated Sub-Steps: Defined using @Step annotation.
  2. Lambda Sub-Steps: Utilizing lambda expressions for more concise and inline step definitions.
  3. No-Op Sub-Steps: Employed as placeholders or for structuring steps without additional functionality.

For detailed guidance on implementing each type of sub-step, consult the test steps reference.

Java
import io.qameta.allure.Step; import org.jbehave.core.annotations.Then; public class JBehaveSteps { @When("I open labels page") public void openLabelsPage() { step1(); step2(); } @Step("Step 1") public void step1() { subStep1(); subStep2(); } @Step("Sub-step 1") public void subStep1() { // ... } @Step("Sub-step 2") public void subStep2() { // ... } @Step("Step 2") public void step2() { // ... } }
Java
import io.qameta.allure.Allure; import org.jbehave.core.annotations.Then; public class JBehaveSteps { @When("I open labels page") public void openLabelsPage() { Allure.step("Step 1", (step) -> { // ... Allure.step("Sub-step 1"); // ... Allure.step("Sub-step 2"); }); Allure.step("Step 2", (step) -> { // ... }); } }

Support for Scenario Outlines

Allure JBehave provides complete support for Scenario Outlines, a feature of JBehave that allows for parametrized tests. No special setup is needed to take advantage of this capability within Allure.

Scenario: Registration When I go to the registration form And I enter my details: <login>, <password>, <name>, <birthday> Then the profile should be created Examples: | login | password | name | birthday | | johndoe | qwerty | John Doe | 1970-01-01 | | janedoe | 123456 | Jane Doe | 1111-11-11 |
Java
import io.qameta.allure.Allure; import org.jbehave.core.annotations.Then; import org.jbehave.core.annotations.When; public class JBehaveSteps { @When("I go to the registration form") public void goToRegistrationForm() { // ... } @When("I enter my details: $login, $password, $name, $birthday") public void enterMyDetails() { // ... } @Then("the profile should be created") public void profileShouldBeCreated() { // ... } }

Furthermore, Allure's Runtime API can be utilized to include extra parameters in the test report, offering enhanced documentation capabilities and greater detail for each test scenario:

Scenario: Registration When I go to the registration form And I enter my details Then the profile should be created
Java
import io.qameta.allure.Allure; import org.jbehave.core.annotations.Then; import org.jbehave.core.annotations.When; public class JBehaveSteps { @When("I go to the registration form") public void goToRegistrationForm() { // ... } @When("I enter my details") public void enterMyDetails() { Allure.parameter("login", "johndoe"); Allure.parameter("password", "qwerty"); Allure.parameter("name", "John Doe"); Allure.parameter("birthday", "1970-01-01"); // ... } @Then("the profile should be created") public void profileShouldBeCreated() { // ... } }

Attaching screenshots and other files

In Allure reports, you have the ability to attach various types of files, which can greatly enhance the comprehensibility of the report. A common practice is to attach screenshots that capture the state of the user interface at specific moments during test execution.

Allure JBehave offers multiple methods for creating attachments, whether from pre-existing files or from content generated on-the-fly. For detailed instructions on how to implement attachments, refer to the attachments section in the Allure JBehave reference.

Java
import io.qameta.allure.Allure; import org.jbehave.core.annotations.Then; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class JBehaveSteps { @When("I open labels page") public void openLabelsPage() throws IOException { // ... Allure.attachment("data.txt", "This is the file content."); Allure.attachment("img.png", Files.newInputStream(Paths.get("/path/img.png"))); } }

Selective test run (Allure Testops)

Test plan is currently not supported by the Allure JBehave adapter.

Environment information

For the main page of the report, you can collect various information about the environment in which the tests were executed.

For example, it is a good idea to use this to remember the OS and Java versions. This may help the future reader investigate bugs that are reproducible only in some environments.

Allure Report Environments Widget

To provide environment information, put a file named environment.properties into the allure-results directory after running the tests. See the example in Environment file.

Note that this feature should be used for properties that do not change for all tests in the report. If you have properties that can be different for different tests, consider using Parametrized tests.

Powered by
logo

Join our newsletter

Join our community

We aim to make Allure Report as reliable and user-friendly as possible, and together with the community, we're here to help when problems arise.

© 2024 Qameta Software Inc. All rights reserved.