Tuesday, February 1, 2011

TestNG

TestNG is yet an another framework to work in JAVA.


there are many features available in the TestNG that you will not find in JUnit.


TestNG Annotations
Following are some of the annotations we have used in our example
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.
@AfterClass: The annotated method will be run after all the test methods in the current class have been run.
@Parameters: Describes how to pass parameters to a @Test method.
@Test: Marks a class or a method as part of the test.

If you look at the @BeforeClass and @AfterClass annotation they are same as of JUnit, the only difference is the method annoted with @BeforeClass or @AfterClass need not to be static as compared to the JUnit.



Google.java



import static org.testng.AssertJUnit.*;
import org.testng.annotations.*;
import com.thoughtworks.selenium.*;
public class Google {
private Selenium selenium;
@BeforeClass
public void startSelenium() {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com");
selenium.start();
selenium.open("http://www.google.com");
}
@AfterClass(alwaysRun=true)
public void stopSelenium() {
this.selenium.stop();
}
@Test(groups="search")
public void googling() {
try {
selenium.type("name=q", "sasidhar");
selenium.click("name=btnG");
selenium.waitForPageToLoad("60000");
assertTrue(selenium.isTextPresent("sasidhar"));
} catch (SeleniumException e) {
fail(e.getMessage());
}
}
}




Then compile the above program

No comments:

Post a Comment