-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: http://www.eclipse.org/downloads/
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,
Package.*
import
com.thoughtworks.selenium.SeleneseTestCase ;
public
class MyFirstTest extends SeleneseTestCases
{
public
void setUp() throws Exception
{
setUp( "
http://www.google.com/ " , "*firefox”);
}
//............
Your test script..............
public
void testUntitled() throws Exception
{
selenium.open("http://www.google.com/");
assertEquals("Google",
selenium.getTitle());
selenium.type("id=lst-ib",
"selenium");
selenium.click("name=btnG");
}
}
In
case you want to run this in different browser then simply you can
change your script.
setUp(
" http://www.google.com/ " , "*firefox”); to setUp(
"http://www.google.com/ " , "*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.