18 July 2011
Familiarity with basic test automation concepts will be helpful. Knowledge of Flex applications and Flash Builder will be needed to introduce a defect into the sample application.
Intermediate
Additional required other products
RIATest 4
This article explains how to begin testing your Flex application with RIATest 4. RIATest (see Figure 1) is a multiplatform test automation tool that uses the Flex Automation Framework to automate user interactions with GUI components in Flex applications. It uses a simple scripting language that is similar to ActionScript. RIATest can automate Flex 2, Flex 3, Flex 4.x, and Flex 4.5.x applications. Both browser-based and desktop AIR applications are supported.
In this article, you are going to create and execute an automated test for a basic browser-based Calculator application, which is included with the sample files for this article.
To test a Flex application you need to perform the following four steps:
A set of test scripts for your application is called a project. The project defines the scripts themselves and in what order they will be executed. In RIATest, the Project View shows the Project Tree, which contains all scripts in the project. You can combine scripts into groups. You can change the ordering of the scripts (and thus the execution order) by dragging and dropping script items in the tree.
Before you create your first project, you'll need to set up a Flex application to test. Download the sample file for this article, Calculator.zip, and import it into Flash Builder.
Next, after downloading and installing RIATest, follow these steps to create your first project:
This is the simplest of the Loading Type options available for Flex applications. With this option selected, RIATest will open a special preloader called Runtime Loader in the browser, which will in turn load your application SWF file for testing.
A new RIATest project will be created at the specified location and an empty Startup.rts test script will be added to it (see Figure 3).
You can now launch the Flex application in preparation for recording your first test.
The browser opens and the application is loaded. You can see the Calculator application in the browser, looking exactly as it would normally. In addition, the RIATest Agent toolbar is also visible. The Agent toolbar title indicates that RIATest is Ready (see Figure 4).
You can now start recording a test.
At this point, you can start interacting with the Flex application just as if you were using it normally. All of your actions will be recorded. For this example, you'll calculate 12+15, and then convert it to hexadecimal using the Radix drop-down list.
As you can see, several lines of script have been recorded. Each line corresponds to an action that you performed on the application. For example when you clicked the down arrow of the drop-down list, line 7 was recorded:
SparkDropDownList("radix")=>open();
This line says that an open action was performed on a SparkDropDownList component named radix .
Next, you'll add a verification statement to your test. Verification statements are normally added to your tests when you want RIATest to verify certain properties of the application's user interface components during execution of the test. Failures will be reported if the properties do not match the expected values. There are a number of different verification statements, which are documented in the RIATest manual. In this example, you'll use a basic verification statement to verify the result of the calculation.
To add a verification for the calculation result field, you use the RIATest Inspect function and point to the result field that you want to verify.
SparkTextInput("editNum") . The RIATest Object Inspector (see Figure 7) appears.
You can see the tree of GUI components on the left, with the editNum field selected and the properties of the component listed on the right.
Next, you'll add a verification for the text property of the result field to ensure that it has the value 1B .
Another window appears that lists the properties of the result text field (see Figure 8).
text property is selected for verification so simply click OK.
You can see that a verifyEqual statement has been created (see Figure 9). This statement will verify the text property of the editNum element during the playback of the test.
You have finished recording your first test.
You have created a project and recorded the first test. Now you're ready to run the test and see the results.
The browser window opens, the application is loaded, and the actions that you recorded are performed on the application. Wait until the test is finished and the browser window is closed.
The results of the test are shown in the RIATest IDE. You can see the duration of the test and that the overall result is ALL OK (see Figure 10).
Note: If you are using the trial version of RIATest, you will see WARNINGS FOUND instead of ALL OK, and in the execution log you'll see a warning that reminds you when the trial will expire.
The results also include statistics for startup, shutdown, and each script in the project. In this case, there is only one script in the project. You can see that 8 actions and 1 verification were performed.
You can see the actions and the one verification that you defined. If you click a line number, RIATest will show the actual script line that corresponds to the message.
You can see that the verification was generated by the verifyEqual statement that you created earlier.
To see how RIATest reports errors, you'll need to change the application so that it no longer works correctly.
Calc() function:case '+': res = lastVal + val; break;
case '+': res = lastVal + val + 1; break;
Now you can run the test again and see how RIATest identifies the problem in the application.
The test starts running and then the RIATest IDE appears (see Figure 12). You can see that the execution is suspended on the verifyEqual statement and an error message is displayed. The message says that the text of the editNum field does not match the expected value.
The results of the test now indicate that errors were found (see Figure 13).
That's all there is to it. You have successfully created a simple RIATest project, recorded a test, run the test, and checked the results.
Take a few minutes to explore RIATest further. You can create a new test by right-clicking the project and selecting Add New Script. You may want to create another project and start testing your own Flex application.
Functional testing and regression testing can be time-consuming and error-prone when performed manually. Automating these tests using RIATest is a straightforward way to save time and ensure your tests are completed accurately every time.
For more information on RIATest, visit www.riatest.com.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License