Let's Connect Allure Reports to a Test Project Made on Citrus Framework

Written by taacoder | Published 2023/05/09
Tech Story Tags: testing | test-reporting-tools | test-automation | software-testing | automated-testing | reporting-tool | test | testing-tools

TLDRIn this article I want to tell you how to connect and further generate Allure reports to a test project if your test project is made on the Citrus Framework. I hope you know about Allure framework, which is designed to generate reports after passing tests. The report opens on a browser page, where you can see which tests passed successfully and which did not, you can also see at which test step the expected result did not match.via the TL;DR App

In this article, I want to tell you how to connect and further generate Allure
reports for a test project if your test project is made on the Citrus Framework. I hope you know about Allure framework, which is designed to generate reports after passing tests. The report opens on a browser page, where you can see which tests passed successfully and which did not, you can also see at which test step the expected result did not match.
Since the Citrus Framework can use the TestNG or Junit engines, you need to include the Allure library according to the engine you are using. I will show the example of TestNG and the project builder we use Maven.
1. First of all, the Allure distribution must be installed locally and the path to the distribution must be written in PATH, similar to installing Maven. The
distribution can be taken from here by choosing the latest version:
https://repo.maven.apache.org/maven2/io/qameta /allure/allure-commandline
You can check if you have Allure locally with this command in cmd:
allure --version
If everything is ok, you will see the current version installed locally:
2. In the pom.xml file, you need to add the dependency “allure-testng” and two plugins “maven-surefire-plugin” and “allure-maven”, probably “maven-surefire-plugin” will already be in your list, then add the configuration, as shown below:
 <properties>
    <aspectj.version>1.9.4</aspectj.version>
    <allure.version>2.22.0</allure.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.qameta.allure</groupId>
      <artifactId>allure-testng</artifactId>
      <version>${allure.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.2</version>
        <configuration>
          <failIfNoTests>false</failIfNoTests>
          <workingDirectory>${project.build.directory}</workingDirectory>
          <argLine>
            -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
          </argLine>
          <systemPropertyVariables>
            <allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
          </systemPropertyVariables>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-maven</artifactId>
        <version>2.10.0</version>
        <configuration>
          <reportVersion>${allure.version}</reportVersion>
          <allureDownloadUrl>https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/${allure.version}/allure-commandline-${allure.version}.zip</allureDownloadUrl>
        </configuration>
      </plugin>
    </plugins>
  </build>
After Reload Maven, the connected Allure plugin will appear in the list of plugins:
3. Now we can add Allure annotations to tests as shown in the screenshot:
@Story("GET REQUEST")
public class FirstTestGetUser extends TestNGCitrusSupport {

    private TestContext context;

    @Test(description = "Getting information about user")
    @CitrusTest
    public void getTestActions() {
        this.context = citrus.getCitrusContext().createTestContext();
//        "Send GET request"
        sendRequest();
//        "Get response"
        getResponse();
    }

    @Step("Send GET request")
    public void sendRequest() {
        $(http()
                .client("restClientReqres")
                .send()
                .get("users/" + context.getVariable("userId")));
    }

    @Step("Get response")
    public void getResponse() {
        $(http().client("restClientReqres")
                        .receive()
                        .response(HttpStatus.OK)
                        .message()
                        .type(MessageType.JSON)
                        .body(new ObjectMappingPayloadBuilder(getJsonData(), "objectMapper"))
        );
    }

    public User getJsonData() {
        User user = new User();
        Data data = new Data();
        data.setId(Integer.valueOf(context.getVariable("userId")));
        data.setEmail("[email protected]");
        data.setFirstName("Janete");
        data.setLastName("Weaver");
        data.setAvatar("https://reqres.in/img/faces/2-image.jpg");
        user.setData(data);
        Support support = new Support();
        support.setUrl("https://reqres.in/#support-heading");
        support.setText("To keep ReqRes free, contributions towards server costs are appreciated!");
        user.setSupport(support);
        return user;
    }
}
We added Allure annotations @Story for class and @Step for methods in the test above.
4. After passing the test, we can generate a report by calling the "allure:serve" command:
5. Browser will automatically launch with the report page:
Thus, we connected Allure reports to our test project. If you are using the Junit engine in your test project, then you will need to follow the same steps, only you will need the “allure-junit4” or “allure-junit5” dependency. This is all. I wish you happy testing).

Written by taacoder | QA-Automation
Published by HackerNoon on 2023/05/09