IBM® Rational® Functional Tester enables you to automate regression testing of applications in various domains, such as Java, HTML, .NET, Microsoft Silverlight, Adobe Flex, and Dojo Toolkit. Version 8.2.1 added support for testing Flex Spark applications, along with several other new features. This article covers setup and script creation to test Flex Spark applications. You will learn how to enable the Spark application so that Rational Functional Tester can identify Spark controls. This will give you a better understanding and make it easier for you to use Rational Functional Tester for Flex Spark test automation.
- Rational Functional Tester 8.2.1 or later version.
- Adobe Flash Builder 4.0 or later
- Adobe Flash Player 10.0 or later
- Microsoft Internet Explorer or Mozilla Firefox browser
- Java Runtime Environment (JRE)
Overview of Rational Functional Tester Flex testing support
Rational Functional Tester supports testing of Flex applications built on Flex SDK 2.0, onward. With the release of Flex 4, a new skin component architecture for Flex user interface components called Spark was introduced. Rational Functional Tester Version 8.2.1 onward supports testing of applications containing Flex Spark controls if they are built on Flex SDK 4.0 or 4.1. Testing of Flex applications requires steps to enable the Flex application so that it can be tested with Rational Functional Tester. Enablement involves adding reference to automation libraries in the Flex application. This can be done either at source code level or as runtime enablement. This article covers the enablement at source code level.
Add a reference to automation libraries in the Flex application
Flex application testing automation with Rational Functional Tester requires adding references to both Flex and Functional Tester Flex automation libraries. These libraries are actually the .swc files for automation. The Flex automation libraries get installed with Flash Builder, and the counterparts get installed with Rational Functional Tester.
You can use any of the following three ways to add references to automation libraries, and the subsections here explain each of them:
- Add a reference in the Flash Builder IDE
- Add a reference using the Rational Functional Tester Configure Application wizard
- Add a reference by using the command line
Method 1. Add a reference in the Flash Builder IDE
- Start Flash Builder 4.0 or later, and create a new Flex project.
- Import the attached TestSparkwithRFT.mxml application.
- Select Flex Project > Src > Package.
- Right-click on the package, and click Import.
- Select General > File System.
- Click Next.
- Browse to the directory where the .mxml file is stored. From the right pane, select the .mxml file, and click Finish.
- Go to Project > Properties > Flex Compiler.
- In the Additional Compiler arguments text box, add the libraries from Listing 1.
Listing 1. Libraries to add
-locale en_US -include-libraries "C:\Program Files\Adobe\Adobe Flash Builder 4.x\sdks\ 4.x\frameworks\libs\automation\automation.swc" "C:\Program Files\Adobe\Adobe Flash Builder 4.x\sdks\4.x\ frameworks\libs\automation\automation_agent.swc" "C:\Program Files\Adobe\Adobe Flash Builder 4.x\sdks\4.x\frameworks\libs\automation\automation_spark.swc" "C:\Program Files\Adobe\Adobe Flash Builder 4.x\sdks\4.x\frameworks\libs\automation\ automation_dmv.swc" "C:\Program Files\IBM\SDP\FunctionalTester\bin\rftFlex4.0.swc" "C:\Program Files\IBM\SDP\FunctionalTester\bin\rftProp_Flex4.0.swc"
4.x with appropriate Flash Builder and SDK versions in the above argument.
The path above is ideal in a 32-bit system. You need to modify the argument to point to the correct location of .swc files. After adding the above arguments, any Flex Halo or Spark application created in this project will be ready to be tested with Rational Functional Tester.
This code is intentionally broken to fit on the screen. Use the code listing download file for the proper code.
Figure 1. Flash Builder Project > Properties wizard with additional compiler arguments
- Click Apply and then OK.
Flash Builder will compile the .mxml file, and the corresponding .swf and .html files will be created in the bin-debug location of the Flex Project. In this case, these two files will be generated:
The Flex Spark application will be tested by using this .html file.
Method 2. Add a reference using the Rational Functional Tester Configure Application wizard
- Copy the attached TestSparkwithRFT.mxml file (see Downloads) into a directory on your C:\ drive. For example:
- Launch the Application Configuration Tool wizard by selecting - Configure Applications for Testing from the Rational Functional Tester perspective.
- In the Application Configuration Tool wizard, click the Add button.
- Select Flex Application in the wizard, and then click Next.
Figure 2. The Add Application wizard
- Select Configure Flex application setup, and click Next.
Figure 3. Select the Flex application configuration type
- In the Flex application configuration wizard, select:
- Local Application
- Flex SDKs as 4.0/4.1 (because Spark support is from Flex 4.x onward)
- OS type for your system
- Click Browse (the one against the Application text box) to select the Flex Spark Application file.
- Click Browse (the one against the SWF Target Location) to select the directory where the compiled Flex Spark Application .swf file should be generated.
Figure 4. The Add Application wizard to select Flex application configuration parameters
- Select the Generate HTML Page check box so that an HTML page is generated corresponding to this Flex Spark application.
Flex applications can be tested only when they are loaded in an HTML browser. Rational Functional Tester does not support Flex applications in stand-alone Flash players.
The enabled HTML text box is populated based on the SWF Target location.
- Click Finish.
Notice that Spark application appears in the Applications list in the Application Configuration Tool. You could rename the added application at this point.
Method 3. Add a reference by using the command line
- Unzip the attached file in a location on your system. For example:
- Start the command prompt (preferably an Adobe command prompt or a Microsoft Visual Studio command prompt).
- Go to the directory of the application (the directory of the unzipped file, which is C:\TestFlexSpark in this case).
- Run the batch file provided in the compressed file at the command prompt with the name of the .mxml file (also shown in the screen capture in Figure 5:
Figure 5. Command prompt showing the command to execute the batch file
Appropriate batch files are provided in the Flex directory of the Rational Functional Tester installation.
After executing the above command, this swf file is generated:
When you have this .swf file, you can embed it in an HTML page, for example TestSparkwithRFT.html (which contains the code in Listing 2) by using an object or embed tag as shown here.
Listing 2. Source code of the HTML page to load the Flex swf
<HTML> <HEAD><TITLE>Flex Sample Application Testing</TITLE> </HEAD> <BODY> <HR> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="myapp" width="100%" height="100%" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> <param name="movie" value="TestSparkwithRFT.swf" /> <param name="quality" value="high" /> <param name="bgcolor" value=#CCCCCC /> <param name="allowScriptAccess" value="sameDomain" /> <embed src="TestSparkwithRFT.swf" quality="high" bgcolor=#CCCCCC width="100%" height="100%" name="myapp" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" plug-inspage="http://www.macromedia.com/go/getflashplayer"> </embed> </object> </BODY> </HTML>
You can use the same HTML file for other Flex applications by changing just the .swf name in that code snippet.
Recording on a Flex application
If you followed the second method above, the Flex application is already configured, and you can see it listed in the StartApplication wizards list.
In the first and third methods, you can configure the Flex Spark application for testing by pointing to the corresponding HTML page.
- Launch the Application Configuration Tool wizard by selecting Configure Applications for Testing from the Rational Functional Tester perspective.
- In the Application Configuration Tool wizard, click the Add button.
- In the Add Application wizard, select Flex Application, and then click Next.
- Select Add URL of Flex Application.
Figure 6. Add Application wizard to add URL of the Flex application
- In the text box, provide the path of the HTML file. For example, if you used the third method, you add this path:
- Click Finish.
The Spark application now appears in the Applications list in the Application Configuration Tool.
Record the test script
After you have configured the application, you are ready to start recording the test script against your Spark application.
- Start recording the Rational Functional Tester script by clicking Record.
- Enter the script name, select the script folder location, and then click Finish.
- Click Start Application in the recording window to select the Flex Spark application that you configured earlier.
The application starts in Internet Explorer (or your default browser). You can perform actions on the controls, and those actions get recorded.
Example of a recorded script
After you complete your test scenario, stop the recording, and the test script will be generated as shown in the sample test script in Figure 7, which shows that the Flex Spark objects and their corresponding events have been recognized. This enables users to capture and play back GUI-level interactions, to verify data and property, and to do data drive on Spark controls.
Figure 7. A sample Rational Functional Tester script with actions recorded on Flex Spark controls
Figure 8. Sample object map shows hierarchy and properties of Spark controls
A few mandatory steps
To test Flex applications, the browser being used should be enabled. Enable the browser using the Enable Environments for Testing wizard of Rational Functional Tester, and ensure that the browser enablement test passes.
The application should be running from a trusted directory. Follow these steps to assign trust designations:
- Create a folder FlashPlayerTrust in one of these:
- C:\WINDOWS\system32\Macromed\Flash on a 32-bit system
- C:\Windows\SysWOW64\Macromed\Flash on 64-bit system
- Create a file named
Flexwithout any file extension in the FlashPlayerTrust folder.
- Type the directory path of the Flex application in the Flex file. For example, in above case (in the second or third method) the Flex application is in C:\TestFlexSpark, so type the path in the Flex file as
- Save the file.
- Allow the ActiveX plug-in to load by clicking Yes on the warning dialog prompt when you load the Flex application in the browser.
If you are using the default HTML page generated by the Flash Builder IDE, the Flex controls do not get recognized.
- Open the HTML page in an editor.
- Delete this statement, which is at the beginning of the HTML page:
<!-- saved from url=(0014)about:internet -->
Due to this statement, Rational Functional TesterFlexPlugin.dll does not get loaded in the browser, and that Flex application cannot be tested. If you are using Flash Builder and want to test those applications, modify the template of the HTML page to exclude that statement.
On a Microsoft Windows server, Rational Functional Tester needs to be run as administrator to record on Flex applications.
- Error shown in Flash Builder IDE after adding the additional compiler arguments
Make sure that the path of the .swc files is correct.
- The HTML page is blank after using the second method
Check whether the .swf file is created in the directory. If the .swf file is not created in the directory, see the instructions for the next problem.
- When using the second method to add a reference, the .bat and .html files are is generated but no .swf file is generated
Try to execute the batch file manually at the command prompt. It will show the exact error, which could be related to the path of the .swc files. If the path of .swc files is not correct, modify the .bat file to point to the correct location of the .swc files, and then execute the batch file manually at the command prompt again. This should generate the required .swf file.
For future references, it is advisable to modify the path in the FlexInstallInfo.properties file in the Flex directory of the Rational Functional Tester installation. Modifying the path in this file is a one-time task and resolves the problem while generating the .swf file using the Rational Functional Tester Application Configuration wizard. Restart Rational Functional Tester after modifying the FlexInstallInfo.properties file.
- If you get this exception while executing the batch file manually (as mentioned in the previous problem):
Exception in thread "main" java.lang.UnsupportedClassVersionError: flex2/tools/Mxmlc (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
Please set JAVA_HOME variable to point to higher version of JDK as jdk 1.6.
- Nothing gets recorded though the environment is setup correctly.
Try these steps, and then restart the application"
- Access Settings Manager for your Flash Player.
- Open an application in Flash Player.
- Right-click and select Settings.
- Select the Privacy tab.
- Click Advanced. Adobe Flash Player launches a new browser window and loads the Settings Manager help page.
- Click the Global Security Settings link to open the Global Security Settings window.
- Add your application directory to the Secured or Trusted directory. In the "Always trust files in these locations" drop-down menu, click Add location, and browse for the location.
For more information about setting the security configuration, see the Adobe Web site.
|Code listing 1||FlexSpark-listing1.txt||1KB|
|Flex Spark sample||FlexSparkSample.zip||3KB|
|Test Spark with RFT||TestSparkwithRFT.zip||6KB|
- For more about Rational Functional Tester:
- Check 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.
- Additional useful information about Flex testing with Rational Functional Tester:
- Get more information from Adobe about these features: Using the Security panel of the Settings Manager.
- Visit the Rational software area on developerWorks for technical resources and best practices for Rational Software Delivery Platform products.
- Subscribe to the developerWorks weekly email newsletter, and choose the topics to follow. Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics.
- 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
- Download trial versions of IBM Rational software.
- Download these IBM product evaluation versions and get your hands on application development tools and middleware products from DB2®, Lotus®, Tivoli®, and WebSphere®.
- Get involved in the developerWorks Functional and GUI Testing forum, which is a place for users of Rational Functional Tester and for the discussion of general testing topics.
- Check out developerWorks blogs and get involved in the developerWorks community.
Dig deeper into Rational software on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Keep up with the best and latest technical info to help you tackle your development challenges.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.