Selenium: web application testing

  • Multi-browser (IE, Firefox, Safari)
  • Multi-platform (Windows, Linux, and Macintosh).

Selenium IDE

Selenium IDE is a Firefox extension. Watch the video tutorial and download it

Note: the recorded test can be saved as HTML, Java, Python, Ruby, Perl and C#.

Selenium RC (Remote Control)

Selenium RC comes in two parts:

  • server which launches, controls, and kills browsers.
  • client libraries (Java, Python, PHP, Ruby, Perl and .NET) to control the server.

Installation on Ubuntu

  • check java references Sun 1.5 version. Otherwise:
cd /etc/alternatives
sudo rm java
sudo ln -s  /usr/lib/jvm/java-1.5.0-sun-1.5.0.11/jre/bin/java java
  • add /usr/lib/firefox/firefox-bin to your PATH

Misc

  • launch Selenium server:
java -jar selenium-server.jar -interactive

Selenium jUnit tests in Eclipse

  • it's possible to set some breakpoints and launch the test in debug mode (Run -> Debug Last Launched)
  • advanced example:
package jj;
 
import java.util.Random;
 
import junit.framework.TestCase;
 
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
 
public class EncountersRegistrationTest extends TestCase {
 
	// TODO *** update this variable to match your config ***
    private static final String LOCAL_LOGIN_URL = "";
 
	private Selenium selenium;
 
    public void setUp() {
        selenium = new DefaultSelenium("localhost", 4444, "*firefox", LOCAL_LOGIN_URL);
        selenium.start();
    }
 
    public void testParticipantRegistration() {
 
		selenium.open("/encounters23/login.html");
		assertEquals("Login", selenium.getTitle());
		selenium.type("code", "BC011234");
		selenium.click("lang");
		selenium.click("//input[@value='Submit']");
		selenium.waitForPageToLoad("30000");
 
 
		assertEquals("Registration 1 - Basic Information", selenium.getTitle());
		Random random = new Random();		
		selenium.type("username", "test_" + random.nextInt(10000));
		selenium.type("email", "toto@example.com");
		selenium.select("province", "label=Nova Scotia");
		selenium.click("//input[@value='Save And Continue']");
		selenium.waitForPageToLoad("30000");
 
 
		// preferences
		selenium.select("theme_5092", "label=11");
		selenium.click("document.forms[0].terms[4]"); // checkbox
		selenium.click("//input[@value='Save And Continue']");
		selenium.waitForPageToLoad("30000");
 
		// school
		assertEquals("Registration 5 - School", selenium.getTitle());
		selenium.select("school", "index=3");
		selenium.click("//input[@value='Save And Continue']");
		selenium.waitForPageToLoad("30000");
    }
 
    public void tearDown() {
        selenium.stop();
    }
}

Feedback

cool site
rob
Feb 23, 2011
#1
thank you for writing this page
geofrey
May 21, 2012
#2
great info! thanks!
zsolt
May 12, 2013
#3