Here is an example explaining how to use JUnit3 with Selenium i.e using JUnit3 to run selenium test.
//GoogleTestJunit3.java
This test launches firefox browser to run the google search test.The selenium session is started in setUp() method which is called before every test run and ends with tearDown() method which is called after every test run.Since setUp() and tearDown() are called before and after every test run so we can use only one test method to be run in each class if you want to start and stop selenium sessions with setUp() and tearDown() methods.Multiple tests with this fashion is a drawback i.e if you want to write multiple tests in a same class selenium session 'll start and stop for every test run.
//GoogleTestJunit3.java
- package test.example;
- import junit.framework.TestCase;
- import com.thoughtworks.selenium.DefaultSelenium;
- import com.thoughtworks.selenium.Selenium;
- /**
- * Search Google example.
- *
- * @author aksahu
- */
- public class GoogleTestJUnit3 extends TestCase{
- Selenium selenium;
- public void setUp(){
- selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
- selenium.start();
- selenium.windowMaximize();
- }
- 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");
- }
- public void tearDown(){
- selenium.stop();
- }
- }
This test launches firefox browser to run the google search test.The selenium session is started in setUp() method which is called before every test run and ends with tearDown() method which is called after every test run.Since setUp() and tearDown() are called before and after every test run so we can use only one test method to be run in each class if you want to start and stop selenium sessions with setUp() and tearDown() methods.Multiple tests with this fashion is a drawback i.e if you want to write multiple tests in a same class selenium session 'll start and stop for every test run.
No comments:
Post a Comment