Extend Rational Functional Tester to test Adobe Flex or Flash applications

Extend with open-source tools to minimize impact of frequent browser patches and updates

One of the great benefits of Rational Functional Tester and its Eclipse IDE is that it can easily be extended with literally hundreds of useful open source components. Our team was challenged to consistently automate GUI Flex applications using the built-in support for Flex automation due to constant browser security patches. We resolved this problem by using open source components to keep up with the browser security updates that seem to come daily. This article explains how Rational Functional Tester works in combination with Selenium and FlexMonkium. Tim Hague provides step-by-step instructions to help you implement a similar solution.

Share:

Tim Hague (thague@us.ibm.com), Quality Assurance Automation Engineer, IBM

author photoTim Hague is an automation engineer for IBM, currently focused on developing automation frameworks for the IBM InfoSphere Optim product portfolio. He has been in several development and QA roles since 1994, including Java developer, web developer, QA lead , project manager, and business analyst.



07 February 2012

Also available in Chinese Spanish

Extending Rational Functional Tester

One of the biggest advantages of using Rational Functional Tester is its ability to be extended with any number of open source components. GUI automation developers often run into test tool limitations, but with Rational Functional Tester's extensibility, we can often remove these limitations. This article shows you how to use Selenium and FlexMonkium with Rational Functional Tester to test Adobe Flex or Flash applications

The challenges of testing browser-based Flex applications

We can probably all agree that the most often patched or updated software in general use today is Internet browsers and the Flash plug-ins that they support. Because Flex applications typically run on browsers within the Flash plug-in, these Flex apps create challenges for automation testing tools to be able to consistently recognize the GUI test objects within the application under test (AUT). Imagine building an automation framework to test your enterprise Flex app, and then having that framework be "broken," possibly a couple of times a month, because of browser or Flash plug-in security patches. It becomes apparent that you need a more consistent Flex GUI object recognition solution to keep up with the frequent plug-in patches.

Advantages of extending with Selenium and FlexMonkium

The Selenium suite of tools is designed to provide seamless automation testing of browser-based applications. The Selenium development team works closely with the browser development teams to make sure that browsers interoperate with their testing tools consistently. For our purposes, Selenium-RC is the perfect solution for passing the Flex test commands from Rational Functional Tester to the browser application with little worry of browser security patches getting in the way.

The FlexMonkium tools provide a consistent Flex application GUI object recognition solution with strong support for the constant Flash plug-in updates. FlexMonkium offers these comprehensive sets of tools:

FlexMonkiumConsole

Used for GUI object discovery and recording 
FlexMonkium SWC

A lightweight automation_monkey.swc file compiled into your AUT to "enable" Flex automation 

Combined, Selenium and FlexMonkium offer strongly supported components that work seamlessly together to provide a consistent Flex application automation solution.


How this combination works together

The separate components all play important roles. Let's take a look at how they work together.

Rational Functional Tester

Rational Functional Tester is used for what it does best in this solution:

  • Extensible Eclipse IDE for developing and containing your Java or JUnit test scripts and code
  • Test execution platform to launch tests and log results

Selenium

Selenium is used mostly for interoperability between Rational Functional Tester and the browser that hosts the Flex application:

Selenium IDE

This is used to record automation scripts that can be exported or converted to the JUnit code. 
Selenium-RC

This component is used as the HTTP bridge from the Rational Functional Tester JUnit code to the browser that contains the Flex application. The commands contained in your JUnit code are passed and executed as JavaScript commands, which all browsers understand. 

FlexMonkium

FlexMonkium is used for Flex automation script recording, Flex GUI object recognition or discovery, and for interoperability between Selenium-RC and the Flex application.

FlexMonkiumConsole

When combined with the Selenium IDE, the console provides an easy-to-use Flex application GUI automation recorder. Recorded scripts are then exported as JUnit code for use in Rational Functional Tester. 
FlexMonkium SWC

Compiled as part of your Flex application build, this component essentially turns on automation for the target application. 

Getting started

Prerequisites

  • Rational Functional Tester installed and ready to run
  • Firefox 3 browser installed (newer versions of Firefox should also work)
  • Include automation_monkey.swc from the Gorilla Logic website (see the Resources section of this article) in your target Flex application.

Component setup

Tip:

See the Resources section of this article for links to the required downloads and installation instructions mentioned in this section.

  1. Download and install the Selenium IDE. The Selenium IDE is an Add-on (extension) to Firefox and can be opened as a sidebar after you have it installed (Firefox > View > SideBar > Selenium IDE).
  2. Download the latest Selenium-RC (also known as Selenium Server) Java archive (JAR) file, selenium-server-standalone-2.x.x.jar.
  3. Download the latest Selenium Client Driver for Java .zip file, selenium-java-2.x.x.zip, and extract the JAR files, which you will include in your Rational Functional Tester project.
  4. Download the latest FlexMonkium.zip file from the Gorilla Logic website, and extract the contents to a local directory.
  5. Install the FlexMonkiumConsole using the FlexMonkium installer, and take note of the location where you have installed it.
  6. Install the flexmonkium.xpi plug-in, which comes with the FlexMonkium.zip file, into Firefox. This can be done either by dragging the .xpi file into Firefox or opening the .xpi file in Firefox.
  7. Start the Selenium-RC/Selenium Server and apply the user-extensions.js provided in the FlexMonkium.zip file. The following command run in a Microsoft Windows command prompt should work:
    java –jar path/selenium-server-standalone-2.x.x.jar –userExtensions path/user-extensions.js

Rational Functional Tester configuration

  1. Create a new Project in Rational Functional Tester to contain your Flex automation:
    RFT > New > Functional Test Project.
  2. Enable Firefox as your default browser for Rational Functional Tester:
    Configure > Enable Environments for Testing > Mozilla Firefox > Set as Default
  3. Add a "lib" directory to your project:
  1. Right-click your project and select Add Test Folder.
  2. Name the folder lib, and click Finish.
  1. In the lib directory of your new Rational Functional Tester project, import the selenium-java-2.x.x.jar file by right-clicking on the lib directory and selecting Import > General > File System and then selecting the selenium-java-2.x.x.jar file. Click Finish to import the file.
  2. Update your Rational Functional Tester project's build path by right-clicking on the project name and selecting Properties. Then select Java Build Path > Add Jars > your project name > lib > selenium-java-2.x.jar > OK.
  3. Depending on your setup of Rational Functional Tester, you might need to import and include more of the files that were downloaded as part of the Selenium Client Driver for Java .zip file (selenium-java-2.x.x.zip). If your Rational Functional Tester project runs into compilation or runtime problems, your first action should be to import and include these files in your project's Java Build Path.

Recording and generating JUnit code

You will use the Selenium IDE sidebar within Firefox and the FlexMonkiumConsole to record test scripts and to discover the Flex application's GUI object properties.

Discover Flex GUI object properties

You might eventually want to create a data-driven automation framework for your Flex app testing, and the GUI object properties allow you to map and recognize your test objects within your framework. In a Flex app, each GUI object can be given a unique identifier (for example, the "Id" property) by the development team while they build the application. These steps show you how to discover these properties:

  1. Open Firefox and point to the URL of your target Flex application.
  2. Open the Selenium IDE sidebar by selecting Firefox > View > Sidebar > SeleniumIDE, as shown in Figure 1.
Figure 1. Selenium IDE sidebar and target application
Firefox with Selenium sidebar displayed
  1. Ensure that the Selenium IDE + FlexMonkium is recognizing the Flex application by first starting the FlexMonkiumConsole, as shown in Figure 2.
Figure 2. Open the FlexMonkiumConsole (click the black icon)
Red arrows points to FlexMonkiumConsole icon
  1. Now check the connection status of the FlexMonkiumConsole and the Flex app. The green light should be on (see Figure 3).
    • If it is not, you need to debug issues with your application and the automation_monkey.swc file that you compiled with your build.
    • If the green light is on, then you are now able to record scripts and object properties within the target Flex application.
Figure 3. Check the FlexMonkium status
FlexMonkiumConsole icons
  1. Inspect GUI object properties in the target Flex app by clicking the green checkmark in the FlexMonkiumConsole window and hovering your cursor over the GUI objects that you would like to inspect. The object that you are inspecting will be highlighted by a red outline, and you see will some of the object's properties displayed, as Figure 4 shows.
Figure 4. Inspect GUI objects in the Flex app
GUI object inspection
  1. If you would like to see all of the properties for the GUI object that you are inspecting, click that object to open the window shown in Figure 5.
Figure 5. View expanded Flex object properties window
Verify Component Properties view

Record test scripts and export to JUnit code

The Selenium IDE and FlexMonkiumConsole work well to record and play back various testing actions. But, ultimately, you'll need to be able to run these through Rational Functional Tester, where you can build a data-driven automation framework. The steps that follow show you how to record simple scripts and export them to JUnit code that you can run from Rational Functional Tester.

  1. Close all browsers, and open Firefox to the URL of your target Flex application.
  2. Open the Selenium IDE sidebar: Firefox > View > Sidebar > SeleniumIDE (see Figure 6). Notice that the red "Record" button is depressed by default.
Figure 6. Firefox and Selenium IDE sidebar ready to record
Selenium IDE recording
  1. Complete some actions within your Flex app, and notice the commands that get captured in the Selenium IDE sidebar, as shown in Figure 7.
  2. Click the red Record button to stop recording at this point.
Figure 7. Record actions and view the captured commands
Recorded commands in Selenium IDE
  1. Export JUnit code from the Selenium IDE, click File > Export Test Case As > FlexMonkium (JUnit) – Selenium – RC as shown in Figure 8.
Figure 8. Export JUnit code for use in Rational Functional Tester
Export JUnit code menu selected
  1. You will be prompted to export the code to a file name of your choice. The code is exported in the format of a Java class file, so you can save the file as either a .txt or a .java file, if you like. For the purposes of this demo, save the file with ExportedCode.java as the file name.

See Listing 1 for an example of what the JUnit code will look like.

Listing 1. Example of exported JUnit code
package tests;
import com.thoughtworks.selenium.*;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

public class ExportedCode {
 private Selenium selenium;
 private HttpCommandProcessor proc;

 @Before
 public void setUp() throws Exception {
 proc = new HttpCommandProcessor
("localhost", 4444, "*firefox", "http://9.75.229.34:8080/");
 selenium = new DefaultSelenium(proc);
 selenium.start();
 }

 @After
 public void tearDown() throws Exception {
 if (selenium != null) {
 selenium.stop();
 selenium = null;
 }
 }

 @Test
 public void myTestMethod() throws Exception {
 selenium.open("/optim/console#");
 for (int t = 0;; t++) {
 if (t >= 60) fail("timeout");
 try {

 if (proc.getBoolean("isFlexMonkey", new String[] {"<UIEvent command=\"SelectText\" 
value=\"userNameTextInput\"><arg value=\"0\"/><arg value=\"0\"/></UIEvent>"})) break;
 } catch (Exception e) { }
 Thread.sleep(500);
 }

 for (int t = 0;; t++) {
 if (t >= 60) fail("timeout");
 try {
 if (proc.getBoolean("isFlexMonkey", new String[] {"<UIEvent command=\"Input\" 
value=\"userNameTextInput\"><arg value=\"test\"/></UIEvent>"})) break;
 } catch (Exception e) { }
 Thread.sleep(500);
 }

 for (int t = 0;; t++) {
 if (t >= 60) fail("timeout");
 try {
 if (proc.getBoolean("isFlexMonkey", new String[] {"<UIEvent command=\"Input\" 
value=\"passwordTextInput\"><arg value=\"test\"/></UIEvent>"})) break;
 } catch (Exception e) { }
 Thread.sleep(500);
 }

 for (int t = 0;; t++) {
 if (t >= 60) fail("timeout");
 try {
 if (proc.getBoolean("isFlexMonkey", new String[] {"<UIEvent command=\"Click\" 
value=\"Login\"/>"})) break;
 } catch (Exception e) { }
 Thread.sleep(500);
 }

Running exported test cases

The "generated" code shown in Listing 1 leaves much to be desired. It should be cleaned up considerably for use in whatever framework you plan to set up. For the purposes of this demo, you can create a Rational Functional Tester test script and call the exported or generated methods directly from the testMain(Object[] args)contained by default in all Rational Functional Tester scripts.

  1. Create a new package in your Rational Functional Tester project called tests, and import the ExportedCode.java file that you created earlier into this "tests" package.
  2. Create a new Rational Functional Tester test script by selecting RFT > New > Empty Functional Test Script. Give your test script a name, and click Finish.
  3. In the testMain(Object[] args) method, add code similar to what Listing 2 shows.
Listing 2. Rational Functional Tester test script example
import resources.TestScriptHelper;
import tests.ExportedCode;

/**
 * Description : Functional Test Script
 * 
 */
publicclass TestScript extends TestScriptHelper {
   publicvoid testMain(Object[] args) {
      ExportedCode expCode = new ExportedCode();
      try {
         expCode.setUp();// Setup AUT and Selenium components for testing
         expCode.myTestMethod();// Run recorded Flex test scripts
         expCode.tearDown();// Bring down AUT and Selenium components
      } catch (Exception e) {
 e.printStackTrace();
 }
 }
}
  1. Now you can run a test. Click the Play button (green circle) in the toolbar, as shown in Figure 9.
Figure 9. Run or play back a Flex app test in Rational Functional Tester
Test script open, ready to run

Larger view of Figure 9.


Consider building an automation framework

Rational Functional Tester lends itself very well to developing data-driven automation frameworks, because it is essentially a full-blown Java IDE that you can extend any way that you need to in order to solve various automation problems. Here are several points to consider for a Flex automation framework:

  • Declare the Flex app's GUI objects in an objects.properties file, rather than in code.
  • Store your test data in a flat file, CSV file, or a database, and use it to drive your tests. Record and Playback is a maintenance nightmare in the long run.
  • Create action or fill helper methods for each Flex object type, so you can easily call these methods from within your framework
  • Implement an expanded logging solution for your framework. There are many extensions available from other sources to improve on Rational Functional Tester logging.

Summary

As described here, the extension of Rational Functional Tester with Selenium and FlexMonkium creates a consistent, strongly supported Flex application automation testing platform that can be built into a powerful automation framework.


Acknowledgements

Thanks to Sunaina Gupta and Tom Hammell for recommending the FlexMonkium possibility and for helping with the proof of concept. Additional thanks to Carlo Yaralian and Connie Ko for their help in implementing these tools in a real-world environment.

Resources

Learn

Get products and technologies

  • Try Rational Functional Tester free requires registration).
  • Evaluate IBM software in the way that suits you best: Download it for a trial, try it online, use it in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement service-oriented architecture efficiently.

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=791488
ArticleTitle=Extend Rational Functional Tester to test Adobe Flex or Flash applications
publish-date=02072012