Monday, June 14, 2010

Testing web application using Selenium RC with eclipse

Hi Folks , sorry for bieng inactive from last few months. I was really busy these days. I respect all of yours comments and query. In fact I am not working with Selenium now but as you people asked me some queries on Selenium RC with eclipse in one of my previous article http://vishalsachan.blogspot.com/2009/09/using-selenium-rc-in-your-java-project.html

I am planing to write a use full article here where I will cover end-to-end testing your web application using Selenium in Eclipse. This is infact a detail version of my prev article mentioned above.

As said earlier I am not in touch with Selenium i.e I am not using this currently, so I will try my best to use my memory and old days 'R and D' to get it completed with high quality and quantity. Huaaaa

Here I will start with selenium IDE but will not go in detail as asuming that you people are comfirtable with IDE part. If you need any help in IDE then you can refer to other articles in this blog only.

Record and save you java script
1- Open Firefox and enter the URl to browse your application
2- Launch IDE from Tool menu.
3- Record your script
4- Choose the programing language as JAVA and save your script. To chose the language go to Option-> Clipboard formate and select Java-Selenium RC

Now you have a java code saved in your disk. I am making it simple and not covering scripting in detail. My motive is to teach 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.
Now we have ur test with us.
The next step is to open your eclipse and create a project.

1- Creating you java project in eclipse
The fiste stpe in eclipse is to create/add your project. To do this follow the steps below:
   -> Launch Eclipse
   -> Creat a java project named TestProject (for example)

2- Add Junit Library to your project
The next step is to add Junit Liabraries which consiste of following steps: 
  ->  Go to Project Properties
  ->  Go to Java Build Path
  ->  Click on Libraries tab
  ->  Click on 'Add Library' button
  ->  Select 'Junit' option from list and click on next
  ->  Select version 'Junit4' from drop down and click on finish.

4-Add Selenium Java Client Jar into Project:-
Once you added the java liabraries , the next step is to add selenium jar file. you can find it under selenium-remote-control-1.0-beta-1\selenium-java-client-driver-1.0-beta-1 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-java-client-driver.jar' from the sourse where you had saved it.

5- Initiating the Selenium Test Server
To start the selenium test server, first go to the location where your JRE is placed. For example
C:\Program Files\Java\jre6\bin\
and then Run the command java -jar selenium-server.jar
here it is supposed that you have placed your selenium -erver.jar file in same location. In case if you have placed it in other location you can run it in following way:

C:\Program Files\Java\jre6\bin\java -jar jar “E:\SELENIUM\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1\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://vishalsachan.blogspot.com/ " , "*firefox'); }

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

In case you want to run this in diff browser then simply you can change your script
setUp( " http://vishalsachan.blogspot.com " , "*firefox'); to setUp( " http://vishalsachan.blogspot.com " , "*chrome'); or whatever browser you need to run wid.

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'

Ohh ya one thing I forgot to mention that if you  have eclipse with JRE version lower than 1.5 in Build Path
then might be the case when you run the test , it will show some error related to version not suporting. so for this remove the default Eclipse JRE and add JRE version 1.5 or mor to System Library in Build Path.
To add this follow 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 ur java test using selenium RC in eclipse. Thanks.

14 comments :

  1. Excellent Post Vishal..I think after reading this article every one would be confident to work on selenium which is on demand now a days.My most of the doubts are now clear after reading this post..

    ReplyDelete
  2. Hats Off to u Vishal..I was working on manual testing from last 4 years and always wanted to work on some automation like selenium..and this post was became very benificial for me to crack the interviews and to clear my concepts in automation..Excellent One :-)

    ReplyDelete
  3. Dear Vishal,

    It would be realy helpful in any Java Enviorment. Keep it up.

    Thanks.
    Regards,
    --
    Jitendra Singh
    HCL

    ReplyDelete
  4. Hi Vishal,

    Excellent article, it's been long that i have messaged u. Since i started blogging again , My blog now has the best of testing articles across the web therefore adding urs too :)Do let me know if you want to add anything.

    My Blog: http://go-gaga-over-testing.blogspot.com/

    Best Regards,
    Aditya Kalra

    ReplyDelete
  5. Thanks a lot Vishal. I was till now (from past few months) working only with PHP-Selenium. But wanted to schedule and start with eclipse. This article was just a spoon-feeding for the beginners. It helped me to start now.

    Grüße,
    Anita

    ReplyDelete
  6. Hi Vishal,

    Thanks for the above article and it was really helpful. However i am in a situation where i need to run my .py files (exported from selenium IDE) using the eclipse to test on various browsers.
    Will this be possible and how?
    Looking forward to your reply!!!

    Thanks
    A

    ReplyDelete
  7. Thanks man. You have solved my problem. I was in trouble as I was not getting enough details in this regard to crack my interview. But now after reading your post I have cleared all my doubts.

    ReplyDelete
  8. Good one, Please provide some practical exmaples like data driven suing excel file...

    ReplyDelete
  9. Eventhough i have added all jar files it shows below error messages

    The field SeleneseTestCase.selenium is deprecated TestProject/src MyFirstTestCase.java line 21 1322046629562 247

    ReplyDelete
  10. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. thank u


    Selenium Training in Chennai

    ReplyDelete
  11. Software testing basically helps to discover the defect in the software and its configuration. It helps to trace the bugs and errors in your software and recognizing the capacity and the accuracy of the system.STC Technologies

    ReplyDelete
  12. Rize Corp technology innovation proficiency goes far beyond what is typically expected of a web development company.Our team are capable of performing the most complicated and ambitious projects.

    Rize

    ReplyDelete
  13. Hello , Can you Please elaborate that How to design a Hybrid frame work in selenium RC.
    And also want to know that how to Store the Result in an Excel as per test cases.

    Looking for your need full help:)

    ReplyDelete
  14. It can be the bаsіѕ for the аutomotivе transmіѕsion.
    Hοwеver, it is impoгtant that you lеаrn hoω to κeеp уour own fеelings аt bay.
    If bеaring іs utilized іn corгosiνe surroundings, it requirements the bearіng metal tο gеt corrosіon resiѕtance.


    Hеre iѕ my pаge ... NSK Spherical Roller Bearings

    ReplyDelete