Accessibility

Table of Contents

Writing and running functional tests for Flash with Selenium RC

Solution overview

The solution we describe in this article relies on FlashSelenium to drive the Selenium communication with Adobe Flash Player client. Figure 1 gives an overview of the proposed solution. But before digging into the details, you'll need to understand a few terminologies and technologies.

Proposed FlashSelenium solution

Figure 1. Proposed FlashSelenium solution

Selenium RC (Selenium Remote Control) is a tool that allows you to launch browser sessions and run Selenium tests against those browsers. To do this, the Selenium RC server acts as an intercepting proxy for the browser. Typically, commands are dispatched to the Selenium RC server through a Selenium RC client driver.

For instance, you can programmatically create a Selenium RC test with JUnit and the Selenium-Java-client driver. Selenium RC currently provides client drivers for Java, .NET, Python, Ruby, and PHP. Selenium RC client drivers provide methods for interacting with the browser components in the native unit test language. Selenium RC uses JavaScript as the underlying communication between the Selenium RC client driver, the Selenium RC server, and the browser. Moreover, Selenium RC is simple to set up and easy to use.

The following is the "Hello World" example for Selenium RC Java Client Driver:

package com.thoughtworks.selenium;
import junit.framework.*;
import org.openqa.selenium.server.*;
public class GoogleTest extends TestCase {
    private Selenium selenium;
    public void _eard() throws Exception {
        String url = "http://www.google.com";
        selenium = new DefaultSelenium("localhost", SeleniumServer.getDefaultPort(), "*firefox", url);
        selenium.start();
    }
 
    protected void _eardown() throws Exception {
        selenium.stop();
    }
 
    public void testGoogle() throws Throwable {
        selenium.open("http://www.google.com/webhp?hl=en");
        assertEquals("Google", selenium.getTitle());
        selenium.type("q", "Selenium OpenQA");
        assertEquals("Selenium OpenQA", selenium.getValue("q"));
        selenium.click("btnG");
        selenium.waitForPageToLoad("5000");
        assertEquals("Selenium OpenQA – Google Search", selenium.getTitle());
    }
}

The Flash ExternalInterface component (introduced in Flash Player 8) is an API that enables communication between a SWF file and the Flash Player container. One of its uses is to make it possible to invoke ActionScript functions in a SWF file from JavaScript.