Let’s create a property file called allure.properties in src/test/resources folder with the below content. The result directory is where the generated allure report would be stored.
allure.results.directory=build/allure-results
You can display your page level methods in the allure reports by using @Step allure annotation while creating page objects. Example:
/** * Validate if Screen Title is displayed * * @return True if Screen Title is displayed , otherwise returns * false. */ @Step("Verifying the Screen Title is Displayed") public boolean isScreenTitleDisplayed() { return doesElementExist(screenTitle, SMALL_WAIT); }
Similarly, you can display your test methods in the allure reports by using @Epic, @Feature, @Severity, @Story, @Issue, @Description etc. annotations in the test suite. Example:
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Epic("xxxx") @Feature("About App Page Layout") public class AboutAppTestSuite extends BaseTest { private AboutAppScreen aboutAppScreen; protected String testStatus = ""; private static final String SCREEN_NAME = "aboutAppScreen"; @BeforeAll @Override public void setUp() throws Exception { super.setUp(); } @AfterAll @Override public void tearDown() throws Exception { super.tearDown(); } @Severity(SeverityLevel.CRITICAL) @Issue("xxxx") @DisplayName("xxxx") @Description("xxxx: Verify that the AboutAppScreen Title is displayed") @Test @Order(1) @Smoke @Regression @SIT @AT public void testScenario1() { String tcName = new Object() { }.getClass().getEnclosingMethod().getName(); log("Test Name" + tcName); SoftAssertions.assertSoftly( softAssertions -> { softAssertions.assertThat(aboutAppScreen.isScreenTitleDisplayed()).as("The Screen title is displayed").isTrue(); } ); testStatus = aboutAppScreen.isScreenTitleDisplayed() ? "Passed" : "Failed"; updateTCPassCount(); }
You can order the content in the allure report by Epic or Feature type which makes Allure report very appealing.
To generate Allure report after running the test suite, use the below command with appropriate Gradle task. To run test methods tagged with Smoke use:
./gradlew Smoke --tests "com.taf.testautomation.uitests.AboutAppTestSuite" allurereport
If you want to generate Allure report for Cucumber, add the AllureCucumber5Jvm plugin in the runner file as follows. This is because we are using allure-cucumber5-jvm plugin build.gradle.
@CucumberOptions(features = "src/test/resources/features", glue = {"com.taf.testautomation.cucumber.aboutapp"}, monochrome = true, plugin = {"html:build/cucumber-html-report-normal",
"json:build/cucumber.json", "io.qameta.allure.cucumber5jvm.AllureCucumber5Jvm", "com.taf.testautomation.cucumber.ExtentCucumberAdapter:"}, tags = {"@AboutApp"})
Then from Gradle command line run the runner file as follows:
./gradlew test -Dcucumber.options="--tags @AboutApp" allurereport
The Allure report would be generated in Gradle build folder. You can either manually open the Allure report in a browser or use the following command to open it in default browser after the above command is run:
allure serve build/allure-results
- TS360 Engineering Team