The human context of quality

QuickTest Pro first learnings

Posted on 2009-Jan-27 at 06:53

In the past month I have been working with HP QuickTest Pro (QTP) in my job. Our company makes a complex application which includes a web server application and a custom installer for client-side files. We have a library of automated tests in WinRunner that need to be migrated to QTP, so I have been working on that.

QTP claims that it can be used for "keyword-based" testing using record, playback, and object repositories. That approach can work but it is pretty limited, and I quickly had to move beyond it to use the "descriptive programming" feature in most of my code. In descriptive programming, objects are identified dynamically at run time rather than using an object repository. I was quite comfortable with this, because I have worked with web automation tools such as Watij where there is no object repository, all object identification happens at runtime.

Several reason why descriptive programming was necessary in my case:

  • In our company we have multiple "environments" including several internal test environments and production environment. These have different web addresses, so object repositories recorded in one environment will not work in another. I do not want to create duplicate tests for each environment.
  • During installation, our installer has two browser windows with the same title at one point, but slightly different URL. When using an object repository, the test would not pass consistently because QTP was unable to tell the difference between the two windows.
  • Our application is highly customizeable and looks slightly differently for different customers. Again, object repositories record in one customer environment would not generally work in another because of different window titles.

Descriptive programming with regular expressions and wildcards is helpful with dealing with these kinds of issues. I was able to write test cases that would work across multiple test environments, multiple customizations, and consistently find the right window.

Another issue I ran into was that our application has custom menus that are WebElement objects created dynamically on a mouseover event. QTP's Object Spy and Update Objects feature would not see them. I worked around this using the SendKeys function from Windows Scripting Shell. Not elegant but reliable.

A final issue I had to solve was that the internal test environments have different response times. I initially put Wait statements into the code to make sure that screens were present before acting on them. But because of the different timing this would sometimes not work and was inefficient because for long time the automation was doing nothing. Sync statement also did not always work because some of our pages update several times before they are really finished loading. So I wrote this:

Function WaitUntilObjectFound(obj, timeOut)
 Dim timeElapsed, returnVal
 timeElapsed = 0
 returnVal = true
 Do Until obj.Exist(1)
  timeElapsed = timeElapsed + 1
  If timeElapsed >= timeOut Then
   returnVal = false
   Exit Do
  End If
 Loop
 WaitUntilObjectFound = returnVal
End Function

This function will check for the existence of an object approximately every second and will return if the object exists or if the function times out. This code will work for any object that has an Exist property. It works great for waiting for child dialogs or child windows. It will return prematurely if the object you are trying to check the existence of is hidden by another active window. For instance, if obj is a main window, and a child window pops up, Exist will return false and the function will exit even though the main window still "exists".

I expect that most of this is not news to testers who have been working with QTP for a while. Record and playback is only useful as a first step, as a tool to learn how QTP sees objects. Descriptive programming is the only way to go for real world applications and robust test automation frameworks.


Last Page | Page 14 of 15 | Next Page
To realize that you do not understand is a virtue; Not to realize that you do not understand is a defect.
Lao Tzu

Friends