Thursday, September 9, 2010

iMacros: Measuring Web Response Time

Introduction

It's hard to imagine a life without internet in the present age of communication. Internet is being used for just about anything ranging from getting a recipe to finding an address or researching on some topic. With the increase in the number of users on the internet, it has become imperative that the website responds to the user requests, with the latest research indicating that if a website takes more than 2-3 seconds, you start deeming it slow even though it has a lot of graphic content to render. Hence it has become a critical performance test to note the response times of your website even if it is launched on an intranet.

Measuring response times of websites can be done in the following context:

*
Checking the response times with the different system configurations of the web server on which the website is hosted.
*
Compare the response times of websites with different builds.
*
Noting the impact of adding graphical content to the website on the response times of websites.
*
Noting the impact of adding same graphical content in different formats (e.g. split images instead of a single big image).
*
Comparing the query performance for a web request exercising the database for different query implementations

This article discusses about an Add-on from firefox that helps the users to find the response times of your website. It also details on how Python scripts could be used to automate the same.
iMacros Overview

iMacros, an Add-On from Firefox, is a fairly simple record and playback tool that helps the user in the following different ways:

*
Downloading and Uploading Files from internet.
*
Automatically filling web forms
*
Performance testing of websites via Browser (Single-user)
*
Reading the web pages and importing the data to CSV files

More on iMacros here.

This article concentrates on “Web based performance testing” and details on how one of the features of the iMacros Add-on can be used to find the response time of a Website.
Tool Specifications
Add-on Version 6.6.5.0
Firefox support Firefox 3.0 - 3.6
OS Version Win 2K and above
Language English, French, German, Russian
Using iMacros

To get up and running with iMacros:

*
On the firefox browser go to Tools → Add-ons
*
Under Get Add-ons tab, search for iMacros
*
Click on 'Install Now' to install the add-on
*
Firefox browser gets restarted and you can use it by browsing to View → Slide Bar → iOpus iMacros

iMacros is now ready for use.

On the left-hand side of your home page you would see an iMacros pane as below:

imacro.jpg
Configuration

As mentioned earlier, iMacros is a record and playback tool. Let's check out the pane in detail to see how tests can be recorded and re-run.

The pane that we saw above contains three main tabs:
Play

*
Play - This option starts replaying the recorded tests for the user.
*
Pause - While the recorded tests are replayed, this option can be used to pause the test.
*
Stop - While the recorded tests are replayed, this option can be used to stop the test.
*
Repeat Macro - This option is used to reiterate the recorded tests for N number of times. Current - depicts the current iteration of the tests and Max - depicts the maximum of number of iteration a user wants to re-run the recorded test.
*
Play (Loop) - Enables the user to re-play/start the recoded tests for N iterations as mentioned under 'Repeat Macro' option.

Rec

*
Record - By clicking this user can start recording the tests.
*
Save - This option would the user to save the tests recorded. This will pop-up a Save File window that asks for 'Name' denoting the name of test and 'Create in' denoting the where the user wants to store the recorded test. It gets stored as .iim file and is also known as a Macro.
*
Load - Will open up a 'Select file to load' pop-up that suggests that the user can load the Macro (earlier recorded test) for re-run.
*
Stop - User can stop recording of the tests using this option.
*
Click Mode/Auto - This option enables how the links are recorded. Links can be recorded by:
1.
Using complete HTM tag.
2.
Using X/Y position of the link.
3.
User can choose either of them OR can go for 'Auto' mode where the Add-on uses the correct configuration for itself.
*
Save Page As - This option can be used to save the current page as .htm in the desired location.
*
Take Screenshot - Option for taking the screenshot of the current page. File is stored in a user defined location as .png.
*
Del. Cache&Cookies - This option would delete the cache and cookies of the firefox browser at the global level.
*
Wait during Play - This option enables the user to put a delay at a certain page, while re-runing the test. 'Wait Parameter' pops up and asks the user to enter the value of delay in seconds.

Edit

*
Edit Macro - It opens up the current Macro (#Current.iim) so that it could be edit.
*
Share Macro - macros can be shared by:
o
Copying as a link that can be pasted on to a browser for direct use.
o
Sending the macro using email application your system (e.g. outlook).
o
Adding it on any of the social bookmarking service. (e.g. blogger).

*
Refresh Macro List - Refreshes all the Macros under 'Favorites' tab of the iMacros pane.
*
Options: It enables the user to allow certain domains from running the shared macros. Domains not listed under this, will not be allowed to run a shared macro.
*
Help - Takes the user to the wiki page of iMacros.

Recording a Macro

A macro can be recorded by performing the following steps:

*
On the iMacros pane go to 'Rec' tab.
*
Make sure you are the web page from where you want to start the test.
*
Press the 'Record' button to start recording the test.
*
Perform all the browsing events that you need to test. iMacros would be recording the actions that you perform.
*
Click on 'Stop' to stop recording the tests.
*
'Save' can be used to save the Macros. (default path: \My Documents\iMacros\Macros).

Case Study: Measuring Response Times

Let us take an example. Here's a macro that I recorded for the case study purpose.

VERSION BUILD=6600217 RECORDER=FX
TAB T=1
URL GOTO=http://www.google.co.in/
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=ChetanAppTimer
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:f ATTR=NAME:btnG&&VALUE:GoogleSearch
TAG POS=1 TYPE=A ATTR=TXT:TestingPerspective-RahulVerma'sWebsiteonSoftwareTesting

This is what the above Macros does:

*
launches “www.google.com”
*
Inputs a string “Chetan AppTimer” and clicks on the Search button
*
Clicks on the “Testing Perspective” link found by google search.

Note The above macro would work only if the above search result is found on the first page (which was the case at the time this macro was recorded)
Measuring Response Time

This script can now be tweaked to measure the response times. It can be achieved by using a simple feature in iMacros called STOPWATCH. Here's how we use it.

VERSION BUILD=6600217 RECORDER=FX
TAB T=1

SET !FILESTOPWATCH C:\logs.csv

STOPWATCH ID=Opening_Google
URL GOTO=http://www.google.co.in/
STOPWATCH ID=Opening_Google

TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=ChetanAppTimer

STOPWATCH ID=Google_Search
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:f ATTR=NAME:btnG&&VALUE:GoogleSearch
STOPWATCH ID=Google_Search

STOPWATCH ID=Opening_TestingPerspective
TAG POS=1 TYPE=A ATTR=TXT:TestingPerspective-RahulVerma'sWebsiteonSoftwareTesting
STOPWATCH ID=Opening_TestingPerspective

In this Macro we have added certain statements:

*
SET !FILESTOPWATCH C:\logs.csv – This suggests that we have set a STOPWATCH on some of the operations in our recorded test and we are logging the measurements made by the add-on in “C:\logs.csv” file.
*
STOPWATCH ID=Opening_Google – This suggests that we have added a STOPWATCH on opening www.google.com. (“Opening_google” can be referred to as Transaction name as done in some commercial performance testing tools)

By enabling the STOPWATCH option for all operations in our earlier recorded script, we can easily get the response times for each operation. In the modified code, we can get the response times of:

*
Opening www.goolge.com.
*
Searching time for “Chetan AppTimer” on www.google.com.
*
Opening of www.testingperspective.com/doku.php/collabration/chetan/apptimer1.

The macro can be run in 'Play (Loop)' mode to perform N iterations.
Results and Data Analysis

We are logging the measured response times in C:\logs.csv file. Attached is the snapshot of the log file. The test was run for four times. Log file shows all the three measurements with the timestamp.

logs.jpg

After getting the measurements for four runs, the user can take an average of all the measurements under same category like “Opening Google” and get the closest approximate of the response time of www.google.com.

Similarly, the user can run the test N number of times and get the response times of websites or sub-sections of the website. Here N denotes the number of iterations a user wants to run the test for depending on the performance criterion set by the him/performance testing team.

The usual statical equivalence criteria should be employed while averaging the response times.
Application in Performance Testing

1.
As a Probing Client: A probing client is the replacement for a human tester who checks and records the response time of the website during the actual multi-user performance testing is in progress. IMacros can be a very effective way of doing this job in a consistent manner.
2.
One can build a multi-threaded solution on top of iMacros using a language of choice and later process the response time data collected to see the application behavior on a certain user load. Could be an easy way of testing small scale websites. This would be especially helpful when one is not conversant with elaborate performance testing tools or has access to tools which do not have good record/playback feature (HTTPS traffic recording is a usual lacking feature seen in free tools)

Automation Outlook

Once the tests are recorded you would want to run them with every test cycle. You can easily automate this process in either of the two ways:
Using iMacros.exe

imacros.exe is a freely available tool and can be downloaded here. You could use imacros.exe from the command line. Here are some of the commands that can be used to automate the tests:

Commands

*
Runs the macro from a desired location on the hard drive.

imacros.exe -macro \Sample.iim

*
Runs the macro in a loop with N iterations.

imacros.exe -macro \Sample.iim -loop N

*
Runs the macro with N iterations in background without actually opening up the browser instance.

imacros.exe -macro \Sample.iim -loop N -silent

*
Runs the macro with parameters.

imacros.exe -macro \Sample.iim -var_myvar

Results of the test

After running the commands on the CmdLine, you could check the results of the tests by checking on the ENV variabale %ERRORLEVEL%.

Success: %ERRORLEVEL% = 1
Failure: %ERRORLEVEL% != 1 (Value is negative)

Running the automation

*
Create a Batch file.
*
Enter in all the commands for all the macros that you want to run.
*
Double-Click and run the batch script to start running the automation.
*
Alternatively, you could also schedule it with DOS 'AT' command.

Using firefox application

Here is a simple example that shows how the macro can be run using firefox.exe.

"c:\program files\mozilla firefox\firefox.exe" http://run.imacros.net/?m=Sample.iim

Using Python Script

Here's a small Python script that can automate the tests.

def automateIMacros(macros_file_path):
import win32com.client
w=win32com.client.Dispatch("imacros")
w.iimInit("", 1)
w.iimPlay(macros_file_path)

if __name__=='__main__':
automateIMacros("")


Automation scripts for Perl, Powershell and VB could be found on iMacros wiki
Known Issues and Limitations

*
The tool itself provides response time for s single user. You would have to build a multi-user environment on top of the tool by employing a language of choice (Python/Perl/VB etc.)
*
Mainly available for Firefox, though an extension for IE is available now as well.

No comments:

Post a Comment