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 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 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 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.
- 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.
Tip:
See the Resources section of this article for links to the required downloads and installation instructions mentioned in this section.
- 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).
- Download the latest Selenium-RC (also known as Selenium Server) Java archive (JAR) file, selenium-server-standalone-2.x.x.jar.
- 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.
- Download the latest FlexMonkium.zip file from the Gorilla Logic website, and extract the contents to a local directory.
- Install the FlexMonkiumConsole using the FlexMonkium installer, and take note of the location where you have installed it.
- 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.
- 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
- Create a new Project in Rational Functional Tester to contain your Flex
automation:
RFT > New > Functional Test Project. - Enable Firefox as your default browser for Rational Functional Tester:
Configure > Enable Environments for Testing > Mozilla Firefox > Set as Default - Add a "lib" directory to your project:
- Right-click your project and select Add Test Folder.
- Name the folder
lib, and click Finish.
- 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.
- 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.
- 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:
- Open Firefox and point to the URL of your target Flex application.
- Open the Selenium IDE sidebar by selecting Firefox > View > Sidebar > Selenium IDE, as shown in Figure 1.
Figure 1. Selenium IDE sidebar and target application
- 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)
- 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
- 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
- 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
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.
- Close all browsers, and open Firefox to the URL of your target Flex application.
- Open the Selenium IDE sidebar: Firefox > View > Sidebar > Selenium IDE (see Figure 6). Notice that the red "Record" button is depressed by default.
Figure 6. Firefox and Selenium IDE sidebar ready to record
- Complete some actions within your Flex app, and notice the commands that get captured in the Selenium IDE sidebar, as shown in Figure 7.
- Click the red Record button to stop recording at this point.
Figure 7. Record actions and view the captured commands
- 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
- 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.javaas 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);
}
|
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.
- 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. - 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.
- 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
*
*/
public class TestScript extends TestScriptHelper {
public void 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();
}
}
}
|
- 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
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.
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.
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.
Learn
- Links to download applications:
- Download the Firefox browser from the Mozilla website.
- Download and install the Selenium components from the Selenium HQ website.
- Download and install the FlexMonkium components from the Gorilla Logic website.
- Visit the Rational Functional Tester area on developerWorks for introductory to
in-depth information. Explore the Rational Functional Tester Information Center, where you can also take a
short video tour. Investigate Rational Functional Tester Plus, which is a software application testing
bundle.
- Visit the Rational software area on
developerWorks for technical resources and best practices for Rational
Software Delivery Platform products.
- Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics.
- Attend a free developerWorks Live! briefing to get up-to-speed quickly on IBM products and tools, as well as IT industry trends.
- Watch developerWorks on-demand demos, ranging from product installation and setup demos for beginners to advanced functionality for experienced developers.
- Improve your skills. Check the Rational training and
certification catalog, which includes many types of courses on a wide range
of topics. You can take some of them anywhere, any time, and many of the "Getting
Started" ones are free.
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
- Get involved in the developerWorks Functional and GUI Testing discussion forum where you can
discuss and ask questions about Rational Functional Tester and general testing
topics.
- Rate or review Rational software. It's quick and easy. Really.
- Share your knowledge and help others who use
Rational software by writing a developerWorks article. Find out what makes a good developerWorks article and how to proceed.
- Follow Rational software on Facebook, Twitter (@ibmrational), and
YouTube, and add your
comments and requests.
- Ask and answer questions and increase your
expertise when you get involved in the Rational
forums, cafés, and wikis.
- Get social about thought leadership. Join the Rational community to share your
Rational software expertise and get connected with your peers.
- Connect with others who share your interests by
joining the developerWorks
community and responding to the developer-driven blogs.





