Tuesday, November 26, 2019

How to generate javadoc in eclipse



In Java programming, we can use the javadoc tool for generating API documentation from comments embedded in source code (Javadoc comments). However, it requires remembering various options of this tool, which is painful and time-consuming. Eclipse IDE can help to relieve this pain by providing the Javadoc Generation wizard. So this tutorial is going to walk you through the steps of generating Javadoc for a Java project using Eclipse. But first, let’s see some sample Javadoc comments:


1.     In Eclipse IDE, select Generate Javadoc… from Project menu. The Javadoc Generation wizard appears as follows:





Javadoc Generation step 1


In this dialog, do the following steps (as marked by the red numbers in the above screenshot):
  1. Specify location of the javadocprogram on your computer. Typically, it is located under JAVA_HOME’s bin directory. For example, C:\Program Files\Java\jdk1.7.0_21\bin\javadoc.exe, on Windows platform.
  2. Select the project and packages for which you want to generate Javadoc.
  3. Narrow down the source files whose Javadocs will be generated (All files are selected by default).
  4. Limit what class members which will have Javadocs generated, by choosing the visibility (access modifier). For example: If Public is chosen, then only public methods will have Javadocs generated. If Protected is chosen, then only protected and public methods will have Javadocs generated, and so on.
  5. Specify the destination directory where the Javadocs will be put in.
  6. Click Next.


The next screen allows us to specify some arguments and options for the javadoc tool, such as document title (1); document structure (2); documenting tags (3); JAR files and projects to which referenced links are generated (4); and stylesheet for the document (5):
Javadoc Generation step 2
At least you should specify the document title, leave others as default, and then click Next.
In the next screen, we can optionally specify the overview document (1); VM options (2); Extra javadoc options (3):
Javadoc Generation step 3
If you want to reuse the settings for future exports (recommended), check the option “Save the settings of this Javadoc export as an Ant script” (4) and specify the location of the generated Ant build file. This option would be helpful as we tend to generate the Javadocs many times when the project evolves.
If the option “Open generated index file in browser” (5) is checked, then Eclipse will open the generated document in its internal web browser.
Click Finish, it may take a while for Eclipse to execute the javadoc tool to parse the source files and generate all the necessary stuffs, and we end up with a nice documentation as follows (sample):
sample javadoc







How to view Javadoc in eclipse ? 

Window -> show view -> javadoc

Else 


Shift-F2 (Open External Documentation)

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