Google Analytics


To search for specific articles you can use advanced Google features. Go to and enter "" before your search terms, e.g. CSS selectors

will search for "CSS selectors" but only on my site.

Friday, February 12, 2010

Step by Step Selenium Java

This is a document on how to write a Selenium Test Case in Java.

  1. Go to Selenium HQ.
  2. Go to the Download section and download Selenium IDE plus Selenium RC
  3. Install the Selenium IDE into Firefox (I assume you have Firefox installed)
  4. Go to Google.
  5. From the Tools menu in Firefox select Selenium IDE.
  6. From the Add-On Preferences, change Selenium to save in Java.
  7. On the Google page, right click and select Open /ig
  8. Type Selenium in the Google search text field.
  9. Press TAB to move focus away from the input field.
  10. Right click on the search text field and select verifyValue q Selenium
    1. Note that verifyValue is the action, q is the locator and Selenium is the optional third value
  11. Click the I'm Feeling Lucky button.
  12. Go to the Selenium IDE and you should see everything we just did.
  13. Click the red dot in the upper right to stop the recording.
  14. From the File menu, save the file as
  15. Open Eclipse
  16. Create a Java Project
  17. Add the jar selenium-java-client-driver.jar to the project.
  18. Add the library junit 3.
  19. Right click on the project name in the Package Explorer and add new package com.example.tests.
  20. Import from File System, the file we saved earlier.
  21. When you finish there should be an error because the class is called Untitled by default.
  22. Edit the file and change the class name to LearningSelenium
  23. In the setUp() change the http://change-this-to-the-site-you-are-testing/ to
  24. If using Mac OS, change the browser string from *chrome to *safari.
  25. Add a public void tearDown() throws Exception which just calls super.tearDown();
  26. Run Firefox from the command line using firefox -P (or firefox-bin -P on UNIX/Linux machines)
  27. Create a new profile, call it selenium and save it in the Eclipse workspace
  28. Go to the command line and start the selenium server using:
    1. java -jar selenium-server.jar -firefoxProfileTemplate /directory/where/you/saved/firefox/profile/selenium
    2. But change the /directory/where/you/saved/firefox/profile/selenium to the place you saved the profile in step 25.
  29. Back in Eclipse, right click the class name and select Run As, JUnit Test
You are done.


Lumbee said...

Great write up Darrell. This helped me out alot!

CP said...

I agree with Lumbee. Brilliant write up. The post about using Selenium from scratch was just as brilliant. This is the only "manual" I've been able to find online.