Monday, 5 September 2011

Sample script using TestNG

Below is the sample script which designed based on the TestNG Annotations
public class TestNG {
public static Selenium selenium;
@BeforeClass
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.co.in");
selenium.start();
selenium.open("http://www.google.co.in");
Thread.sleep(1000);
}
@Test
public static void sample_1() throws InterruptedException {
assertEquals(selenium.getTitle(), "Google");
selenium.type("id=lst-ib", "Testing");
selenium.click("name=btnG");
Thread.sleep(1000);
}
@Test
public static void sample_2() throws InterruptedException {
assertEquals(selenium.getTitle(), "Testing - Google Search");
Thread.sleep(1000);
selenium.click("css=em");
Thread.sleep(1000);
}
@Test
public static void sample_3() throws InterruptedException {
assertEquals(selenium.getTitle(), "Software testing - Wikipedia, the free encyclopedia");
Thread.sleep(3000);
selenium.click("css=#ca-talk>span>a");
}
@AfterClass
public void tearDown() throws Exception {
selenium.stop();
}
}

No comments:

Post a Comment