RSS

Adding Network Conditions to a QTP Script – Part 1

Mon, Mar 2, 2009

Tips and Tricks

Quick Test Pro (QTP) is a very useful functional testing tool and now as a result of the Shunra-HP partnership, QTP can integrate with Shunra VE Desktop Professional to automate the testing and analysis of applications under network conditions.

In the following series of posts I will walk you through the process of extending QTP scripts to:

  1. Test an application under network conditions such as latency, packet loss and limited bandwidth (this post)
  2. Analyze the performance of application transactions under network conditions (part 2 in this series)
  3. Automatically execute a test for application performance from different simulated network sites (part 3 of this series)

This series will be making use of 3 tools which should be installed on the same machine:

Quick Test Pro from HP Software, Shunra VE Desktop Professional and Shunra VE Analyzer (optional)

We will begin with a very simple QTP script recorded against the HP demo server hosted at http://newtours.demoaut.com.

In the beginning of the process the script looks like this:

Services.StartTransaction "Sign In"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "amichai"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "49875eac11258595e0335617ec51bad1590a"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 21,4
Services.EndTransaction "Sign In"
Services.StartTransaction "SearchFlights"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("findFlights").Click 42,13
Services.EndTransaction "SearchFlights"
Services.StartTransaction "SignOff"
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Link("SIGN-OFF").Click
Services.EndTransaction "SignOff"

The first step in integrating QTP with VE Desktop Professional is to load the VE Desktop Professional COM object, this will be done in a code block that is located before the QTP action steps as follows:

'Load the COM interface for VE Desktop API
Set ctrl = CreateObject("ShunraVEAPI.ShunraVEDController")

Next we will activate the network conditions. This function takes, as input, a value for latency [msec] packet loss [%] and bandwidth [kbps where 0 = unlimited]

(NOTE: For some reason WordPress doesn’t allow the larger than and less than signs, so if you copy paste the code below, replace the Is Not statement with the appropriate logical operator)

'Activate the following network conditions 50 msec latency, 0% packet loss and unlimited bandwidth (0)
returnStatus = ctrl.StartAdvanced(50,0,0)
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "Start Advanced", text
End If

By adding the 2 function calls above, the same QTP script will now run under the defined network conditions. We now simply have to remove those network conditions at the end of the script and release the COM object.

'Stop the network impairments
returnStatus = ctrl.StopTest()
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "StopTest", text
End If

'Release the COM object
Set ctrl = Nothing

The complete script now looks as follows:

'Load the COM interface for VE Desktop API
Set ctrl = CreateObject("ShunraVEAPI.ShunraVEDController")

' Activate the network conditions 50 msec latency, 0% packet loss and unlimited bandwidth (0)
returnStatus = ctrl.StartAdvanced(50,0,0)
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "Start Advanced", text
End If

'BEGINNING OF THE QTP ACTION
Services.StartTransaction "Sign In"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "amichai"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "49875eac11258595e0335617ec51bad1590a"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 21,4
Services.EndTransaction "Sign In"
Services.StartTransaction "SearchFlights"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("findFlights").Click 42,13
Services.EndTransaction "SearchFlights"
Services.StartTransaction "SignOff"
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Link("SIGN-OFF").Click
Services.EndTransaction "SignOff"
'END OF THE QTP ACTION

'Stop the network impairments
returnStatus = ctrl.StopTest()
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "StopTest", text
End If

'Release the COM object
Set ctrl = Nothing

Here is a version of the script with a few safety checks at the beginning.

We first remove any previous network conditions by stopping the VE Desktop test. Then we checkout a license, in case the floating license for the VE Desktop client has expired. At the end of the script we return the floating license to the license server by calling the license checking function. The complete script is presented below:

'Load the COM interface for VE Desktop API
Set ctrl = CreateObject("ShunraVEAPI.ShunraVEDController")

'Just in case network conditions are already applied , stop the VED test
returnStatus = ctrl.StopTest()
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "StopTest", text
End If

' check out a license from the VED server
returnStatus = ctrl.LicenseCheckout(5)
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "License Checkout", text
End If

' Activate the network conditions 50 msec latency, 0% packet loss and unlimited bandwidth (0)
returnStatus = ctrl.StartAdvanced(50,0,0)
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "Start Advanced", text
End If

'BEGINNING OF THE QTP ACTION
Services.StartTransaction "Sign In"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "amichai"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "49875eac11258595e0335617ec51bad1590a"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 21,4
Services.EndTransaction "Sign In"
Services.StartTransaction "SearchFlights"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("findFlights").Click 42,13
Services.EndTransaction "SearchFlights"
Services.StartTransaction "SignOff"
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Link("SIGN-OFF").Click
Services.EndTransaction "SignOff"
'END OF THE QTP ACTION

'Stop the network impairments
returnStatus = ctrl.StopTest()
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "StopTest", text
End If

returnStatus = ctrl.LicenseCheckin()
If returnStatus Is Not 0 Then
	ctrl.GetLastError returnStatus, text
	Reporter.ReportEvent  micFail, "License Check In", text
End If

'Release the COM object
Set ctrl = Nothing
, , , , , , , , , ,

share

0 Comments For This Post

1 Trackbacks For This Post

  1. Adding Network Performance Analysis to a Quick Test Pro Script | Application Performance Management Blog - Shunra Software Says:

    [...] is the second post in the series that covers the use of QTP with VE Desktop. In the previous post I showed you how to add network conditions to a QTP [...]

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes