Testing web application using Selenium RC with eclipse - Vishal Sachan



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 in fact a detailed version of my prev article mentioned.

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.

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 format 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 first step in eclipse is to create/add your project. To do this follow the steps below:
   -> Launch Eclipse
   -> Create a java project named TestProject (for example)

2- Add Junit Library to your project
The next step is to add Junit Libraries which consist 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 libraries , 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 assumed 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.

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 is that if you  have eclipse with JRE version lower than 1.5 in Build Path
then it might show some error related to version not supporting. So remove the default Eclipse JRE and add JRE version 1.5 or more 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 java test using selenium RC in eclipse. Thanks.

Source: Testing web application using Selenium RC with eclipse- Vishal Sachan

Comments

  1. i want to use selnium tool in nokia mobile browser can i use it

    ReplyDelete
  2. AFAIK Selenium has specific drivers for testing mobile apps , here is the list:

    For Android:
    http://code.google.com/p/selenium/wiki/AndroidDriver

    For IPhone:
    http://code.google.com/p/selenium/wiki/IPhoneDriver

    http://code.google.com/p/selenium/wiki/WebDriverForMobileBrowsers

    Hope this helps!

    ReplyDelete
  3. can you guys suggest me , I wann to use Iphone and Android Selenium testing using C#(.Net) ? how can i do that

    ReplyDelete
  4. Hi...

    Am exploring on selenium. Can any one help me how to use user-extensions in slenium RC.
    I browsed in net, but am not left with any conclusion of where to keep the userextension functions and how to use those extensions inside test script.

    Kindly help me..

    Thanks in advance..
    Raj

    ReplyDelete
  5. Anonymous25/6/13

    I like the helpful info you provide in your articles. I will bookmark your blog and check again here frequently.

    I am quite sure I will learn lots of new stuff right here!
    Best of luck for the next!

    Feel free to visit my site how to install

    ReplyDelete
  6. Anonymous28/6/13

    Hаѵing read thiѕ I bеlieved it was гather informative.
    I аpprecіate you fіnding the time and effoгt to
    put this infοrmativе article togetheг. I once again find mysеlf sρenԁing
    wау too much time both геaԁing аnd leaving comments.

    But sо ωhat, іt ωas stіll worthwhile!


    Heгe is my blog post best mobile site

    ReplyDelete
  7. Anonymous2/7/13

    Hello there I am so glad I found your blog page, I really found you by error,
    while I was researching on Bing for something else, Nonetheless I am here
    now and would just like to say many thanks for a
    remarkable post and a all round interesting blog (I also love the
    theme/design), I don’t have time to look over it all at the moment but I have saved it and also included your RSS feeds, so when I have time I will
    be back to read more, Please do keep up the awesome b.


    Stop by my page android apps apk

    ReplyDelete
  8. Anonymous2/7/13

    Greetings! I've been reading your site for some time now and finally got the courage to go ahead and give you a shout out from Humble Texas! Just wanted to tell you keep up the fantastic job!

    My blog pinched nerve in neck

    ReplyDelete

Post a Comment

Popular posts from this blog

XPATH for IE / internet explorer

All time good software testing books!