February 11, 2011

Create Reports Using TestNG

February 11, 2011 7


Creating Report.....It is easy with TestNG...it will create default reports....in HTML format.


The Default feature in TestNG is it will create reports automatically..you need not to write any code...

Just run the Script with TestNG...it will automatically create a report...

First Setup the TestNg
Please go through link if you dont know how to set up...

Setting up Selenium RC & TestNG using Eclipse


Observe the screen shot before running the test...


Before Running the Test


Run the script --Run as -->TestNG --see the below screen shot...Report is generated.










Screen Shot after running the Test

After Running the Test


NOTE: You need to download the testng-5.14.10.jar file................it should be in your referenced library..

Hope it will be helpful .......




Test Suite using Test NG....

February 11, 2011 6
Test Suite using Test NG....
Most testing frameworks have the concept of grouping a set of text fixtures into a ’suite’ so that you can execute a number of related tests together.

Creating test suites with Selenium doesn’t appear to be obvious at first. Here’s a simple guide on how to create and execute suites of functional tests:



First create two scripts....Ex:Google1 and Google2


Google1.java
------------------------------------------------------------

package test;


import com.thoughtworks.selenium.*;


import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Google1 extends SeleneseTestCase{
public Selenium selenium;
public SeleniumServer seleniumserver;


@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore","http://");
seleniumserver.start();
selenium.start();
}


@Test
public void testDefaultTNG() throws Exception {


selenium.open("http://www.google.com");
selenium.windowMaximize();
}


@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();


}
}
------------------------------------------------------------

Google2.java

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

package test;


import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.*;
import org.testng.annotations.*;

public class Google2 extends SeleneseTestCase{
public Selenium selenium;
public SeleniumServer seleniumserver;

@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore","http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testGoogle2() throws Exception {

selenium.open("http://www.yahoo.com");
selenium.windowMaximize();
}

@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();

}
}




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


Now Create testsuite.xml file....

To create new XML file ..just right click on package(test--my package name) --->new-->File---testsuite.xml(any name you can give )

Sample XML file looks like this..
TestNG Suite

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite thread-count="5" configfailurepolicy="skip" verbose="1" name="suite" skipfailedinvocationcounts="false" parallel="false" annotations="JDK" data-provider-thread-count="10">   <test verbose="2" name="testsuite" junit="false" preserve-order="false"> 
    <classes> 
      <class name="test.Google1"/>
      <class name="test.Google2"/>
    </classes> 
  </test> </suite>  



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

       
  
DONE...........


How to RUN????


Right click on testsuite.xml--->Run as--->TestNG Suite.

Thats it!...your tests will run one after the another.................


Hope you enjoy this post....