All Posts

Sample Selenium RC Test

Sample Selenium RC Test

Selenium RC (Remote Control) is a deprecated component of Selenium that allowed test scripts to be written in various languages and controlled browsers through a server.

Note: Selenium RC has been replaced by Selenium WebDriver, but this example is still useful for legacy systems or learning purposes.

✅ Sample Selenium RC Test in Java

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class SampleSeleniumRCTest {

    public static void main(String[] args) {
        // Step 1: Create a Selenium instance
        Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://www.google.com");

        // Step 2: Start the Selenium session
        selenium.start();

        try {
            // Step 3: Open Google
            selenium.open("/");

            // Step 4: Type a query in the search box
            selenium.type("name=q", "Selenium RC Test");

            // Step 5: Submit the search form
            selenium.click("name=btnK");
            selenium.waitForPageToLoad("5000");

            // Step 6: Print the page title
            System.out.println("Page title: " + selenium.getTitle());

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // Step 7: Stop the Selenium session
            selenium.stop();
        }
    }
}

 

🧰 Prerequisites

Selenium RC Server (selenium-server.jar) must be running:

/> java -jar selenium-server.jar

Firefox must be installed (since this test uses *firefox).

Selenium Java client driver must be added to your classpath.

💡 Notes

  • DefaultSelenium connects to the Selenium RC Server.

  • selenium.start() launches the browser.

  • selenium.open("/") opens the homepage (in this case, Google).

  • selenium.type() and selenium.click() perform actions on elements.

  • selenium.getTitle() retrieves the title of the current page.