Here is an example explaining how to use TestNG with Selenium RC i.e using TestNG to run selenium rc tests.
//GoogleTestTestNG.java
This test launches firefox browser and executes the google search test.The selenium session is started in startSelenium() method which is called before any test run in the test class and ends with stopSelenium() method which 'll call after the tests run.
//GoogleTestTestNG.java
- package test.example;
- import org.testng.annotations.AfterClass;
- import org.testng.annotations.BeforeClass;
- import org.testng.annotations.Test;
- import com.thoughtworks.selenium.DefaultSelenium;
- import com.thoughtworks.selenium.Selenium;
- /**
- * Search Google example.
- *
- * @author aksahu
- */
- public class GoogleTestTestNg {
- Selenium selenium;
- @BeforeClass
- public void startSelenium(){
- selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
- selenium.start();
- selenium.windowMaximize();
- }
- @Test
- public void testGoogleSearch(){
- selenium.open("/");
- selenium.type("id=lst-ib", "selenium");
- selenium.click("name=btnK");
- selenium.click("link=Selenium - Web Browser Automation");
- selenium.waitForPageToLoad("30000");
- }
- @AfterClass
- public void stopSelenium(){
- selenium.stop();
- }
- }
This test launches firefox browser and executes the google search test.The selenium session is started in startSelenium() method which is called before any test run in the test class and ends with stopSelenium() method which 'll call after the tests run.
No comments:
Post a Comment