Tuesday 8 January 2013

Running your first selenium test case in eclipse

1- In FireFox ,Start Your Selenium-IDE from tools->Selenium IDE
2- Record your script
3- Go to File->Export test case as->Choose the programing language as JAVA and save your script.
4-Save it with .java extension

The next step is to open your eclipse and create a project.

1- Creating your java project in eclipse
The first step in eclipse is to create/add your project. To do this follow the steps below:
-> Launch Eclipse
-> Right click in navigator->Create a java project named TestProject (for example)

2- The next step is to add JUnit Libraries which consists of following steps:
-> Go to Project Properties
-> Go to Java Build Path
-> Click on Add external-jar button in Libraries tab
-> Browse and go to the location where u stored ur junit.jar.

4-Add Selenium Java Client Jar into Project:-
Once you added the Junit jars , the next step is to add selenium jar file. you can find selenium-server.jar under selenium-remote-control\selenium-java-client-driver folder what you have downloaded from

http://selenium-rc.openqa.org/download.html

To add this Jar file follow the below steps:
-> Go to Project Properties
-> Go to Java Build Path
-> Click on Libraries tab
-> Click on 'Add External Jars' button
-> Browse and add the 'selenium-server.jar' from the source where you had saved it.

5- Initiating the Selenium Test Server
To start the selenium test server, first go to the location where your selenium-server.jar is placed.
and then Run the command java -jar selenium-server.jar

This will start you selenium server.

6- Adding your test (Java class ) in our Project
To add you test (which you have saved earlier) as a java class file to the project (TestProject, already saved) follow the steps:
-> In eclipse go to create a new java class
-> Create it with name MyFirstTestCase (for example) and paste the code from the file u had saved it
-> Choose "com.thoughtworks.selenium.SeleneseTestCase" as its super class
-> Finish it

7- Modifying your test script (java class)
Once you are done with ur class file, it will look like,

Package.*
import com.thoughtworks.selenium.SeleneseTestCase ;
public class MyFirstTestCase extends SeleneseTestCases {
public void setUp() throws Exception {
setUp( " http://www.google.com/ " , "*firefox'); }

............ You test script..............
}

In case you want to run this in diff 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 with.

8- Running your test
Finally we are ready to tun our first test. To run this in eclipse you click on Run button
select option Run as "JUnit Test'

So finally I am done with your end to end execution of ur java test case using selenium RC in eclipse. For report generation using JUnit in eclipse,check my other post Thanks.

No comments:

Post a Comment