Skip to main content

Reporting in Selenium


Method 1 : Maven - Testng - Surefire report

The project will be created in Maven with SureFire Plugin and SuiteXmlFile tag in the POM.xml . The testng.xml will be called in the POM.

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <version>2.18.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>
                            C:\Users\har\InterviewTraining\MavenXslt\testng.xml
                        </suiteXmlFile>
                    </suiteXmlFiles>
                    <testFailureIgnore>
                        true
                    </testFailureIgnore>
                </configuration>
            </plugin>

The Report will be generated in the target/surefire-reports folder


Report will be generated like below ( index.html)





Method 2 : Maven - Testng - XSLT report


Step 1: Generate above report using Maven - Surefire plugin

Step 2 : Download testng-xslt project from below link or some other link which is available. Use Download Zip link on this to download the project in zip file

https://github.com/prashanth-sams/testng-xslt-1.1.2



Step 3 : Copy the "testng-results.XSL" from the TestNG package to your base directory i.e, your project folder. "testng-results.XSL" will be available at [..\testng-xslt-1.1.2-master\src\main\resources]



Step 4 : Create a lib folder in you project and put copy the saxon library from (testng-xslt-1.1.2-master\testng-xslt-1.1.2-master\lib) to your project lib folder.

Step 5: .Now add build.xml in your maven project with below content. This is just to run the "testng-xslt-report"  target.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>

<project name="anttest" default="usage" basedir=".">  

<!-- ========== Initialize Properties =================================== -->
    <property environment="env"/>
    <property name="ws.home" value="${basedir}"/>
    <property name="ws.jars" value="${ws.home}/lib" />
    <property name="test.dest" value="${ws.home}/build"/>
    <property name="test.src" value="${ws.home}/src"/>
    <property name="test.reportsDir" value="${ws.home}/Reports"/>
    <property name="test.resources" value="${ws.home}/src/test/resources"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<pathelement location="${ws.home}"/>
<pathelement location="${test.resources}"/>
    <fileset dir="${ws.jars}">
      <include name="*.jar"/>
    </fileset>
</path>

     <target name="testng-xslt-report">
        <delete dir="${basedir}/testng-xslt">
        </delete>
        <mkdir dir="${basedir}/testng-xslt">
        </mkdir>
        <xslt in="${basedir}/target/surefire-reports/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
            <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
            <param expression="true" name="testNgXslt.sortTestCaseLinks" />
            <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
            <param expression="true" name="testNgXslt.showRuntimeTotals" />
            <classpath refid="testcase.path">
            </classpath>
        </xslt>
    </target>
</project>


Step 6 : Now run your Maven project with mvn clean compile test , which will generate the testng-results.xml in target directory



Step 7 : Now you run ANT target "ant testng-xslt-report"

Step 8 : Above step will generate index.html in the testng-xslt report.

Step 9 : Open index.html in web browser.





Method 3 : Customized HTML report

Customized HTML report can also be generated by writing a java code generated HTML file at the run time, based upon the steps/status of test cases.

Method 4 : Test Report in Excel file

The status of Test Cases can also be sent to Excel file to generate a report.









-----------------------------------------------------------------------------------------------------------

XSLT report in Selenium

 

 

XSLT: XML STYLESHEET LANGUAGE TRANSFORMATION

When we execute our project using TestNg.xml, it automatically create a basic html report and testng-results.xml.
XSLT is going to use this testing-result.xml and transform into better htmlreport


Steps to Generate XSLT reports

Step1: Create a project having test cases like

  • Pass
  • Fail
  • Skip
 with TestNG annotations .

Create 4 .java files such a way that: 2 successful, 1 skipped and 1 failed on run

testcase1: pass


package test;

import org.testng.annotations.Test;
import org.testng.annotations.Test;

public class passtc {

    @Test
    public void passresult()
    {
        System.out.println("Pass");
    }

}

 

testcase2: pass


package test;

import org.testng.annotations.Test;

public class passtc1 {

    @Test
    public void show()
    {
        System.out.println("Testcase2 passed");
    }

}

 

testcase3: failed


package test;

import org.testng.annotations.Test;
import org.testng.AssertJUnit;
import org.testng.Assert;
import org.testng.annotations.Test;

public class failtc {

    @Test
    public void failresult()
    {
        System.out.println("Fail");
        AssertJUnit.assertEquals("Fail", "Pass");
    }

}



testcase4: skipped


 package test;

import org.testng.SkipException;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class skiptc {

    @BeforeTest
    public void intlize()
    {
        System.out.println("this test will skip");
   
    }

    @Test
    public void skip()
    {
        throw new SkipException("Skipped");
    }

}
 



After creating above testclasses your project look like below


   

testng.xml 

 
Right click on the project, select "TestNG" and click on "Convert to TestNG" to create the testng.xml and place under project folder.  

ANT build

Download the latest zip file from here
Extract and keep it in a easily accessible folder and follow below steps:


CLICK ON THIS AND DOWNLOAD THIS APACHE-ANT -1.9 ZIP FILE


EXTRACT IT INTO ANY DIRECTORY OF YOUR SYSTEM
I HAVE EXTRACT IT INTO MY E:FOLDER.YOU CAN EXTRACT IT WHERE YOU WANT.
CONFIGURE PATH:
AFTER EXTRACTING NOW YOU HAVE TO CONFIGURE ANT INTO YOUR SYSTEM.WE NEED TO SET OUR ENVIRNMENT VARIABLE.BEFORE SETTING ENVIORNMENT VARIABLE LET ME SHOW YOU MY APACHE BIN DIRECTORY PATH.

GO TO COMPUTER>RIGHT CLICK>PROPERTIES>ADVANCE SYSTEMS SETTING
CLICK ON ENVIONMENT VARIABLE
CLICK ON NEW
ADD A NEW SYSTEM VARIABLE.GIVE THE PATH UPTO YOUR BIN FOLDER OF APACHE

NOW SET PATH APACHE PATH INTO THE EXISTING DIRECTORY.FIRST SEARCH PATH AND CLICK ON EDIT>THEN EDIT PATH AS ;%ANT_HOME%\BIN.NOW CLICK ON OK
GO TO CMD PROMPT AND WRITE ANT -VERSION.

ANT IS INSTALLED SUCCESFULLY.

BUILD.XML AND TESTNG-RESULTS.XSL:


CLICK HERE TO DOWNLOAD


DOWNLOAD TESTNG-XSLT JAR  HTTPS://GITHUB.COM/PRASHANTH-SAMS/TESTNG-XSLT-1.1.2

Xslt

BUILD.XML: 

OPEN BUILD.XML FILE AND GIVE THE LIBS PATH (WHERE YOU HAVE TESTNG-XSLT JAR AND SELENIUM JARS).


EXECUTE BUILD.XML IN COMMAND PROMPT

CHANGE THE DIRECTORY TO YOUR PROJECT PATH.

TYPE ANT





TYPE "ANT COMPILE"



TYPE "ANT RUN"



 IMPORT TESTNG-RESULT.XSLT 

IMPORT TESTNG-RESULT.XSLT INSIDE XSLT PACKAGE.



FINALLY TYPE "ANT MAKEXSLTREPORTS" 


AFTER EXECUTING THE ABOVE COMMAND THE  XSLT_REPORTS FOLDER WILL  GENERATE
 INSIDE YOUR PROJECT DIRECTORY


OPEN INDEX.HTML 




 

 THANKS.

IF YOU DOUBT PLEASE LEAVE YOUR COMMENTS BELOW.

Comments

Popular posts from this blog

API Testing With Selenium WebDriver

REST API Testing Framework We will be creating a simple Rest Testing Framework in Java and JUnit that could be used for any testing scenarios. Rest Testing Framework Overview The framework should be able to execute the basic REST operations (GET, POST, PUT, PATCH, DELETE) and perform the validations on the code, message, headers and body of the response. The completed code can be accessed from my  GitHub account   from where you can collect and make modifications based on your requirements. Design We will be having three classes for the framework (in package com.axatrikx.controller ) RestExecutor  : Performs the HTTP operations using Apache Http Client RestResponse  : A javabean class to hold our response values (code, message, headers, body) RestValidator  : Validates the response with the expected values The package  com.axatrikx.test  holds the test scripts. Note: I will be using ‘ json-server ‘ to f...

Autonium

About Autonium Autonium is a test automation framework for web applications. This framework is built by using Java and Selenium. It uses Maven project structure. Easy to understand and use it. Having basic idea on Java, Selenium, Maven and TestNG is good enough to start with Autonium. Let’s start Automation with Autonium --------------------------------------------------- Advantages Provides support to all major browsers –  Firefox, Chrome, IE and Safari . Capability of executing scripts on  Remote Machines  by using Selenium Server. Users can make use of Selenium Web driver methods and Autonium methods. Autonium simplifies  Test data management . Test data can be read from properties files. Scripts can be developed without  hard coding  test data . Identifiers can also be read from properties files and  hard coding   of identifiers can be avoided. Test data and Identifier v...