Flex 自动化测试

自动化测试工具有QTP, RFT等,下面就介绍下用RFT测试Flex (SDK version: 2.0.1)的步骤:

RFT(Rational Functional Test)是IBM开发的一套自动化测试工具,可以测试web, GUI和console。

[size=large]前提条件:[/size]

1. Flex SDK installed
2. RFT installed
3. jdk installed
4. flex automation support available

如果没有装Flex automation软件,可以下载包含下面两个文件的附件
automation_agent.swc
automation_agent_rb.swc


[size=large]准备工作:[/size]

1. 复制automation_agent.swc 到 /Flex SDK 2/frameworks/libs 目录下

2. 复制automation_agent_rb.swc 到 /frameworks/locale/en_US 目录下

3. 打开IE[Internet Options] - [Security] - [Local Intranet],

点击[Custom Level],设置安全级别为[Medium-low],

将[Initialize and script ActiveX controls not marked as safe for scripting]设置为Enabled


RFT测试Flex必须要准备Flex test automation runtime环境,两种方式:

[size=large]1. 将Runtime的swf文件嵌套在html页面中,被测flex以参数传进去[/size]

a. 从RFT的安装目录里找到RuntimeLoader.mxml and RuntimeLoadingTest.html

b. 编译RuntimeLoader.mxml文件,加入runtime支持:

%FLEX_BUILDER_DIR%\bin\mxmlc.exe -include-libraries+="%FLEX_BUILDER_DIR%\frameworks\libs\automation.swc;%FLEX_BUILDER_DIR%\frameworks\libs\automation_agent.swc;%FLEX_BUILDER_DIR%\frameworks\libs\automation_charts.swc;%IBM_RATIONAL_RFT_INSTALL_DIR%\rft.swc;%IBM_RATIONAL_RFT_INSTALL_DIR%\rftProp.swc"; %1

注:如果FLEX_BUILDER_DIR或IBM_RATIONAL_RFT_INSTALL_DIR没有设置到系统环境变量中,请替换成实际路径。

把上面这段代码复制并保存为flex_automation.bat文件中,然后运行命令


flex_automation.bat RuntimeLoader.mxml


可以使用ant脚本:

<target name="flexAutomation" depends="initProperties">
<property name="FLEX_HOME" value="E:/Program Files/Flex_2"/>
<property name="rftBinDir" value="C:\Program Files\IBM\SDP\FunctionalTester\bin" />

<for param="fileName">
<path>
<fileset dir="flex/src">
<include name="RuntimeLoader.mxml"/>
</fileset>
</path>
<sequential>
<mxmlc file="@{filename}" keep-generated-actionscript="true">
<source-path path-element="flex/locale"/>
<compiler.include-libraries dir="${FLEX_HOME}/frameworks/libs">
<include name="automation.swc"/>
<include name="automation_agent.swc"/>
<include name="automation_charts.swc"/>
</compiler.include-libraries>
<compiler.include-libraries dir="flex/lib">
<include name="graphLayout.swc" />
<include name="unComponentToolbox.swc" />
<include name="PrimitiveIcons.swc" />
</compiler.include-libraries>
<compiler.include-libraries dir="${rftBinDir}">
<include name="rft.swc"/>
<include name="rftProp.swc"/>
</compiler.include-libraries>
</mxmlc>
</sequential>
</for>
<copy todir="D:/" preservelastmodified="yes">
<fileset dir="flex/src">
<include name="RuntimeLoader.swf"/>
</fileset>
</copy>
</target>


c. 把生成的RuntimeLoader.swf、RuntimeLoadingTest.html和被测试flex文件(testApp.swf)一同拷贝到web容器目录下

d. 开启web服务,在url输入下面字符串:
http://localhost/RuntimeLoadingTest.html?automationswfurl=testApp.swf

现在就可以用RFT去抓取Flex对象了。


[size=large]2. 重新编译被测flex code, 加入Runtime支持[/size]

a. 和上面方法的b步骤一样,这里只要运行:


flex_automation.bat testApp.mxml


b. 生成一个testApp.html文件,里面嵌套testApp.swf


...

<object id="myFlex" ... >
<param name="movie" value="testApp.swf"/>
...
<embed src="testApp.swf" ... >
</embed>
</object>

...



c. 把testApp.html和testApp.swf一起拷贝到web容器目录下

d. 开启web服务,在url中键入以下字符串:

[quote]
http://localhost:8080/testApp.htm
[/quote]

[size=large]注意:[/size]

1. 准备工作3必须要做,IE的默认设置会阻止Flex automation runtime运行(因为没有标记为安全的)

2. 直接输入http://localhost:8080/testApp.swf是可以显示Flex的,但不能够被测试

3. 第一种方案是把识别Flex组件的swc编译到一个RuntimeLoader.swf中,被测试的swf不需要添加这些swc。
第二种方案是把每个要测试的swf文件重新编译,加入支持的swc。

在实际生产环境中,如果swf文件需要从其它地方接受数据,第二种方案比较合适,但也会造成swf文件增大,性能降低。

4. 这里的测试是基于Flex SDK 2.0.1的,如果是其他版本的,请搜索网上其它文档。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值