Starting Selenium Testing with Java and JUnit
This is interesting way of testing web applications, most of the web applications are constantly changed due to new requirements wanted by your beloved business analyst, as most of these guys are technologically handicap changes are asked for even at the UAT stage. The victims of such foolish actions are the hardworking developers, who need to make sure the functionalities are coded and tested. The testing teams do not report bugs coming out of these changes as they do not complete the regression tests on the previously verified functionalities.
So to done away with those saturday evening call that things are not working when sanity done by the users after production deployment selenium can be very helpful. In this post i will let you show you how to setup the selenium testing framework on your machine and run your first JUnit test.
a) We need to download some files to get the framework up and running, click to this link to get to the selenium download page.
Download the three files and get the jars from them. Also get the hamcrest and junit.jar from the Junit download page. Make a user library in eclipse and name it appropriately.
In eclipse, create a Java project.
As you can see in the picture, the project is a simple Java project with a user library named as Selenium and the test file a class with junit tests. The Selenium lbrary contains all the jars present in downloaded files from the selenium download page.
Lets get to program.
- import java.io.File;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.ie.InternetExplorerDriver;
- public class SeleniumTest {
- WebDriver driver;
- @Before
- public void setup() throws Exception{
- File file = new File("G:/development/selenium/IEDriverServer.exe");
- System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
- driver = new InternetExplorerDriver();
- }
- @After
- public void tearDown() throws Exception{
- driver.quit();
- }
- @Test
- public void test(){
- driver.navigate().to("https://www.google.com");
- }
- }
You need to know that testing a web application is similar to JUnit tests, we get to a page and assert that certain elements on the web page have certain values at certain times. We can provide values to the page and observe its behaviour.
In the above program, we are using @Before to setup the driver, here Internet Explorer driver is being used. @After to breakaway the resources, using the quit method.
The actual test marked by @Test, the test simply gets us to the google.com.
When you run the test you will get these two pages coming one after another.
Thats it for this post, some more posts on this topic to follow. Leave comments if you want to.



The Article on Starting Selenium Testing with Java and JUnit is nice. It give detail information about it .Thanks for Sharing the information Selenium Testing Testing.
ReplyDeletemobile application testing