Flex & QTP Automation Testing

While there is not much source available out there about how to prepare QTP (HP QuickTest Professional) automation test environment working with flex applications, I decided to write this post. It is not clear, nor straightforward for one who never ran QTP, and while I spend just a few hours preparing the test environment, I hope this article will help some of you to get started much faster. Basicaly what you need is QTP 11, Internet Explorer 8 (unfortunately), Flex Automation Plug-in and flex automation framework (.swc classes)…

First you need to download and install QTP from HP. To locate a download link appeared to be a few hour investigation thanks to internet full of broken links. Finally I hit this nice article Update: Download and Install QTP describing all the download process hell. Basicaly downloads are available after login on hp.com and you should be looking for HP Functional Testing 11.00 Evaluation. There were some installation steps and additional dependecies and software within the installation, but default settings worked for me.

Next, I spend few hours looking for a valid firefox or chrome plugin to work with QTP, but unfortunately non worked. After I surrendered and decided to use Internet Explorer, it appeared that only IE 8 worked with QTP 11. Does it need any comment describing my anger downgrading to version 8? :) … yeah, you just have to, no other way.

Once you have QTP 11 and IE 8 installed, you should be already able to do some recording with html webpages etc.

Flex Automation Plug-in from Adobe contains .bat executables that register proper .dlls so that is not much work with it, just download and run.

There are 2 possible ways described on Adobe Help of how you can make flex qtp framework work for your application. You can “include-libraries” directly into your app or you can create an application wrapper with libraries included that loads your application.swf via SWFLoader. I played with the idea of having the automation framework classes available through PreloadSWF in mm.cfg (some more reading about PreloadSWF) but it appeared that the classes from preloaded .swf appears in different application domain… and while automation framework classes are unfortunately initialized staticaly (mixin), there is no elegant way to initialize them on components on different application domain. I end up with my custom wrapper, that has some changes against the template from flex sdk (…/4.1.0.16076/templates/automation-runtimeloading-files/runtimeloading.mxml):

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx"
                creationComplete="init()">
    <fx:Script>
        <![CDATA[
            public function init():void
            {
                var pointerKey:String = "automationswfurl";
                var variables:URLVariables = new URLVariables;
                for(var key:String in parameters)
                    if(key != "automationswfurl")
                        variables[key] = parameters[key];
                
                swfLoader.loaderContext = new LoaderContext(false, ApplicationDomain.currentDomain)
                swfLoader.source = parameters.automationswfurl + "?" + variables.toString();
            }
        ]]>
    </fx:Script>
    <mx:SWFLoader id="swfLoader" width="100%" height="100%"/>
</s:Application>

… and ant build script:

<?xml version="1.0" encoding="UTF-8"?>
<project name="AppStudio application" default="main">
	<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
	
	<target name="main">
		<mxmlc file="${basedir}/src/main/flex/QTPWrapper.mxml" output="${OUTPUT}" target-player="${TARGET_PLAYER}" 
			static-link-runtime-shared-libraries="false" debug="${DEBUG}">
			<compiler.include-libraries dir="${FLEX_HOME}/frameworks/libs/automation" append="true">
				<include name="automation.swc" />
				<include name="automation_agent.swc" />
				<include name="automation_dmv.swc" />
				<include name="automation_flashflexkit.swc" />
				<include name="automation_spark.swc" />
				<include name="qtp.swc" />
			</compiler.include-libraries>
		</mxmlc>
	</target>
</project>

There were some more issues and random compile time as well as runtime errors exceptions after including flex automation and qtp libraries, however some unexpectedly disappeared with release build and some were manualy investigated and removed.

Where to go from here:

2 comments so far

  1. JustSomeGuy August 20, 2012 21:48

    The fact that you made this work is nothing short of heroic! I’m still struggling days later, after starting with QTP, giving up, trying flexMonkey, flexUnit, RIAtest and others which just confused the hell out of me and I gave up on.
    Now back to QTP, fun fun.
    Including Libraries has not worked for me as my application has too complex of a setup…I will try your wrapper technique

    Thank you

  2. Jozef Chúťka August 21, 2012 09:53

    hi,
    even if you may have some luck with QTP, when doing a research and playing with it I always had the feeling that qtp is dead. For flex projects I would recommend you to try genie http://sourceforge.net/adobe/genie/wiki/Home/

Leave a comment

Please be polite and on topic. Your e-mail will never be published.