Tutorial: Testing Adobe Flex Applications

Top  Previous  Next

Contents

 

Introduction

Prerequisites

Create a Simple Flex Application: Hello Flex

Enable HelloFlex Application for Testing

  Link HelloFlex with Necessary Libraries

  Add HelloFlex to FlashPlayerTrust

Record a Simple Test

Execute the Test        

Using FlexLoader

See Also

 

Introduction

After going through this tutorial you’ll get a basic idea of how to test browser-based Flex applications with SmarteStudio.

 

Prerequisites

This tutorial assumes that you have installed:

1.SmarteStudio
2.Adobe Flex Builder 3 (http://www.adobe.com/cfusion/entitlement/index.cfm?e=flexbuilder3)

 

Create a Simple Flex Application: HelloFlex

Let’s start from creation of a very simple Flex application.

1.Create home directory for the application: C:\HelloFlex. You may create any other directory that is more suitable for you, just do not forget to change corresponding paths used in this tutorial.
2.Create main file of the application: C:\HelloFlex\HelloFlex.mxml. Place the following code in it:

<?xml version="1.0" encoding="utf-8"?>

 

<mx:Application 

    xmlns:mx="http://www.adobe.com/2006/mxml" 

    viewSourceURL="src/HelloFlex/index.html"

    horizontalAlign="center" verticalAlign="middle" 

    width="640" height="480"

>

    <mx:Script>

        <![CDATA[

            import mx.controls.Alert;

        ]]>

    </mx:Script>

    <mx:Panel 

        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"

        title="My Application"  

    >

 

    <mx:Label text="Hello Flex!" fontWeight="bold" fontSize="24"/>

    <mx:Button id="button" label="Button" click="{Alert.show('Button Pressed');}"/>

 

    </mx:Panel>

</mx:Application>

 

3.Create wrapper HTML for the application: C:\HelloFlex\HelloFlex.html. Place the following code in it:

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>HelloFlex</title>

</head>

 

<body scroll="no">

       <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

                       id="HelloFlex" width="100%" height="100%"

                       codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">

                       <param name="movie" value="HelloFlex.swf" />

                       <param name="quality" value="high" />

                       <param name="bgcolor" value="#869ca7" />

                       <param name="allowScriptAccess" value="sameDomain" />

                       <embed src="HelloFlex.swf" quality="high" bgcolor="#869ca7"

                               width="100%" height="100%" name="HelloFlex" align="middle"

                               play="true"

                               loop="false"

                               quality="high"

                               allowScriptAccess="sameDomain"

                               type="application/x-shockwave-flash"

                               pluginspage="http://www.adobe.com/go/getflashplayer">

                       </embed>

       </object>

</noscript>

</body>

</html

 

4.Compile the application (make sure that mxmlc.exe is available in command line window. If Flex Builder is installed then it is available at: "c:\Program Files\Adobe\Flex Builder 3\sdks\<SDK Version>\bin\mxmlc.exe")

       a) Open CMD window in C:\HelloFlex directory

       b) Run command: mxmlc HelloFlex.mxml

HelloFlexMxmlc

 

5.Test the application by opening C:\HelloFlex\HelloFlex.html in Internet Explorer.

HelloFlexTest

 

Enable HelloFlex Application for Testing

To make HelloFlex application testable by SmarteStudio you need to link it with automation libraries.

 

Link HelloFlex with Necessary Libraries

Recompile HelloFlex application using the following command line that links automation.swc and automation_agent.swc from Flex Builder 3 and FlexAdapter.swc from SmarteStudio:

 

mxmlc HelloFlex.mxml -locale en_US -include-libraries="c:/Program Files/Adobe/Flex Builder 3/sdks/<Version>/frameworks/libs/automation_agent.swc","c:/Program Files/Adobe/Flex Builder 3/sdks/<Version>/frameworks/libs/automation.swc","c:/Program Files/SmarteSoft/SmarteStudio/Extensions/Flex/FlexAdapter/bin/FlexAdapter.swc"

 

HelloFlexBuild

 

Add HelloFlex to FlashPlayerTrust

Adobe Flash Player has restricted security settings for SWFs opened from file system. To enable testing of such SWFs their corresponding folders must be listed in FlashPlayerTrust directory.

 

Path to FlashPlayerTrust directory:

 

to enable testing for all users:

<system>\Macromed\Flash\FlashPlayerTrust

 

to enable testing just for current user:

<ApplicationData>\Macromedia\Flash Player\#Security\FlashPlayerTrust

 

(on Vista this path looks like:

c:\Users\<User Name>\AppData\Roaming\Macromedia\Flash Player\#Security\FlashPlayerTrust

)

 

To register your SWF just create a file with the name "<name of your SWF>.cfg" and put it in this directory. In the file write a path to SWF folder.

 

Note: If you do not have FlashPlayerTrust directory in one of locations listed above then you will have to create missing directories yourself.

 

To register c:\HelloFlex\HelloFlex.swf

       a) create file <ApplicationData>\Macromedia\Flash Player\#Security\FlashPlayerTrust\HelloFlex.cfg

       b) add this to the file: c:\HelloFlex

FlashPlayerTrust

 

Record a Simple Test

1.Open C:\HelloFlex\HelloFlex.html in Internet Explorer.
2.Start SmarteStudio and press Record/Learn button

HelloFlexTest1

 

3.Choose HelloFlex application and press Select, recording will start.

HelloFlexTest2

 

4.In HelloFlex application press Button and then press Ok in the alert message.

HelloFlexTest3

 

5.Then press Verify button on Recording activity dialog and click on "Hello Flex!" label. In Verify Object Properties dialog check Enabled property.

HelloFlexTest4

 

6.You have recorded three basic steps of your test.

HelloFlexTest5

 

7.Press Finish button on Recording activity dialog. You now have recorded the test.

HelloFlexTest6

 

Execute the Test

 

Execute the test by pressing the Play button in SmarteStudio.

 

Congratulations! You have successfully completed this tutorial and now know basics of testing Flex applications with SmarteStudio.

 

Using FlexLoader

If you do not want to compile your application with automation libraries you have an option to use FlexLoader.

 

FlexLoader is a Flex 3 application compiled with required automation libraries and capable of loading any given SWF application. With FlexLoader you do not need to modify your application to make it testable by SmarteStudio.

 

To use FlexLoader just copy FlexLoader.html and FlexLoader.swf from c:/Program Files/SmarteSoft/SmarteStudio/Extensions/Flex/FlexLoader/bin to your web server near your application. Then type in browser URL to FlexLoader.html and supply additional query parameter with the name of your SWF file, e.g.:

http://localhost/FlexLoader.html?automationswfurl=Sample.swf

You can find sample application for testing here: c:/Program Files/SmarteSoft/SmarteStudio/Extensions/Flex/FlexLoader/bin/Sample.swf

 

See Also

Adobe Flex