September 1, 2010

Setting up Selenium RC & TestNG using Eclipse-II


I found that it is not easy for the beginners to setup Selenium RC and run the GoogleTest.java example after downloading it from www.openqa.org . The purpose of this post is to help beginners (new users to Selenium RC) help setting up Selenium RC with TestNG using Eclipse.
This assumes that you have done the following steps.
Download and install Eclipse (www.eclipse.org)
Download the latest TestNG (www.testng.org)
Download Selenium RC (www.openqa.org)
Install TestNG plugin for eclipse
Please follow the step by step instructions to setup the test environment.
Launch Eclipse, you can setup any directory as your default workspace. For this example, my default workspace is as shown below.
001
Click OK, Eclipse will be launched.


Click File > New
002
Set the project name as Google.
0032
Click Next.
On the Source tab leave the default.
Click on Libraries.
Click on Add External Jars
Add the jar files for TestNG and Selenium RC Java client as shown below.
0042
Click Finish, now you will have a Java project created in Eclipse that is correctly set to use Selenium Client and TestNG jar files.
Now Right Click on the src > New > Class
005 
Name the class file as GoogleTest and Click Finish.
Now create a testng test within GoogleTest class as follows.
006

The next step is to run the Selenium Server as
007
Now Right Click on the test and run this as TestNG test.
008
The test will be successful.
009



You can Start server directly in the TestNG script..


Below is the code for that

import com.thoughtworks.selenium.*;


import org.openqa.selenium.server.*;
import org.testng.annotations.*;




public class GoogleTest {
public Selenium selenium;
public SeleniumServer seleniumserver;


  @BeforeClass
  public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://");
seleniumserver.start();
selenium.start();
}


@Test
public void testgoogle()throws Exception {
  
        selenium.open("http://www.google.com");
        selenium.type("q", "Selenium OpenQA");
        selenium.click("btnG");
        Thread.sleep(10000);
        }
 @AfterClass
 public void tearDown()throws Exception {
    selenium.stop();
    seleniumserver.stop();
    
 }
 }



25 comments:

  1. I have the TestNG working when I ask the IDE to run my tests, but how can I get the tests run from the command line using my jar?

    I want to be able to invoke the tests as a remote service that that gets queued up at night every day to run automatically, or that gets invoked to run specific tests as needed by the developers.

    Any pointers to where I can RTFM are appreciated.

    Mike

    ReplyDelete
  2. Hi,

    Thanks to your post. But I am not able to see the image file. Can you pls sort them. It would help me a lot.

    ReplyDelete
    Replies
    1. hi anantha u r from south india? i have heard that south gives full response. is this true?

      Delete
  3. Hi Naga,

    Thanks for the post. Images in this post are not displaying. Can you please look into it.. So that it will be helpful to all..

    Thanks,
    Kamal

    ReplyDelete
  4. Hey Naga,

    Images in the post are not displayed. Please correct it.
    I am referring your blog to learn n expertise my skills on Selenium.

    Thanks,
    Sangamesh

    ReplyDelete
  5. Hi
    Any updates on images not displaying.
    Aniruddha

    ReplyDelete
  6. If you are keen on ensuring a stylish, elegantly designed wedding, don''.
    Fondant can support you to fairly quickly produce a nice seeking foundation for your cake design and style.
    Be it a small wedding or a large wedding, you cannot plan an event if you don't have enough time.

    Also visit my weblog barbie princess cake ideas

    ReplyDelete
  7. If you are on a spending budget this 12 months this post has some useful tips that may show you the best way to decorate
    with some easy outdoor Christmas decorations without going broke.
    A single excellent means of carrying out it might be, by making use of final 12 months.
    Of course Christmas is basically a celebration of faith, so when the nativity scene is central to your Christmas, then by all means make sure to contain it.


    my page; cheap christmas decorating tips

    ReplyDelete
  8. Having read this I believed it was very informative.
    I appreciate you finding the time and effort to put this information together.

    I once again find myself spending way too much time both reading and commenting.

    But so what, it was still worth it!

    Feel free to surf to my site - quantrim purchase

    ReplyDelete
  9. Very nice article, exactly what I needed.

    My web site ... quantrim Fast track Formula

    ReplyDelete
    Replies
    1. my website wowsextube.com pls refer it. it will help for u

      Delete
  10. badha su ma chodo cho benchodo hey nga ne hi naga su image ni patart fado chho

    ReplyDelete
  11. An outstanding share! I have just forwarded this onto a coworker
    who was doing a little research on this. And he in fact ordered me breakfast due to the fact
    that I found it for him... lol. So let me reword this.
    ... Thank YOU for the meal!! But yeah, thanx
    for spending the time to talk about this issue here on your web site.



    Stop by my website; quantrim purchase

    ReplyDelete
  12. Unable to view the images can u check them once please, I am following this for my setup please

    ReplyDelete
  13. Hello. sorry i don't know of this is the right place but how do i convert Selenium IDE tests into JUnit4 for eclipse. I tried to use the 'Export As' option in IDE but it still looks like HTML not like JUnit4? sorry for the noob question(:

    ReplyDelete
    Replies
    1. Never mind I found a way (=. The format menu has a bug or something so i can only convert one test case at a time then i have to restart IDE but at least it works;)

      Delete