This repository contains usages examples of allure-report features.
Outline:
- Prerequisites
- Quick start
- Setup from scratch
- Allure CLI
- Allure properties
- Descriptive names
- Annotations
- Allure lifecycle
- Additional report information
- Allure server
- Allure revision
- Java 17
- Maven 3.+
- Allure commandline(CLI)
Follow the Allure CLI/Installation section for the installation instructions.
- Clone the project
git clone git@github.com:klvl/allure-features.git- Run test
mvn test -Dtest="SimpleTest#simpleTest"- Open report
allure serve- Add allure-testng, testng and maven-surefire-plugin dependencies to pom.xml
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>${allure-testng.version}</version>
</dependency>
</dependencies>- Configure aspectj in build section, maven-surefire-plugin, so steps will be displayed in report
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build> - Add a simple test
package io.klvl;
public class SimpleTest {
@Test
public void testSimple() {
doFirstTestStep();
doSecondTestStep();
}
@Step
public void doFirstTestStep() {
// your code here
}
@Step
public void doSecondTestStep() {
// your code here
}
}- Run test
mvn test -Dtest="SimpleTest#simpleTest"- Open report
allure serveThis section describes how to install and use allure-commandline.
- Using brew on macOS
brew install allure- Using npm
npm install -g allure-commandline --save-dev- Generate
allure-reportdirectory, with HTML report
cd /path/to/allure-results
allure generate- Generate
allure-reportdirectory, with HTML report, passing path toallure-resultsdirectory
allure generate path/to/allure-results/- Generate
allure-reportdirectory, with HTML report, passing path toallure-resultsdirectory and name of output folder
allure generate path/to/allure-results/ -o allure-report- Open report in a web browser
allure open- Generate
allure-reportdirectory in /temp folder and open a report
allure serveThis section describes how to set and use Allure properties.
- Create a file with the
allure.propertiesname, in thesrc/test/resourcesdirectory
allure.results.directory=target/allure-results
allure.link.issue.pattern=https://atlassian.jira.com/issue/{}
allure.link.tms.pattern=https://atlassian.jira.com/{}- Run test
mvn clean test- Generate report
allure serve target/allure-results- Add property to pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
__ <version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>- Run test
mvn clean test- Generate report
allure serve target/allure-results- Run test
mvn test -Dtest="SimpleTest#simpleTest" -Dallure.report.directory="target/allure-results/"- Generate report
allure serve target/allure-resultsThe test name, steps and suites are displayed as packages/classes/method names. This section describes how to set custom names for these attributes.
package io.klvl.descriptive;
import org.testng.annotations.Test;
public class TestActionsNamesTest {
@Test(description = "As allure user I can set descriptive name for my test")
public void testDescriptiveName() {
// your code here
}
}The approach is the same for the following annotations:
- AfterClass
- AfterGroups
- AfterMethod
- AfterSuite
- AfterTest
- BeforeClass
- BeforeGroups
- BeforeMethod
- BeforeSuite
- BeforeTest
- Test
Follow the Annotations/Step and Allure lifecycle/Step sections for information.
Follow the Annotations/Epic, Feature and Story and Allure lifecycle/Epic, Feature, Story and Suite sections for information.
Using a TestNG suite:
- Create testng.xml file and add suite name
<suite name="My test suite name" verbose="1" >
...
</suite>- Add tests to a suite(see
testng.xmlfile in a root directory of the project) - Run this suite
mvn test -DsuiteXmlFile=testng.xml- Enjoy report with suite
allure serve target/allure-resultsDynamically: follow the Allure lifecycle/Epic, Feature, Story and Suite section for information.
This section describes usages of Allure annotations.
Basic usage:
package io.klvl.descriptive;
public class StepTest {
@Step("Perform the first step")
public void firstStep() {
// you code here
}
@Step("Perform the second step")
public void secondStep() {
// you code here
}
}Parametrized step:
package io.klvl.descriptive;
public class StepTest {
@Test
public void testParametrizedSepName() {
stepParametrizedByName("email@example.com", "qwerty123456");
}
@Step("This is email: {email} parameter, and this is password: {password}")
public void stepParametrizedByName(String email, String password) {
// your code here
}
}Imagine you test authorization in your system. It is possible to sign up and sign in. There is a possibility to
authorize using regular login and password or, using your Google account. Finally, there are different cases to test,
e.g. sign up/sign in with valid credentials, sign up/sign in with invalid credentials and so on and so forth.
So, let's pick up a Sign in flow and try to split it by different levels:
- Authorization — it is a top level, and it is called
Epic - Sign in — it is a
Feature - Sign in with login and password(credentials) — it is a
Story - Sign in with valid/invalid credentials —
Testcases
You can mark your test class with corresponding annotations(@Epic, @Feature, @Story) and it will be grouped in
allure report correspondingly. You will be able to find it on the first Owerview page in the Features by stories
section. It might help to find necessary tests faster and will simplify reading of your report for a stakeholders.
Please, note that all annotations(@Epic, @Feature/@Features, @Story/@Stories) can be applied on a test method
level, not only on a test class.
Basic usage:
package io.klvl.annotations.epic.feature.story.auhthorization;
@Epic("Authorization")
@Feature("Sign in")
@Story("Sign in with credentials")
public class SignInWithCredentialsTest {
@Test
public void testSignInWithValidCredentials() {
// your code here
}
}Multiple Features and Stories:
package io.klvl.annotations.epic.feature.story;
@Epic("Some epic name")
@Features({
@Feature("The first feature name"),
@Feature("The second feature name"),
})
@Story("Some story name")
public class MultipleFeaturesTest {
}Multiple Stories:
package io.klvl.annotations.epic.feature.story;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Stories;
import io.qameta.allure.Story;
import org.testng.annotations.Test;
@Epic("Some epic name")
@Feature("Some feature name")
@Stories({
@Story("The first story name"),
@Story("The second story name"),
})
public class MultipleStoriesTest {
@Test
public void testMultipleStories() {
// your code here
}
}Default usage:
package io.klvl.annotations;
import io.qameta.allure.Description;
import org.testng.annotations.Test;
public class DescriptionTest {
@Test
@Description("The purpose of this test is to demonstrate how to add description to a report")
public void testDescriptionDefaultUsage() {
// your code here
}
}Multi-paragraph:
package io.klvl.annotations;
import io.qameta.allure.Description;
import org.testng.annotations.Test;
public class DescriptionTest {
@Test
@Description("""
The purpose of this test is to demonstrate how to add
multi-paragraph description to
allure report
""")
public void testDescriptionMultiParagraph() {
// your code here
}
}The test can have is severity and can be displayed in a report:
package io.klvl;
public class SeverityTest {
@Test
@Severity(SeverityLevel.TRIVIAL)
public void testTrivialSeverity() {
// your code here
}
}The Allure report has the following list of severities:
- TRIVIAL
- MINOR
- NORMAL
- CRITICAL
- BLOCKER
This section describes how to add link to a report.
Default usage:
package io.klvl.annotations;
import io.qameta.allure.Link;
import org.testng.annotations.Test;
public class LinkTest {
@Test
@Link("https://www.google.com")
public void testDefaultLinkUsage() {
// your code here
}
}Link with name:
package io.klvl.annotations;
import io.qameta.allure.Link;
import org.testng.annotations.Test;
public class LinkTest {
@Test
@Link(name = "my-link", url = "https://www.googgle.com")
public void testLinkAsText() {
// your code here
}
}Multiple links:
package io.klvl.annotations;
import io.qameta.allure.Link;
import io.qameta.allure.Links;
import org.testng.annotations.Test;
public class LinkTest {
@Test
@Links({
@Link("https://www.google.com"),
@Link("https://www.yahoo.com")
})
public void testMultipleLinks() {
}
}This section describes how to add link with a bug symbol to a report.
Single issue:
package io.klvl.annotations;
public class IssueTest {
@Test
@Issue("https://atlassian.jira.com/issues/KLVL_123")
public void testIssue() {
// your code here
}
}Multiple issues:
package io.klvl.annotations;
public class IssueTest {
@Test(enabled = false)
@Issues({
@Issue("https://atlassian.jira.com/issues/KLVL_123"),
@Issue("https://atlassian.jira.com/issues/KLVL_124")
})
public void testMultipleIssues() {
// your code here
}
}Issue pattern:
- Follow Allure properties section to configure link pattern
- Mark test methods with the
@Issueannotation
package io.klvl.annotations;
public class IssueTest {
@Test(enabled = false)
@Issue("KLVL_1234")
public void testIssuePattern() {
// your code here
}
}This section describes how to add link with a test management system symbol.
Single TMS link:
package io.klvl.annotations;
import io.qameta.allure.TmsLink;
import org.testng.annotations.Test;
public class TmsLinkTest {
@Test
@TmsLink("https://atlassian.jira.com/KLVL_123")
public void testTmsLink() {
// your code here
}
}Multiple TMS Links:
package io.klvl.annotations;
import io.qameta.allure.TmsLink;
import io.qameta.allure.TmsLinks;
import org.testng.annotations.Test;
public class TmsLinkTest {
@Test
@TmsLinks({
@TmsLink("https://atlassian.jira.com/KLVL_123"),
@TmsLink("https://atlassian.jira.com/KLVL_124")
})
public void testMultipleTmsLinks() {
// your code here
}
}TMS Link pattern:
- Follow Allure properties section to configure TMS link pattern
- Mark test methods with the
@TmsLinkannotation
package io.klvl.annotations;
import io.qameta.allure.TmsLink;
import org.testng.annotations.Test;
public class TmsLinkTest {
@Test
@TmsLink("KLVL_1234")
public void testTmsLinkPattern() {
// your code here
}
}The attachment type is a MIME type.
package io.klvl.annotations;
import io.qameta.allure.Attachment;
import org.testng.annotations.Test;
import java.nio.charset.StandardCharsets;
public class AttachmentTest {
@Test
public void testJsonAttachment() {
attachJsonAsByte("{ " +
"\"user\": \"klvl\", " +
"\"type\": \"attached\" " +
"}");
}
@Attachment(value = "json-attachment", type = "application/json", fileExtension = ".json")
public byte[] attachJsonAsByte(String content) {
return content.getBytes(StandardCharsets.UTF_8);
}
}package io.klvl.annotations;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class ParametersTest {
@DataProvider
public Object[][] provideTestData() {
return new Object[][] {
{ 1, "klvl" },
{ 2, "vznd" }
};
}
@Test(dataProvider = "provideTestData")
@Parameters({"id", "userName"})
public void testParameters(int id, String userName) {
// your code here
}
}This section describes how to use allure features dynamically at a runtime.
package io.klvl.allurelifecycle;
public class StepTest {
@Test
public void testStepAsLambda() {
step("Sign in", () -> {
openLoginPage();
typeEmail();
typePassword();
clickLoginButton();
});
}
}package io.klvl.allurelifecycle;
public class EpicFeatureStorySuiteTest {
@Test
public void testAllureLifecycleBreakdown() {
Allure.epic("Epic name");
Allure.feature("Feature name");
Allure.story("Story name");
Allure.suite("Suite name");
}
}Add simple description:
package io.klvl.allurelifecycle;
import io.qameta.allure.Allure;
import org.testng.annotations.Test;
public class DescriptionTest {
@Test
public void testDescription() {
Allure.description("The purpose of this test is to demonstrate how to add description to a report!");
}
}Add HTML description:
package io.klvl.allurelifecycle;
import io.qameta.allure.Allure;
import org.testng.annotations.Test;
public class DescriptionTest {
@Test
public void testDescriptionHtml() {
Allure.descriptionHtml("<div style=\"color: blue\">" +
"The purpose of this test is to demonstrate how to add HTML description to a report!" +
"</div>");
}
}package io.klvl.allurelifecycle;
import io.qameta.allure.Allure;
import org.testng.annotations.Test;
public class LinkTest {
@Test
public void testLink() {
Allure.link("https://google.com");
Allure.link("google", "https://google.com");
}
}package io.klvl.allurelifecycle;
public class IssueTest {
@Test
public void testIssue() {
Allure.issue("KLVL-123", "https://atlassian.jira.com/KLVL-123");
}
}package io.klvl.allurelifecycle;
import io.qameta.allure.Allure;
import org.testng.annotations.Test;
public class TmsLinkTest {
@Test
public void testTmsLink() {
Allure.tms("KLVL-123", "https://atlassian.jira.com/KLVL-123");
}
}package io.klvl.allurelifecycle;
import io.qameta.allure.Allure;
import org.testng.annotations.Test;
public class AttachmentTest {
@Test
public void testSimpleAttach() {
Allure.attachment("file-name", "file content");
}
@Test
public void testAddAttachment() {
Allure.addAttachment("file-name", "file-contant");
}
@Test
public void testAddAttachmentWithType() {
Allure.addAttachment("file-name", "application/json", "{}");
}
@Test
public void testAddAttachmentWithExtension() {
Allure.addAttachment("file-name", "application/json", "{}", ".json");
}
}package io.klvl.allurelifecycle;
import io.qameta.allure.Allure;
import org.testng.annotations.Test;
public class ParametersTest {
@Test
public void testParameters() {
Allure.parameter("name", "klvl");
Allure.parameter("age", 25);
// your code here
}
}- Run a test
- Generate a report
- Save
allure-report/historyfolder - Run another test
- Move saved
allure-report/hisoryfolder to theallure-resultfolder - Generate a report
The allure-report/history folder should be saved each time when report is generated to move it to the
allure-results folder before the next report generation.
- Add
categories.jsonfile to thesrc/test/resourcesfolder[ { "name": "Response status code mismatch", "matchedStatuses": ["failed"], "messageRegex": ".*The status code.*" }, { "name": "All Failed Tests", "matchedStatuses": ["failed"] }, { "name": "Broken tests", "matchedStatuses": ["broken"] }, { "name": "Known issues", "matchedStatuses": ["unknown"] } ] - Copy
categories.jsonfile to theallure-resultsdirectory using maven-resources-plugin - Run tests
mvn clean test - Generate report
allure serve target/allure-results
- Add
environment.propertiesfile tosrc/test/resourcesdirectoryBrowser=Chrome Browser.Version=63.0
- Copy
environment.propertiesfile to theallure-resultsdirectory using maven-resources-plugin - Run tests
mvn clean test - Generate report
allure serve target/allure-results
- Add
executor.jsonfile tosrc/test/resourcesdirectory{ "name": "Jenkins", "type": "jenkins", "url": "http://example.org", "buildOrder": 7, "buildName": "#7-regression-tests", "buildUrl": "http://example.org/build#7", "reportUrl": "http://example.org/build#7/AllureReport", "reportName": "Demo allure report" } - Copy
executor.jsonfile to theallure-resultsdirectory using maven-resources-plugin - Run tests
mvn clean test - Generate report
allure serve target/allure-results
There is a possibility to store all allure reports in a one place. The allure server should help with this.
You may want to get raw data of allure report and have it available at some accessible place. The allure-revision tool parses the allure-report and uploads results to a Google spreadsheet.