The following shows you step-by-step how to run your first Selenium RC application in Java.
javac -version
cd C:\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1\
java -jar selenium-server.jar -interactive
15:55:51.004 INFO - Java: Sun Microsystems Inc. 10.0-b22 15:55:51.004 INFO - OS: Windows XP 5.1 x86 15:55:51.004 INFO - v1.0-beta-1 [2201], with Core v1.0-beta-1 [1994] 15:55:51.084 INFO - Version Jetty/5.1.x 15:55:51.084 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver] 15:55:51.084 INFO - Started HttpContext[/selenium-server,/selenium-server] 15:55:51.084 INFO - Started HttpContext[/,/] 15:55:51.104 INFO - Started SocketListener on 0.0.0.0:4444 15:55:51.104 INFO - Started org.mortbay.jetty.Server@13e205f Entering interactive mode... type Selenium commands here (e.g: cmd=open&1=http://www.yahoo.com)
/** * Google.java * Open Google webpage and search for "Selenium RC". * @Author: Xuan Ngo */ import com.thoughtworks.selenium.DefaultSelenium; public class Google { public static void main(String[] args) { final String sServerHost = "localhost"; final int iServerPort = 4444; final String sBrowserType = "*iexplore"; // For Firefox, use *firefox final String sBaseUrl = "http://www.google.ca/"; DefaultSelenium oDefaultSelenium = new DefaultSelenium(sServerHost, iServerPort, sBrowserType, sBaseUrl); oDefaultSelenium.start(); // Start Selenium. oDefaultSelenium.setSpeed("5000"); // Wait 5 seconds for every instructions so that you can see what Selenium is doing. // Open the main google webpage. oDefaultSelenium.open("http://www.google.ca/index.html"); // Type "Selenium RC" into the search input field. oDefaultSelenium.type("name=q", "Selenium RC"); // Use name locator to identify the search input field. // Click on "Google Search" button oDefaultSelenium.click("xpath=//input[@name='btnG']"); // Close the browser. oDefaultSelenium.stop(); } }
javac -classpath C:\selenium-remote-control-1.0-beta-1\selenium-java-client-driver-1.0-beta-1\selenium-java-client-driver.jar Google.java
java -classpath C:\selenium-remote-control-1.0-beta-1\selenium-java-client-driver-1.0-beta-1\selenium-java-client-driver.jar;. Google
| Attachment | Size |
|---|---|
| Google.java | 1.14 KB |