如何使用iMacros进行web程序中页面加载的性能测试

来源:互联网 发布:戒指的牌子有哪些 知乎 编辑:程序博客网 时间:2024/05/16 07:19

iMacros 的官方简介如下,这里就不做翻译了,本人觉得还是看原汁原味的介绍好。

iMacros is an extension for the Mozilla Firefox web browsers which adds record and replay functionality similar to that found in web testing and form filler software. The macros can be combined and controlled via Javascript. The extension was developed by iOpus. The current stable release of iMacros is version 0.9.0.2, released on July 7, 2007. As of July 14, 2007 iMacros is one of the TOP 10 most popular Firefox extensions in the Bookmark, Web Data, Alerts, and Widgets and Social and Sharing categories.

iMacros is also available as a free Internet Explorer Add-On and (with additional features) as commercial application for Web Scripting, Web Scraping and Web Testing. The Scripting Interface of the iMacros Scripting Edition is a COM object and allows the user to remote control (script) the Internet Explorer and Firefox web browser from any Windows programming or scripting language.

接下来说一说如何具体操作吧,首先应该从iMacros的官网上下载该程序的最新版本,然后安装到本地就可以了。打开后入下图。


因为该软件具有录制和回放的功能,因此我们可以先进行对要测试页面的录制,然后稍稍对录制后的脚本进行修改,就可以用来做页面加载的性能测试了。本例就以登录google.com 然后搜索iPhone5为例来进行讲解。

1. 在地址栏中输入google.com;

2.点击iMacros的Record tab;

3.点击Record button;

4.在搜索框中输入iPhone5;

5.点击搜索button;

6. 结束录制;

在第六步结束后我们会得到一个名字为#Current.iim的脚本:

VERSION BUILD=7401598
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://www.google.com/    {在状态栏中输入google}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:gbqf ATTR=ID:gbqfq CONTENT=iPhone5   {在搜索栏中输入iPhone5}
TAG POS=1 TYPE=BUTTON:SUBMIT FORM=ID:gbqf ATTR=ID:gbqfb   {点击搜索按钮}
TAG POS=1 TYPE=B ATTR=TXT:iPhone<SP>5   {得到搜索结果}
TAG POS=1 TYPE=IMG ATTR=SRC:http://images.apple.com/iphone/images/product_title.png  {确认得到iPhone的官网}

这个时候如果我们要对从点击搜索按钮到确认得到iPhone的官网之间的操作用了多少时间的话,我们可以对以上脚本做如下简单修改。

VERSION BUILD=7401598
TAB T=1
TAB CLOSEALLOTHERS
SET !TIMEOUT_STEP 20
SET !REPLAYSPEED FAST
URL GOTO=http://www.google.com/
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:gbqf ATTR=ID:gbqfq CONTENT=iPhone5
STOPWATCH ID=iPhone5
TAG POS=1 TYPE=BUTTON:SUBMIT FORM=ID:gbqf ATTR=ID:gbqfb
TAG POS=1 TYPE=B ATTR=TXT:iPhone<SP>5
TAG POS=1 TYPE=IMG ATTR=SRC:http://images.apple.com/iphone/images/product_title.png
STOPWATCH ID=iPhone5

修改后将要测试的操作用STOPWATCH包住,然后将该文件命名为IPhone5.iim。然后再次运行修改后的脚本就可以得到相应的时候了。看看运行一次的结果时间是多少。

在如下的目录查看结果:C:\Documents and Settings\Administrator\My Documents\iMacros\Downloads\performance_IPhone5.csv


同时该软件还提供了重复运行的功能,测试人员可以修改某一个脚本运行的次数,然后将运行的结果求平均值后就可以得到某一个页面的性能值了。