Sunday, September 5, 2010

Configuring Selenium RC with TestNG using eclipse

Recently I was trying Selenium RC with TestNG using eclipse. I found it little tough without any proper step by step documentation. I took help of my collegues and completed. In fact I am not using this tool in my project but I always try to find time to work with selenium. After all you can not stop your learning :)
This tool is pretty good and rapidly taking place in market.

Any way I had successfully ran a sample test case using TestNG in eclipse with selenium RC. While it was starting but decided to post one article on “Configuring Selenium RC with TestNg using eclipse” to help testers those who want to start with same. I also maintain my blog as a database for self reference. So if you find it beneficial for you, you can write few words and if not then you can ignore :(



Finally here, step by step process to configure and run your first java test using TestNG and selenium RC in eclipse

1- Install JRE http://www.java.com/en/download/
2- Download eclipse http://www.eclipse.org/downloads/
3- Download TestNG http://testng.org/testng-5.14.zip
4- Download selenium RC http://seleniumhq.org/download/
5- Launch you eclipse

The workspace, you can select any working directory. In my case it’s “Selenium_Project”


Now clicking on Ok button, it will launch eclipse.




6- Install TestNG plugin

Go to help->install new software






Click on add. This will open a small window where you need to put location “http://beust.com/eclipse”.

Click on OK. You will see that an entry is added there. Now tick that box and click on next.



7- Add project

Click File->new->Java project

Give project name and finish


 

 
This will create project “MyProject”




8- Add TestNG jar to library

Select MyProject and then Go to (menu bar) project->properties->Java build path->Libraries



Click on add external JARs and add TestNG jar file (testng-5.14.jar) from folder which you get after downloading TestNG in step#3.



9- Add Selenium RC jar to library

Add selenium Jar file same way we have added testNG jar. Selenium jar file can be found in the “selenium-java-client-driver-1.0.1” folder which you get after downloading it in step#4.





10- Add Class file

In MyProjectt right click on scr folder then new->class


Name the class (e.g Login) and finish.


Now add your test code here under this class. As in my previous article I had mentioned that you can simply record your test using IDE and pick java code and use here. For more detail refer : http://vishalsachan.blogspot.com/2010/06/hi-folks-sorry-for-bieng-inactive-from.html



11- Run test

Run your clas file as TestNG





Ohh i forget one step here. before executing test/running class file you need to start selenium server. thia is similar to every time so i am just copying it from my previous article.



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 -server.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.


Thanks.
 

12 comments :

  1. Hi vishal nice article and very its really very helpfull. but i have one question here ..why shoud we use TestNG over Junit..

    ReplyDelete
  2. @Sumit, thanks for your comments.

    Gud question really. infact I don't know more about unit testing framework and new one. i used it for selenium test case execution in eclipse.but yes I heart and also i read that TestNG is better than Junit.
    Both are unit testing framework for java and Junit is popular one. Now TestNg come with few gud things which JUnit doe not support.
    in terms of parameterization and suite testing , TestNG is advanced one which help you in complex integration testing. also TestNG cover the entire core JUnit4 functionality as well.

    ReplyDelete
  3. @Sumit, you can read overview on TestNG here
    http://www.ibm.com/developerworks/java/library/j-testng/

    ReplyDelete
  4. Thank you so much... This is exactly what I needed.

    Richard

    ReplyDelete
  5. Hi Vishal, Thanks for you post. it is helpful. Now I would be very thank ful to you if you post some article on datadriven testing using TestNG and selenium.

    ReplyDelete
  6. JNANADEEP VARMA

    Hi,
    it is very nice and clear to under stand selenium rc accesss

    ReplyDelete
  7. Hey man, thanks so much for posting this. I'll go step by step through your instructions now. I love having the screen shots and the entire work clearly explained in a way that even beginners like myself can get it. :)

    ReplyDelete
  8. Hi, iam new to selenium ,it is very nice and clear to under stand selenium rc accesss .i practise one program on it. i want to do parameterization on selenium using junit or testng,to read data form excel or csv file.
    plz help me

    ReplyDelete
  9. Hi thanks alot for nice article

    ReplyDelete
  10. Thanks Vishal. Great post to start with. Though it would be great if you could also provide some details for framework development like test data, locators repository, etc.

    ReplyDelete
  11. Hey Vishal,
    I followed all the above steps. But there no option as "run as -> testng." in the Run as .
    Help me

    ReplyDelete