Here is an example explaining how to use JUnit4 with Selenium RC i.e using JUnit4 to run selenium rc tests.
//GoogleTestJunit4.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.
//GoogleTestJunit4.java
- package test.example;
- import org.junit.AfterClass;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import com.thoughtworks.selenium.DefaultSelenium;
- import com.thoughtworks.selenium.Selenium;
- /**
- * Search Google example.
- *
- * @author aksahu
- */
- public class GoogleTestJUnit4 {
- 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