Hello Selenium RC - Java Client
This Tutorial will show you how to run a Selenium test from JUnit through the Selenium RC Java Client.
Main Learning's
After following this tutorial you will learn how to:
- Create and exucute a JUnit test for Selenium RC
Versions used:
- OS: Windows XP V1.6
- JDK version 1.6.0_3
- Selenium RC version 0.9.2
- JUnit version 3.8.1
Assumptions:
You read the Selenium RC Hello World.
You read the JUnit Hello World.
Tutorial Steps:
- On Eclipse for Java, Create a Java Project – e.g, helloSeleniumRC
- Add junit.jar and selenium-java-client-driver.jar to the build path
- In my case, selenium-java-client-driver.jar is located at C:\seleniumrc\selenium-remote-control-0.9.2\selenium-java-client-driver-0.9.2
- Create a new JUnit unit test – e.g., HelloSeleniumTest.java
- Replace its content by the following code:
- import com.thoughtworks.selenium.*;
import junit.framework.*;
public class HelloSeleniumTest extends TestCase {
private Selenium browser;
public void setUp() {
browser = new DefaultSelenium("localhost",
4444, "*firefox", "http://www.google.com");
browser.start();
}
public void testGoogle() {
browser.open("http://www.google.com/webhp?hl=en");
browser.type("q", "hello world");
browser.click("btnG");
browser.waitForPageToLoad("5000");
assertEquals("hello world - Google Search", browser.getTitle());
}
public void tearDown() {
browser.stop();
}
}
- Start Selenium RC Server.
- Open a command prompt
- Go to the Selenium-Server folder (in my case C:\seleniumrc\selenium-remote-control-0.9.2\selenium-server-0.9.2)
- execute java -jar selenium-server.jar

- Now you are able to execute the JUnit unit test against the Selenium RC server
- Run the HelloSeleniumTest JUnit unit test


Basically the HelloSeleniumTest JUnit invokes the Selenium RC commands.
The testGoogle() test case invoked the commands open, type, click and waitForPageToload. The assertEquals () exemplifies a JUnit validations on the web page title.
Comments (0)
You don't have permission to comment on this page.