Monday, 28 September 2015

GENERATE CUSTOMIZED EXCELREPORTS USING TESTNG IN SELENIUM

Download the Jar from here ExcelReportGenerator. Add this Jar into your project BuildPath.

Step1 : Create a Package ‘ExcelResults’ under your Project.

step2 :Create  the testcases which you’d like to automate using TestNg. (by using @Test,BeforeTest,…….) as Shown.

import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;

public class Test_98 {
@Test(priority = 1)
public void VerfyingTestCaseID_001() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 2)
public void VerfyingTestCaseID_002() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 3)
public void VerfyingTestCaseID_003() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 4)
public void VerfyingTestCaseID_004() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 5)
public void VerfyingTestCaseID_005() {
System.out.println(“test”);
System.out.println(“this”);
Assert.assertEquals(“validText”, “InvalidText”);
}

@Test(priority = 6)
public void VerfyingTestCaseID_006() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 7)
public void VerfyingTestCaseID_007() {
System.out.println(“test”);
System.out.println(“this”);
Assert.assertEquals(“validText”, “InvalidText”);

}

@Test(priority = 8)
public void VerfyingTestCaseID_008() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 9)
public void VerfyingTestCaseID_009() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 10)
public void VerfyingTestCaseID_010() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 11)
public void VerfyingTestCaseID_011() {
System.out.println(“test”);
System.out.println(“this”);
Assert.assertTrue(false);
}

@Test(priority = 12)
public void VerfyingTestCaseID_012() {
System.out.println(“test”);
System.out.println(“this”);
Assert.assertTrue(false);

}

@Test(priority = 13)
public void VerfyingTestCaseID_013() {
System.out.println(“test”);
System.out.println(“this”);
}

@Test(priority = 14)
public void VerfyingTestCaseID_014() {
System.out.println(“test”);
System.out.println(“this”);
}
}

Step3 : Create a testng.xml file under your Project as Shown.

<suite name=”Build 2.0.1?>

<test name=”TestReport”>
<classes>
<class name=”Test_98? />
</classes>
</test>
</suite>

Now Run the testng.xml file.

Step 4 : Now Create a Class ‘ExcelGenerate’  and paste the following code.

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;
public class ExcelGenerate {

public static void main(String[]args) throws ParserConfigurationException, IOException, SAXException
{
ExcelReportGenerator exe= new ExcelReportGenerator();
exe.GenerateExcelReport(“YourTestName.xlsx”);

System.out.println(“Reports Generated in ExcelResults Package.Please refresh the packages”);

}
}

Step5 :Refresh the Package ‘ExcelResults’

No comments:

Post a Comment