I am giving sample example for TestNG Framework for Selenium : (Selenium RC)
I have used Inheritance concept also.
public class Launch {
static DefaultSelenium ds;
public static void fn_launch(String br,String url)
{
ds=new DefaultSelenium("localhost",8888,br,url);
ds.start();
ds.windowMaximize();
ds.open("/");
}
}
2.GoogleSearch_Launch.java program which is given classname and method name in testng.xml
import org.testng.Reporter;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class GoogleSearch_Launch extends Launch
{
@Test
@Parameters({"browser"})
public static void resultspresent(String b) throws Exception
{
fn_launch(b,"http://google.co.in");
ds.type("q", "selenium");
ds.click("btnK");
Thread.sleep(5000);
if(ds.isElementPresent("resultStats"))
{
Reporter.log("<font color='green'><B>Results are displayed</B></font>");
}
}
}
<suite name="mysuite">
<test name="mytest_firefox">
<parameter name="browser" value="*firefox" />
<classes>
<class name="GoogleSearch_Launch"/>
<methods>
<include name="resultspresent" />
</methods>
</classes>
</test>
<test name="mytest_ie">
<parameter name="browser" value="*iehta" />
<classes>
<class name="GoogleSearch_Launch"/>
<methods>
<include name="resultspresent" />
</methods>
</classes>
</test>
</suite>
I have used Inheritance concept also.
1.Create one Launch.java as below
import com.thoughtworks.selenium.DefaultSelenium;public class Launch {
static DefaultSelenium ds;
public static void fn_launch(String br,String url)
{
ds=new DefaultSelenium("localhost",8888,br,url);
ds.start();
ds.windowMaximize();
ds.open("/");
}
}
import org.testng.Reporter;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class GoogleSearch_Launch extends Launch
{
@Test
@Parameters({"browser"})
public static void resultspresent(String b) throws Exception
{
fn_launch(b,"http://google.co.in");
ds.type("q", "selenium");
ds.click("btnK");
Thread.sleep(5000);
if(ds.isElementPresent("resultStats"))
{
Reporter.log("<font color='green'><B>Results are displayed</B></font>");
}
}
}
3.Create TestNG.xml like below
<suite name="mysuite">
<test name="mytest_firefox">
<parameter name="browser" value="*firefox" />
<classes>
<class name="GoogleSearch_Launch"/>
<methods>
<include name="resultspresent" />
</methods>
</classes>
</test>
<test name="mytest_ie">
<parameter name="browser" value="*iehta" />
<classes>
<class name="GoogleSearch_Launch"/>
<methods>
<include name="resultspresent" />
</methods>
</classes>
</test>
</suite>
Hi ..can you please show how to extend this with multiple classes ..I am creating separate class for each webpage for my application
ReplyDelete