qaguru

Software QA and Testing Related Articles

Selenium and Flash : Testing Flash application using Selenium

leave a comment »

[Original Article : http://www.adobe.com/devnet/flash/articles/flash_selenium.html]

Writing and running functional tests for Flash with Selenium RC

Requirements

Prerequisite knowledge

You should have a good understanding of ActionScript 3.0 as well as the JUnit unit testing framework.

User level

Intermediate

Additional Requirements

Selenium Remote Control

FlashSelenium

Functional tests are intended to help you verify that a system, as a whole, functions as intended. Such tests verify that everything is wired together correctly. Selenium is an open-source testing tool for web applications. Selenium tests run directly in the web browser itself, mimicking what real users do. Furthermore, it supports a large variety of browsers and platforms. It is especially useful for executing tests to verify web application functionality and user acceptance. We used Selenium in our last project to verify that a web application (which contains one or more Flash components) worked the way we wanted.

Even though Selenium has been widely used for testing web applications, we did not find any resources linking Selenium to Flash or Flex when we started developing and testing Flash applications ourselves. After some work, however, we had a working solution for Selenium to test a deployed Flash application. This article describes how you can use the Selenium web testing tool to create and run functional tests for Flash and Flex web applications.

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.

The FlashSelenium component

Selenium RC uses JavaScript to communicate with the browser. Flash ExternalInterface provides a mechanism for which you can use JavaScript to call an ActionScript function in a SWF file embedded in an HTML page. Therefore, we created FlashSelenium, a Selenium RC client extension that uses JavaScript as the conduit between Selenium RC and the Flash application (see Figure 2).

FlashSelenium with JavaScript connecting to Flash ExternalInterface

Figure 2. FlashSelenium with JavaScript connecting to Flash ExternalInterface

FlashSelenium is the component that adds Flash communication capabilities to the Selenium framework. Basically, it is a Selenium RC client driver extension for helping execute the tests against the Flash component. The FlashSelenium constructor takes a Selenium instance and a Flash object ID as parameters.

An instance of FlashSelenium is used to invoke the functions on the Flash component. You can invoke functions that were externalized by the ExternalInterface, as well as the default functions of any Flash SWF (for example, isPlaying, PercentLoaded and TotalFrames). FlashSelenium is currently available for Java, .NET, Ruby, and Python. Analogous components are being created for PHP.

Next we will show you a complete example of a Flash-based web application and its corresponding Selenium RC tests.

Sample web application

The sample web application is very simple. It consists of a web page with an embedded Flash SWF object. The title of the page is “Clicking Colors.” The Flash SWF object presents a clickable rectangle that repaints itself (rotating colors green, blue and red) for every click. Try it out on our demonstration page.

Below is the source code for colors.html, the web application containing a Flash SWF object:

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Clicking Colors</title> <body> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100" height="100" id="clickcolors" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="ColoredSquare.swf" /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> http://ColoredSquare.swf </object> </body> </html>

Note that the Flash SWF object ID, clickcolors, will be used by the Selenium RC test.

Below is ColoredSquare.as, the source code for the Flash SWF component embedded in the web application:

package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.external.ExternalInterface; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; public class ColoredSquare extends Sprite { private const COLOR_HEX_VALUES:Array = [0×00ff00, 0×0000ff, 0xff0000]; private const COLORS:Array = ["GREEN", "BLUE", "RED"]; private const SQUARE_SIDE:uint = 500; private var currentColor:uint; private var currentColorIndex:uint = 0; private var buttonSprite:Sprite = new Sprite(); private var squareLabel:String = "(Click here)"; private var label:TextField = new TextField(); public function ColoredSquare() { currentColor = COLOR_HEX_VALUES[currentColorIndex % 3]; updateButtonLabel(); drawButton(); addEventListener(MouseEvent.CLICK, buttonClicked); // functions available for JavaSript calls ExternalInterface.addCallback("getColor", getColor); ExternalInterface.addCallback("click", changeColor); ExternalInterface.addCallback("getSquareLabel", getSquareLabel); ExternalInterface.addCallback("setSquareLabel", setSquareLabel); } private function buttonClicked(event:MouseEvent):void { changeColor(); } private function changeColor():void { currentColorIndex++; currentColor = COLOR_HEX_VALUES[currentColorIndex % 3]; this.squareLabel = COLORS[currentColorIndex % 3]; updateButtonLabel(); drawButton(); } private function updateButtonLabel():void { var format:TextFormat = new TextFormat(); format.size = SQUARE_SIDE / 10; var label:TextField = new TextField(); label.autoSize = TextFieldAutoSize.LEFT; label.selectable = false; label.defaultTextFormat = format; label.text = squareLabel; label.x = SQUARE_SIDE / 5; label.y = SQUARE_SIDE / 2.5; if (buttonSprite.contains(this.label)) { buttonSprite.removeChild(this.label); } this.label = label; buttonSprite.addChild(this.label); } private function drawButton():void { buttonSprite.graphics.beginFill(currentColor); buttonSprite.graphics.drawRect(0, 0, SQUARE_SIDE, SQUARE_SIDE); buttonSprite.graphics.endFill(); addChild(buttonSprite); } public function setSquareLabel(squareLabel:String):void { this.squareLabel = squareLabel; updateButtonLabel(); drawButton(); } public function getColor():String { return COLORS[currentColorIndex % 3]; } public function getSquareLabel():String { return this.squareLabel; } } }

The following ChangeColor functions are made available for JavaScript invocation by means of the ExternalInterface: getColor, changeColor, getSquareLabel, and setSquareLabel:

// functions available for JavaSript call ExternalInterface.addCallback("getColor", getColor); ExternalInterface.addCallback("click", changeColor); ExternalInterface.addCallback("getSquareLabel", getSquareLabel); ExternalInterface.addCallback("setSquareLabel", setSquareLabel);

The Selenium RC client

We selected the Selenium RC Java client to trigger the tests. Analogous implementations can be made for the other available Selenium RC clients: .NET, Perl, Python, and Ruby.

We encourage you to run the following Selenium RC Java client JUnit test against the sample web application. But before doing so, please make sure the environment is properly set up and that you are familiar with executing a basic Selenium RC Java client JUnit test.

FlashSelenium is the component that enables Selenium RC Java client to talk to Flash. To use it, all you need to do is add flashselenium-java-client-extension.jar (JAR, 3.6K) to your classpath, the same way you added junit.jar and selenium-client-driver.jar.

The following is the ChangeColorsSiteTest.java, a Selenium-based JUnit test case testing the web application containing the changecolor flash component:

import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; import com.thoughtworks.selenium.SeleniumException; import junit.framework.TestCase; public class ColorsTest extends TestCase { private FlashSelenium flashApp; private Selenium browser; private final static String GREEN = "GREEN"; private final static String BLUE = "BLUE"; private final static String RED = "RED"; private final static String URL = "http://flashselenium.t35.com/colors.html"; public void setUp() { browser = new DefaultSelenium("localhost", 4444, "*firefox",URL); browser.start(); flashApp = new FlashSelenium(browser, "clickcolors"); browser.open(URL); } public void tearDown() { browser.stop(); } public void testColorTransition() { assertEquals("Clicking Colors", browser.getTitle()); assertEquals(GREEN, flashApp.call("getColor")); flashApp.call("click"); assertEquals(BLUE, flashApp.call("getColor")); flashApp.call("click"); assertEquals(RED, flashApp.call("getColor")); flashApp.call("click"); assertEquals(GREEN, flashApp.call("getColor")); } public void testRectangleLabel() { assertEquals("(Click here)", flashApp.call("getSquareLabel")); flashApp.call("setSquareLabel", "Dummy Label"); assertEquals("Dummy Label", flashApp.call("getSquareLabel")); } }

Notice at the testColorTransition method that the following statement is testing the web page title:

assertEquals("Clicking Colors", browser.getTitle());

This exemplifies that, beyond adding Flash testing capabilities, you are able to use Selenium for testing all other web application objects. You are also able to do all the web application verifications from the same test (if appropriate). This capability is particularly interesting for validating the interoperability of web application components—for example, validating corresponding values from the Flash component and the rest of the web application.

The remaining part of the testColorTransition method validates the color transition logic. Note that the changeColor() ActionScript 3.0 code method is directly invoked by the Selenium RC Client code:

flashApp.call("click");

The testRectangleLabel method shows a scenario in which the test validates an external parameter being passed to the Flash application, the rectangle label. Figure 3 shows the ChangeColorsSiteTest executed within the Eclipse IDE.

Executing the ChangeColorSiteTest within Eclipse

Figure 3. Executing the ChangeColorSiteTest within Eclipse

Figures 4 and 5 show the sequence (within the browser started by Selenium) when executing the testRectangleLabel() test.

testRectangleLabel() in execution: Step 1

Figure 4. testRectangleLabel() in execution: Step 1

testRectangleLabel() in execution: Step 2

Figure 5. testRectangleLabel() in execution: Step 2

Where to go from here

This article showed you how to run Selenium tests for your Flash-based web application. On the Selenium RC client side, you use FlashSelenium (for Java, available as flashselenium-java-client-extension.jar), a Selenium RC client extension that enables communication between the Selenium RC client and the Flash application. On the Flash side, you can verify the default functions of any Flash SWF (e.g., isPlaying, PercentLoaded, and TotalFrames) and/or a specific Flash application’s functions externalized by Flash ExternalInterface. We walked you through testing a simple web application containing a Flash SWF object. For more examples, please refer to the Flash Selenium project page.

FlashSelenium is useful for testing both Flash and Flex applications. As we demonstrated in this article, the tests are executed against the deployed SWF. Flex originally was designed to support enterprise development for the Flash platform. For instance, Flex is geared towards application development. Testing is a fundamental practice for a successful enterprise development practice. Therefore, Flex developers should add Selenium and FlashSelenium to their test tools arsenal.

Selenium RC is the proposed solution’s main component. Selenium drives the functional tests against the web application embedding the Flash SWFs. Because Selenium is an active open-source project, we can benefit from its current and future capabilities (for instance, Selenium Grid could be used for running tests in parallel and for validating Flash web applications’ compatibility against a variety of browsers and operational systems). Also, as is usually the case, the Flash application executes in a web browser; and by using Selenium (and enhancing it to work with Flash), we are able to test the Flash application as well as the other web application components.

Our special thanks to Mark Striebeck, Paul Hammant, and Jason Huggins for encouraging and supporting this work.

Comments (23)
  • John McKeanOctober 23, 2008

    Thanks.  This article is very informative.
    I just had one simple question.  The JUnit test that tests the flash component that you provided worked well for me all except for the calls to
    flashApp.call(“click”);
    Those calls went straight through without actually changing the color of the box.  If I manually click on the box it will change color.
    The article specifies that this ExternalInterface was used for that method…
    ExternalInterface.addCallback(“click”, changeColor);
    I tried to call
    flashApp.call(“changeColor”);
    to see if that might work but I got “Object doesn’t support this property or method” in that case.
    So, I’m just curious if you know why that one function doesn’t work for me.
    Thanks,
    -John

  • Younes HashlamounNovember 6, 2008

    changeColor don’t take any parameter it just change the color upon clicking the mouse…
    also you call each test case alone …either testColorTransition() or testRectangleLable() ..as testColorTransition() first compare color to Green then lable to Click here…

  • jpfulmerNovember 12, 2008

    Where do I find the JavaDoc for FlashSelenium?

  • jpfulmerNovember 12, 2008

    assertEquals(GREEN, flashApp.call(“getColor”));
    Error:
    The method call(String, String[]) in the type FlashSelenium is not applicable for the arguments (String)

  • flexer2008December 11, 2008

    Is this working with FLEX Air desktop application as well and can be integrated in ant build?

  • tirumala rao vasamsettyJanuary 10, 2009

    Remove the line in ColoredSquare.cs:
    ExternalInterface.addCallback(“click”, changeColor);
    Add the line in ColoredSquare.cs
    ExternalInterface.addCallback(“changeColor”, changeColor);

    Make a new swf file and put on your web server.

    Change all you ref to “click” Selenimu Client Java program to “changeColor”. For example:                 flashApp.call(“changeColor”);

    BTW, use “Selenium RC   Mar 5, 2008   1.0 beta 1” to validate this program. Other releases and nightly builds are not able to read the handle to flash object.

  • Sunaina GuptaJanuary 27, 2009

    Hi,

    This article was really helpful. But I still have a basic question. Any help would be greatly appreciated.

    I’m trying to write a java unit test to test click event of a button. The button is in the SWF file which is embedded in HTML. I wanted to know a way of getting the button object which is in SWF, from my unit test.

    Thanks!

  • seer14January 30, 2009

    This article is very helpful and I think it will be of great use to our organization. We have the PHP version of the RC client deployed and thus I’m wondering if any progress been made on the PHP RC Client?

  • Per OlesenFebruary 13, 2009

    Just wanted to add: I need to wait for my flash to load, to make this work. Like this:

    public void testFooBar() {
    waitForFlashLoaded();
    assertEquals(“hello world”, myapp.call(“callMe”));
    }

    private void waitForFlashLoaded() {
    try {
    while (myapp.PercentLoaded() != 100) {
    Thread.sleep(500);
    }
    } catch (InterruptedException e) {
    // craps
    }
    }

  • frank_fenApril 30, 2009

    Links in the first paragraph to http://helloopensource.org/ go to a search aggregatr (aggravator!) page that has nothing to do with Silenium and just has links to commercial software.

    As a newbie, would appreciate good links / pointers on “setting up proper environment” and “executing junit test”.

    Thx

  • sogwizMay 11, 2009

    I’m getting this Exception when calling flashApp.call(“click”);
    Exception in thread “main” com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: window.document.clickcolors is undefined
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:435)
    at com.thoughtworks.selenium.FlashSelenium.call(FlashSelenium.java:54)
    at com.mobilesearchqa.qs.ColorsTest.setUp(ColorsTest.java:31)

    The exception occurs anytime I try to call a function associated with the flashApp object.

  • Paulo CaroliMay 27, 2009

    Hey All,
    I am glad FlashSelenium is helping you test your Flex application.
    Some general recommendations:
    Make sure to use the latest version of Selenium RC and FlashSelenium.
    Also, please verify if selenium RC is working by its own before using it with FlashSelenium.
    I have created a FAQ page on the flash-selenium project at google code.  For now on, whenever there is a question, I will post it there with its answer.
    Also the latest project in the Flex Testign family: flex-ui-selenium is building on top of FlashSelenium and will take care of the most requested feature: interacting with the UI components without explicitly adding ExternalInterface for each UI component event.
    Please joins us at FlashSelenmium and FlexUISelenium; be are looking for Q&A items and project additions.
    FlashSelenium project page: http://code.google.com/p/flash-selenium/
    FlexUISelenium project page: http://code.google.com/p/flex-ui-selenium/
    Cheers,

  • aedananaoJune 27, 2009

    hello,
    i’ve been using selenium-rc for few months now but new to selenium-flash… tried compiling the code above but seems like i’m the only getting error. Someone please help.

    ColorsTest.java:8: cannot find symbol
    symbol  : class FlashSelenium
    location: class ColorsTest
    private FlashSelenium flashApp;
    ^
    ColorsTest.java:19: cannot find symbol
    symbol  : class FlashSelenium
    location: class ColorsTest
    flashApp = new FlashSelenium(browser, “clickcolors”);
    ^
    2 errors

    —ColorsTests.java—
    import com.thoughtworks.selenium.DefaultSelenium;
    import com.thoughtworks.selenium.Selenium;
    import com.thoughtworks.selenium.SeleniumException;

    import junit.framework.TestCase;

    public class ColorsTest extends TestCase {
    private FlashSelenium flashApp;
    private Selenium browser;

    private final static String GREEN = “GREEN”;
    private final static String BLUE = “BLUE”;
    private final static String RED = “RED”;
    private final static String URL = “http://www.geocities.com/paulocaroli/flash/colors.html“;

    public void setUp() {
    browser = new DefaultSelenium(“localhost”, 4444, “*firefox”,URL);
    browser.start();
    flashApp = new FlashSelenium(browser, “clickcolors”);
    browser.open(URL);
    }

    public void tearDown() {
    browser.stop();
    }

    public void testColorTransition() {
    assertEquals(“Clicking Colors”, browser.getTitle());
    assertEquals(GREEN, flashApp.call(“getColor”));
    flashApp.call(“click”);
    assertEquals(BLUE, flashApp.call(“getColor”));
    flashApp.call(“click”);
    assertEquals(RED, flashApp.call(“getColor”));
    flashApp.call(“click”);
    assertEquals(GREEN, flashApp.call(“getColor”));
    }

    public void testRectangleLabel() {
    assertEquals(“(Click here)”, flashApp.call(“getSquareLabel”));
    flashApp.call(“setSquareLabel”, “Dummy Label”);
    assertEquals(“Dummy Label”, flashApp.call(“getSquareLabel”));
    }
    }

  • aedananaoJune 27, 2009

    sorry for above needless posting… problem is solved now missing this statement:
    import com.thoughtworks.selenium.FlashSelenium;

  • schuel2July 13, 2009

    I am not clear on how to build up the flash application to be tested. The URL given http://www.geocities.com/paulocaroli/flash/colors.html is missing the external interfaces.
    The source code provided in the Flash-Selenium project is ColoredSquare.as, but how is that meant to be built into an swf?

  • Denis ZgonjaninAugust 25, 2009

    I get this error when trying to call a method on the flash object from Selenium RC:

    ERROR: Threw an exception: NPMethod called on non-NPObject wrapped JSObject!
    com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: NPMethod called on non-NPObject wrapped JSObject!
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:443)
    at com.thoughtworks.selenium.FlashSelenium.call(FlashSelenium.java:57)

    Any idea what is wrong? I can’t find a reference to the error anywhere

  • orimar1January 13, 2010

    Hi-

    This is very helpful.

    Do you intend to have the demo part to test against (colors.html) @ http://www.geocities.com/paulocaroli/flash/colors.html to continue to run?
    Currently it is down.

    Thanks.

  • Stefan Gruenwedel(Administrator)January 19, 2010

    @orimar1: The article now links to (and shows in the code sample on this page) the new hosted demo page URL:
    http://flashselenium.t35.com/colors.html

    </sg>

  • Vikram-VIJanuary 21, 2010

    Hi,
    thanks for this useful article, I tried the code and came across below issue
    I’m using windows 7, FF 3.5

    com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: this.browserbot.findElement(“clickcolors”).getSquareLabel is not a function
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:443)
    at com.thoughtworks.selenium.FlashSelenium.call(FlashSelenium.java:57)
    at GoogleTest.testRectangleLabel(GoogleTest.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    —-
    also I think code need to slightly updated as below

    public class GoogleTest extends TestCase{

    private FlashSelenium flashApp;
    private Selenium browser;
    private SeleniumServer serverLauncher;
    private RemoteControlConfiguration RC;
    File FFpath;

    private final static String GREEN = “GREEN”;
    private final static String BLUE = “BLUE”;
    private final static String RED = “RED”;
    private final static String URL = “http://flashselenium.t35.com/colors.html“;

    public void setUp()
    {
    try{
    FFpath = new File(“c:\\workspace1\\Flash-profile”);

    RC = new RemoteControlConfiguration();
    RC.setFirefoxProfileTemplate(FFpath);

    serverLauncher = new SeleniumServer(RC);
    serverLauncher.start();

    browser = new DefaultSelenium(“localhost”, 4444, “*chrome”,URL);
    browser.start();
    flashApp = new FlashSelenium(browser, “clickcolors”);

    browser.open(URL);

    }catch(Exception e){
    e.printStackTrace();
    }
    }

    public void tearDown()
    {
    browser.stop();
    serverLauncher.stop();

    }

    public void testColorTransition()
    {
    assertEquals(“Clicking Colors”, browser.getTitle());
    assertEquals(GREEN, flashApp.call(“getColor”));
    flashApp.call(“click”);
    assertEquals(BLUE, flashApp.call(“getColor”));
    flashApp.call(“click”);
    assertEquals(RED, flashApp.call(“getColor”));
    flashApp.call(“click”);
    assertEquals(GREEN, flashApp.call(“getColor”));
    }

    public void testRectangleLabel()
    {
    assertEquals(“(Click here)”, flashApp.call(“getSquareLabel”));
    flashApp.call(“setSquareLabel”, “Dummy Label”);
    assertEquals(“Dummy Label”, flashApp.call(“getSquareLabel”));
    }

    }

  • kruthachetasMarch 24, 2010

    Hi, I am trying to run this demo and get similar exception:
    com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: this.browserbot.findElement(“clickcolors”).getColor is not a function
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:471)
    at com.thoughtworks.selenium.FlashSelenium.call(FlashSelenium.java:57)
    at FlashTest.testColorTransition(FlashTest.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

    Any help would be greatly appreciated.

    Thanks

  • yyvincent2002August 24, 2010

    I got the same issue:

    com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: this.browserbot.findElement(“clickcolors”).getColor is not a function
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:443)
    at com.thoughtworks.selenium.FlashSelenium.call(FlashSelenium.java:57)
    at ColorTest.testColorTransition(ColorTest.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:243)
    at junit.framework.TestSuite.run(TestSuite.java:238)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Does any one figure this out? Thanks,

  • theotherlamontagneNovember 18, 2010

    Re: the browserbot.findElement error.

    I don’t know the root cause for this but i did manage to get around it by changing the browserString in the DefaultSelenium object to “*iexplore”. I was building this only as a proof of concept so I haven’t had time to do any more investigation.

    Hope this helps.

  • AyeshaNoorFebruary 15, 2011

    Great article (Y)
    Found one little hitch though, that no one else seemed to encounter… when i executed the very first “Hello World”  example for Selenium RC Java Client Driver i got a NullPointerException at the very first line of the test case, for which i had to make the following changes in order to make it work:
    1.change _eard() to setUp()
    2.add extends SeleneseTestCase where the class for my test case was declared.
    3.add selenium.close(); before selenium.stop(); in _eardown()
    4. Replace SeleniumServer.getDefaultPort() by 4444, since it was not identifying the method.

    i found these remedies through hit n trial, and it’d be great if someone here could pin point the exact reasons for each of these changes.
    Thanks 🙂

Please sign in to improve or rate the content.

Written by qaguru

24/05/2011 at 05:26

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: