Install TestNG
1.
Launch the Eclipse IDE
2.
Navigate to
Help->Install new software
3.
In Install dialog window,
click “Add”
button.
4.
Type name as you wish, for
example :- “TestNG”
5.
Type “http://beust.com/eclipse/”
as location.
6.
Click OK.
7.
Just Click TestNG checkbox
8.
Press “Next”
button.
9.
Click “I accept
the terms of the license agreement”
10.
Click Finish.
11.
Restart Eclipse
Create testng Class
1.
Right click on your package ( for this example
package is p1)
2.
Select New-> Others->testing class
3.
Enter name of the class ( for this example name
is testng1)
4.
Click OK
5.
Copy paste below code in the opened class
package p1;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import
org.testng.annotations.Parameters;
import
org.testng.annotations.Test;
public class testng1 {
WebDriver
driver;
@Test(groups = {"Regression"},priority = 2)
@Parameters({"Browser1","url1"})
public void test1(String
sBrowser,String url) {
if (sBrowser.equalsIgnoreCase("firefox"))
{
driver=new FirefoxDriver();
}
else if (sBrowser.equalsIgnoreCase("ie"))
{
System.setProperty("webdriver.ie.driver", "C:/imp/software/IEDriverServer.exe");
driver=new InternetExplorerDriver();
}
else
{
System.out.println("Invalid browser");
System.exit(0);
}
driver.get(url);
String sTitle=driver.getTitle();
System.out.println("Title is "+ sTitle);
Assert.assertEquals("idojfioe", sTitle);
driver.close();
}
@Test(groups = {"Smoketest"},priority = 1)
@Parameters({"Browser2","url2"})
public void test2(String
sBrowser,String url) {
if (sBrowser.equalsIgnoreCase("firefox"))
{
driver=new FirefoxDriver();
}
else if (sBrowser.equalsIgnoreCase("ie"))
{
System.setProperty("webdriver.ie.driver", "C:/imp/software/IEDriverServer.exe");
driver=new InternetExplorerDriver();
}
else
{
System.out.println("Invalid browser");
System.exit(0);
}
driver.get(url);
String sTitle=driver.getTitle();
System.out.println("Title is "+ sTitle);
driver.close();
}
}
Create TestNG xml file
1.
Right click on your Project
2.
Select New-> File
3.
Enter name of the file ( for this example name
is testing.xml)
4.
Click OK
5.
Copy paste below code in xml file
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM
"http://testng.org/testng-1.0.dtd">
<suite name="Suite"
parallel="false">
<parameter
name="Browser1" value="firefox"/>
<parameter
name="Browser2" value="ie" />
<parameter
name="url1" value="http://www.google.com"/>
<parameter
name="url2" value="http://newtours.demoaut.com" />
<test
name="Selenium-AutomationSuite">
<groups>
<run>
<include name="Smoketest" />
<include name="Regression" />
</run>
</groups>
<classes>
<class name="p1.testng1"/>
</classes>
</test>
</suite>
Run the Suite
1.
Right click on xml file(testing.xml)
2.
Navigate to Run as-> TestNG Suite