Tuesday, June 18, 2013

How to generate Report in TestNG?

Generating reports is easy in TEstNG compared to other frame works. TestNG will generate reports
automatically. After running the script just refresh the project.

Right click on Project and click Refresh…then u can see a new folder test-output..expand that folder you

can see INDEX.html and emailable-report.html.

Test Case using TestNG

package Pract;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class FirstTNG {

public SeleniumServer seleniumServer;//Create a variable
public Selenium selenium;//Create a variable

@BeforeClass
public void beforeClass() throws Exception
{
seleniumServer=new SeleniumServer();//Create an object
seleniumServer.start();//start selenium server
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "http://"); //Pass arguments to selenium
selenium.start();//srat selenium server
}
@Test
public void testFirstTNG() throws Exception
{
//open google page
selenium.open("http://www.google.com");
//maximize window
selenium.windowMaximize();
Thread.sleep(5000);
}
@AfterClass
public void afterClass()
{

//stop selenium
selenium.stop();
//stop selenium server
seleniumServer.stop();
}
}