Saturday, 18 April 2015

How to Use the Project:

Two important classes which we will be using

  • ATUReportsListener - A TestNG Listener
  • ConfigurationListener - A TestNG Listener
  • MethodListener - A TestNG Listener
  • ATUReports - Used for logging the report data


The above listeners must be called in the TestNG script or used in the testng.xml file.

Using The Listener in a TestNG Script:

In a TestNG Script, use the Listener as

import atu.testng.reports.listeners.ATUReportsListener;
import atu.testng.reports.listeners.ConfigurationListener;
import atu.testng.reports.listeners.MethodListener;
@Listeners({ ATUReportsListener.class, ConfigurationListener.class,
MethodListener.class })
public class TestNGScript {
}


NOTE: If you plan to work with ATU Reporter for Selenium TestNG then follow next procedure else skip it

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


Set the driver Object to the ATUReporter as follows.

driver = new FirefoxDriver();

ATUReports.setWebDriver(driver);

This is required to retrieve the browser information and taking screenshots. If this is not set, Screenshots will not be captured.

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

Setting Index page Description, this is Optional
ATUReports.indexPageDescription = "My Project Description";

Setting Author Details, this is Optional
@Test
public void testME() {
   setAuthorInfoForReports();
}

private void setAuthorInfoForReports() {
   ATUReports.setAuthorInfo("Automation Tester", Utils.getCurrentTime(),"1.0");
}

This must be set for every test case so that the author details are set on the Test Case Report Page.
Finally, we log the Test Step execution as follows.
@Test
public void testME() {
  setAuthorInfoForReports();
  ATUReports.add("Step Desc"false);
  ATUReports.add("Step Desc""inputValue"false);
  ATUReports.add("Step Desc""expectedValue""actualValue"false);
  ATUReports.add("Step Desc""inputValue""expectedValue","actualValue"false);
}
The ATUReports class has four overloaded add methods for logging the Step information. 
The Boolean value tells whether a screenshot should be taken for the current Step.
true : Takes Screenshot
false : No Screenshot
Full Program:
package com.testcases;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import atu.testng.reports.ATUReports;
import atu.testng.reports.utils.Utils;

import atu.testng.reports.listeners.ATUReportsListener;
import atu.testng.reports.listeners.ConfigurationListener;
import atu.testng.reports.listeners.MethodListener;

@Listeners({ ATUReportsListener.class, ConfigurationListener.class,

MethodListener.class })
public class TestNGScript {


       //Set Property for ATU Reporter Configuration
       {
         System.setProperty("atu.reporter.config", "Path to the properties file");

       }

       WebDriver driver;
       @BeforeClass
       public void init() {
              driver = new FirefoxDriver();
              ATUReports.setWebDriver(driver);
              setIndexPageDescription();
       }
       private void setAuthorInfoForReports() {
              ATUReports.setAuthorInfo("Automation Tester", Utils.getCurrentTime(),
                           "1.0");
       }
       private void setIndexPageDescription() {
              ATUReports.indexPageDescription = "My Project Description <br/> <b>Can include Full set of HTML Tags</b>";
       }

            //Deprecated Methods
       @Test
       public void testME() {
              setAuthorInfoForReports();
              ATUReports.add("Step Desc"false);
              ATUReports.add("Step Desc""inputValue"false);
              ATUReports.add("Step Desc""expectedValue""actualValue"false);
              ATUReports.add("Step Desc""inputValue""expectedValue",
                           "actualValue"false);
       }


       //New Way of Logging

       @Test
       public void testNewLogs() throws AWTException, IOException {
              ATUReports.add("INfo Step", LogAs.INFO, new CaptureScreen(
                           ScreenshotOf.BROWSER_PAGE));
              ATUReports.add("Pass Step", LogAs.PASSED, new CaptureScreen(
                           ScreenshotOf.DESKTOP));
              WebElement element = driver
                           .findElement(By.xpath("/html/body/div/h1/a"));
              ATUReports.add("Warning Step", LogAs.WARNING,
                           new CaptureScreen(element));
              ATUReports.add("Fail step", LogAs.FAILED, new CaptureScreen(
                           ScreenshotOf.DESKTOP));
       }

}


Using The Listener in testng.xml File

Create a listener tag and add the Listener.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test">
    <classes>
      <class name="com.testcases.TestNGScript"/>
      <class name="com.testcases.WordPress"/>
    </classes>
  </test> <!-- Test -->
  <listeners>
  <listener class-name="atu.testng.reports.listeners.ATUReportsListener"></listener>
  <listener class-name="atu.testng.reports.listeners.ConfigurationListener"></listener>
  <listener class-name="atu.testng.reports.listeners.MethodListener"></listener>
  </listeners>
</suite> <!-- Suite -->

For More information please visit official ATU Repoter Site : http://automationtestingutilities.blogspot.in/p/reporting.html

4 comments:

  1. Hi Sai,

    Nice stuff... Very useful.

    Thanks,
    Ravi

    ReplyDelete
  2. Nice blog... Good

    ReplyDelete
  3. Hi SeleniumMansion,

    I am getting following error after running my test suite.
    Can you help me on this.


    java.io.FileNotFoundException: C:\Users\smanigam\IportalTest\ATU Reports\Results\Run_103\pieChart.js

    ReplyDelete