Tuesday, November 26, 2019

Allure report system Configuration with Selenium Project

Allure report system gives a rich reporting format https://docs.qameta.io/allure/


Allure report system Configuration :

1. Modify pom.xml with below configuration:

Properties Section

Allure TestNG Dependency

Build Section




The final pom.xml is below:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>Flipkart</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Flipkart</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <aspectj.version>1.8.10</aspectj.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.7.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>3.3.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>4.1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<!--        <dependency>-->
<!--                <groupId>com.fasterxml.jackson.core</groupId>-->
<!--                <artifactId>jackson-databind</artifactId>-->
<!--                <version>2.9.5</version>-->
<!--            </dependency>-->
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>ProjectExecutor.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <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>
</project>


Feature-1: Display Name

In order to make our test report more understandable, I used description property of @test annotation.
@Test (priority = 0, description=”Invalid Login Scenario with wrong username and password.”)
Also, you can add an additional description with @Description annotation:
@Description(“Test Description: Login test with wrong username and wrong password.”)
The result will be shown as below:

Feature-2: Steps

Steps are test actions in our test scenarios. They can be used for any testing scenario. Thus, we need to define steps in a generic place in our test project. In order to define a step, we need to use @Step annotation. In our project, steps are defined at our page classes. LogintoN11verifyLoginUserNameverifyLoginPassword, all of these methods are our test steps. Therefore, we need to add @Step annotation above these methods as shown below. Here, we can also pass parameters with {} syntax. For example, at first method, {0} is first parameter – username{1} is second parameter – password.
LoginPage Steps:
HomePage Steps:
Here are the results. They will look on the report as like below image.

Feature-3: Attachments

We can add attachments to our reports by using @Attachment annotation. It can return String, byte [], etc. For example, if we want to attach a screenshot we should return byte[]. Also, I need to add @Listeners({ TestListener.class }) declaration at the top of the test class.
In TestListener class, I wrote two attachment method for string attachment and screenshot attachment.
And, I called those methods when a test failed as shown below.
The result will be like below in the report.

Feature-4: Links

You can integrate your defect tracking system and test management tool with allure by using @Link annotation as shown below. [1]
In order to specify the link pattern you can use the system property in the following format: allure.link.my-link-type.pattern=https://example.org/custom/{}/path. Allure will replace {} placeholders with the value specified in the annotation. For example:
I will not use this feature in my test so I cannot show you any result for this.

Feature-5: Severity

We can order test by severity by using @Severity annotation. I used this feature in tests as shown below.
and the result will be like that.

Feature-6: Behaviour Driven Reporting (Features and Stories)

We can group tests with @Epic@Feature, and @Stories annotations.
Here is the report result in Behaviors Section.
and that’s all. šŸ™‚ Now, we should run the test and generate the report.

Step-3: Run the Test and Generate Allure Report

You can run the test with maven command. In order to do this in IntelliJ first, you should click configurations.
Select maven, and write the maven “clean test” command as shown below and then click OK.
Now, we can run the code by clicking the green run icon.
Now, it is time to generate the report!
In order to generate a report, we should install Allure command-line interpreter.
  1. Download the latest version as a zip archive from bintray.
  2. Then, click the Files tab and then download the .zip file for windows. For Linux, you can download .tgz file. For Mac use brew to install allure.
  3. Unpack the archive to allure-commandline directory.
  4. Navigate to bin directory.
  5. Add allure to system PATH.
If you are using MAC, then you can install allure with below Brew command.
and finally, open a command prompt screen, go to the project directory, and write below command!
allure serve allure-results
and, you will see the beautiful Allure Test Report as shown below.

Dashboard

Categories

Suites

Graphs

Timeline

Behaviors

Packages



No comments:

Post a Comment