Running your first Selenium RC script

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. Selenium RC is great for testing complex AJAX-based web user interfaces under a Continuous Integration system. It is also an ideal solution for users of Selenium IDE who want to write tests in a more expressive programming language like Java,Perl etc.
Selenium IDE is much simpler and can be used only on firefox. Selenium RC lets you to write much complex scripts using the programming language features. And you can mention the browser on which you want to run the script. Selenium RC supports Internet Explorer, firefox, googlechrome etc.

You can use any IDE for developing your scripts but I like using Eclipse. I will be explaining later how to use Eclipse.

Ok...so lets start creating the Selenium RC script using TestNG. You will need to install the following first.

Install the below
1. JDK : You can be download it from here http://java.sun.com/javase/downloads/index.jsp. Set the classpath.

2. Selenium RC: Download it from here: http://seleniumhq.org/download . Extract the files in a folder named SeleniumRC and rename the selenium-server to JavaServer (it would be easy for us to use later).



3. TestNG : Download TestNG from http://testng.org/doc/download.html. Unzip. The files will get extracted to a folder called testng.

4. Eclipse : Download eclipse from http://www.eclipse.org/downloads/.Choose the "Eclipse IDE for Java Developers".Unzip the downloaded file. The files will get extracted to a folder called 'eclipse'.

5. TestNG plug-in for Eclipse: Start Eclipse by clicking the eclipse icon in the eclipse folder that's mentioned earlier. Click on Help->Install New Softwares. Enter "http://beust.com/eclipse/" in the "Work With:" and press Enter. You should see TestNG. Select it and then press Next till you reach Finish. Restart Eclipse.

Good that we have finished installing everything that we needed to start with selenium and TestNG. You could always work with selenium and testng without eclipse in which case you wont have to install Eclipse and the TestNG plug-in required for eclipse. But its better to have an IDE (like Eclipse or anyother) so that its far easier to write the scripts.

Let's start with the SeleniumRC and TestNG script now:
1. Open eclipse. Start by creating a new project : File->New->Java Project. Give a name say 'Automation'.
2. Add the required jars. Select the project-'Automation' , right click Build Path->Configure Build Path. Click Libraries->Add External Jars. You will have to add the testng and selenium jars.
3. Create a new package in the project. Select the project -'Automation' and then right click New->Package. Give a name say 'First'.
4. Create a new java program. Select the package-'First' and then right click New->Class. Enter the name as say 'GoogleSearchTC'.Press Enter.
5. Now go to Selenium IDE and open the 'google.html' script which we had created in our first blog- 'Starting with Selenium IDE'. Click on Options->Format->Java(TestNG)Selenium. You can see that the format of your test case is now changed.
The format is in the testng format now. Your script would look like below:




6. Copy paste the whole code into eclipse(GoogleSearchTC). You can see some errors.
7. Make changes so that your testng script looks like below:



Great!!!!! Your first testng script is ready to be run. Wasnt that easy?

8. Start your selenium server. Go to command prompt and then go to SeleniumRC/JavaServer folder (where you installed selenium rc). Type in
java -jar selenium-server.jar -port 1234
This is assuming that the port 1234 is free. You can give any other port number if 1234 is being used. Just ensure that the port num given in the testng script matches with the port num used to bring up the selenium server.

Your command prompt screen should look something like below:



Your selenium server is up and running now.

9. Now run the testng script by going back to eclipse. Right click on the testng script. Click RunAs->TestNG Test.
Your script should run successfully.

27 comments:

  1. excellent tutorial! really clear!
    I am a tester myself and I want to start running my selenium tests with testng, had really hard time finding tutorials for beginners like me

    ReplyDelete
  2. I have followed the exact instructions with out any issue. But after I recorded and formatted the script into TestNG format and then I copy and paste the whole code into Eclipse it prompts so many errors. Is there is a way to fix all those errors.

    The given below code is the one I retrieved after I formatted it. But once I copy and paste it to Eclipse it prompts so many errors. There for I am unable to exeucte it a s TestNG. Please appreciate your response. Advice me why I get a error in Eclipse and how to fix it.

    TestNG script.

    import com.thoughtworks.selenium.*;
    import org.testng.annotations.*;
    import static org.testng.Assert.*;
    import java.util.regex.Pattern;

    public class cap extends SeleneseTestNgHelper {
    @Test public void testCap() throws Exception {
    selenium.open("about:home");
    selenium.type("id=searchText", "cap");
    selenium.click("id=searchSubmit");
    selenium.waitForPageToLoad("30000");
    selenium.click("link=Cap (sport) - Wikipedia, the free encyclopedia");
    selenium.waitForPageToLoad("30000");
    }
    }

    ReplyDelete
    Replies
    1. Thanks for this useful information. IntelliMindz is the best IT Training in Bangalore with placement, offering 200 and more software courses with 100% Placement Assistance.

      Selenium Online Course
      Selenium Training In Bangalore
      Selenium Training In Chennai
      Selenium Training In Coimbatore
      Selenium Training In Tirupur

      Delete
  3. Thanks for your informative post; selenium is portable automation testing tool to validate the performance and behavior of a software application or environment. Best Selenium training institute in Chennai

    ReplyDelete

  4. Hi, probably our entry may be off topic but anyways, I have been surfing around your blog and it looks very professional. It’s obvious you know your topic and you appear fervent about it.Thanks for the forum posting..

    Mobile Application Development and Testing Training

    ReplyDelete
  5. Thanks for share this information. I have read your blog. Your information is really helpful for me. Keep update your blog. I did Selenium training in Chennai at Besant technologies. It’s very useful for me to know more about selenium.

    ReplyDelete
  6. Greens Technology's the leading software Training & placement centre Chennai & ( Adyar)
    selenium training in chennai

    ReplyDelete
  7. Thanks for your informative post on selenium automation testing tool.
    sas training in chennai

    ReplyDelete
  8. Its really nice appreciated article with screenshot of running RC Script.People willing to get the indepth knowledge in getting knowledge such as TestNG,jenkins,Maven and POM should get properly get best selenium training in chennai

    ReplyDelete
  9. Nice information about the installation of selenium RC scripts the steps pf installation are explained in easy and understandable manner My sincere thanks for sharing this post
    Selenium Training in Chennai

    ReplyDelete
  10. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    PSD to Wordpress
    wordpress website development

    ReplyDelete
  11. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment.
    industrial safety course in chennai

    ReplyDelete
  12. I love what you’ve got to say. But maybe you could a little more in the way of content so people could connect with it better.
    industrial course in chennai

    ReplyDelete
  13. The article "Running your first Selenium RC script" is more informative. This is more helpful for our selenium training in chennai. Thanks for sharing

    ReplyDelete
  14. I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this Salesforce Training who are providing certification and job assistance. Salesforce job oriented training in Noida

    ReplyDelete
  15. Great post. keep sharing such a worthy information.
    SEO Training in Chennai
    SEO Course

    ReplyDelete