Thursday, November 3, 2011

How To Run Selenium Script In Eclipse

-Dhivya Seethapathy
I would like to share how to run the selenium script in Eclipse through this blog . But before to list out the steps that i have followed, i would like to give a brief introduction about what exactly Selenium is?
Selenium is a portable software testing framework for web applications Selenium provides a record/playback tool for authoring tests without learning a test scripting language. Selenium is an open source tool for web application testing. This tool is primarily developed in Java Script and browser technologies and hence supports all the major browsers on all the platforms.

Selenium IDE is an integrated development environment for Selenium scripts. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests.

Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.

Why Selenium:
  • Its Open source!!
  • It’s easy to learn and implement.
  • Supports multiple browsers.
  • Supports multiple scripting/programming languages.
  • Flexible to your choice, simple record and playback (IDE), Complex Framework design to your choice by using your favorite programming language.
Here I would like to share how to run the selenium script in Eclipse.
Steps to run the selenium script in eclipse:

Step 1: Download required components
1. Download Eclipse IDE:
2. Download Selenium RC:
3. Download JUnit:

Step 2: Record and save the java selenium script
  • Open Firefox and enter the URL to browse your application.
  • Launch IDE from Tool menu.
  • Record your script.
  • Choose the programming language as JAVA and save your script. To choose the language, go to Option-> Clipboard format and select JUnit 3 (Remote Control).
  • Now you have a java code. I am making it simple and not covering scripting in detail. My motive is to share you the end to end process of using this IDE and RC to run a simple test using Eclipse. Rest you can change your script as per your need.
Step 3: Create a java project in Eclipse
 The first step in eclipse is to create a java project to do this follow the steps below
  • Launch Eclipse.
  • Click on File > New > others > select java project.
  • Enter the java project name as First Project (for example).
  • Click on finish button.
Step 4: Add selenium java client jar and JUnit library to your project
  • Right click the project and select the properties.
  • Go to java build path and select libraries tab.
  • Click add external jars.
  • Browse and add the selenium-java-client-driver.jar and junit4.jar from the source where you had saved it.
Step 5: Initiating the Selenium Server
  • Open the command prompt and run the selenium RC by below command.
  • D:\selenium-remote-control-1.0.3\selenium-server-1.0.3> java -jar selenium-server.jar
  • After entering that command, the selenium server will start in your machine.
Step 6: Adding your test script in our Project
To add your test (which you have saved earlier) as a java class file to the project (FirstProject, already saved) follow the below steps:
  • In eclipse right click the project FirstProject select new > class
  • Enter the class name as MyFirstTest.
  • Paste the recorded code from the file you had saved it.
  • Choose "com.thoughtworks.selenium.SeleneseTestCase" as its super class.
  • Finish it.
Step 7: Modifying your test script
Once you are done with your class file, it will look like,


import com.thoughtworks.selenium.SeleneseTestCase ;

public class MyFirstTest extends SeleneseTestCases


  public void setUp() throws Exception


  setUp( " " , "*firefox”);


//............ Your test script..............

 public void testUntitled() throws Exception


  assertEquals("Google", selenium.getTitle());

  selenium.type("id=lst-ib", "selenium");"name=btnG");



In case you want to run this in different browser then simply you can change your script.
setUp( " " , "*firefox”); to setUp( " " , "*chrome”); or whatever browser you need to run.

Step 8: Running your test
Finally we are ready to run our first test. To run this in eclipse you click on Run button. Select option Run as "JUnit Test”.

Note: One thing I forgot to mention that if you have eclipse with JRE version lower than 1.5 in build path, it will show some error related to version not supporting. To resolve this you have to remove the default Eclipse JRE and add JRE version 1.5 or more to System Library in Build Path.
To add this follows the steps:
  • Go to Java Build path and select Libraries tab.
  • Under this select JRE system Library.
  • Remove your default one.
  • Now click on add Library and select JRE system Library and click next.
  • Add JRE.
  • Now add this JRE to your class path.
So finally I am done with your end to end execution of java test script using selenium RC in Eclipse.


kristina said...

This is excellent post. Its having good description regarding this topic.It is informative and helpful.I have known many information from this.
data recovery vancouver

PallaviS said...

Hi....I am new to selenium... I followed the steps given above to run my selenium Script in Eclipse but I am either getting the error as "no junit tests found" or My code does not run ,it just shows in the tab as :

JUnit version 4.10

Time: 0

OK (0 tests)

Can anyone help me out with this ?

Wright Petter said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.
I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
If anyone wants to become a Java developer learn from Java EE Online Training from India.
or learn thru Java EE Online Training from India .
Nowadays Java has tons of job opportunities on various vertical industry.