Friday, December 20, 2013

Develop test cases using the Selenium WebDriver

Welcome back!  Today we will make some tests using Selenium WebDriver. All you need is to download Eclipse IDE For Java EE Developers and Selenium from our previous post. 

First step: Installation and configuration

Once you have downloaded Selenium you have to decompress the downloaded file.  You will find two different files .jar with the name of selenium -java-2.35.0.jar and selenium-java-2.35.0-srcs.jar. The name can change depending of the downloaded version of the tools, these files have to be copied on the libs folder of selenium.

Now that you have copied the files in the libs folder, you can create a new project in eclipse in which you can make some basic tests with the help of selenium. First you go to eclipse then you go to File->New->Java Project.

The next window will be displayed. Here you are going to write the project’s name. In this example the name of the project is “Tests”.

Then, you click on the Next button and you go to libraries.

You will see the next window, here you click on the button that says Add External JARs, a window will appear in which you have to select all the files .jar that are in the libs folder of selenium.

Once you have selected all the .jar files of selenium, you have to click on the finish button. The new project will appear at the left side of the screen.  In the left side of the screen you will find a section that says Referenced Libraries that contains all the files that you have selected previously.

The configuration is done :)  

We can start to write the tests, hooray!

Second step: Writing the test cases

Now we will do two simple tests:

  • search a text in google 
  • obtain the title of the Google page.

To do the tests go to File->New->JUnit Test Case.

You will see a new window in which you will have to write the name of the JUnit Test Case, in this case the name is “prueba” (it means test in our native language ;) ).

Once you have created the file, you will be able to make the test, first you create the test that opens firefox, goes to the google page and search ‘Selenium WebDriver’. To do this you have to import the following libraries:

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

To do the test you can use the following code, this test after searching  ‘selenium WebDriver’ obtains the title of the page and compare if the title of the page isSelenium WebDriver - Buscar con Google’, if the title is different the test will fail:

 public void test() throws InterruptedException {
  WebDriver firefox_driver = new FirefoxDriver();
  WebElement search = firefox_driver.findElement("q"));
  search.sendKeys("Selenium WebDriver");
  WebElement search_button = firefox_driver.findElement("gbqfb"));;
  if(!firefox_driver.getTitle().equals("Selenium WebDriver - Buscar con Google")){
   fail("Test Fail");

Now to do the test that obtains the title of the page and prints it in the console you can use the following code, this test will fail if the title of the page is not Google:

 public void title() {
  WebDriver firefox_driver = new FirefoxDriver();
   fail("Test Fail");

So that´s it for writing the tests, in the following post we will use ANT to execute them and then we will automatize the execution of our testcases using Hudson.

See you soon!


  1. The blog gave me an idea to develop test cases using selenium Thanks for sharing it
    Selenium Training in Chennai

  2. Great post and i have one doubt. How to develop a template for test cases?. Please can anyone explain. Software Testing Training in Chennai

  3. Great sharing about test cases. keep sharing. want to learn selenium training with best placement support reach us Selenium Training in Chennai

  4. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging
    software testing course in chennai

  5. Nice post.Thank you so much for sharing.Yiioverflow is a web development company.We have well expert team in Angular JS, Ionic, Yii Framework, Node JS, Laravel, PHP, MySQL, and WordPress.If you want a developer visit..

  6. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training

  7. Visit us at BGAOC and good luck will smile at you a casino online top Win now or never.

  8. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
    Data Science Training in Chennai | Data Science Course in Chennai
    Python Course in Chennai | Python Training Course Institutes in Chennai
    RPA Training in Chennai | RPA Training in Chennai
    Digital Marketing Course in Chennai | Best Digital Marketing Training in Chennai

  9. I am obliged to you for sharing this piece of information here and updating us with your resourceful guidance. Hope this might benefit many learners. Keep sharing this gainful articles and continue updating us.
    Blue Prism Training in Chennai
    Blue Prism Course in Chennai
    German Classes in Chennai
    Cloud Computing Training in Chennai
    Data Science Course in Chennai
    Devops Training in Chennai
    Blue Prism Training in Porur
    Blue Prism Training in Adyar

  10. After looking over a few of the blog articles on your site, I honestly like your way of writing a blog. I added it to my bookmark webpage list and will be checking back in the near future. keep share more..
    AngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery