How do you write your QTP Tests?

Josh Harris picture Josh Harris · Dec 16, 2009 · Viewed 7.9k times · Source

I am experimenting with using QTP for some webapp ui automation testing and I was wondering how people usually write their QTP tests. Do you use the object map, descriptive programming, a combination or some other way all together? Any little code example would be appreciated, Thank you

Answer

Albert Gareev picture Albert Gareev · Dec 17, 2009

Here's my suggestion.

1) Build your test automation requirements matrix. You can use samples from my blog

http://automation-beyond.com/2009/06/06/qa-test-automation-requirements-usability/

http://automation-beyond.com/2009/06/07/qa-test-automation-requirements-usability-2/

http://automation-beyond.com/2009/06/10/qa-test-automation-requirements-5-maintainability/

http://automation-beyond.com/2009/06/08/qa-test-automation-requirements-robustness/

http://automation-beyond.com/2009/06/09/qa-test-automation-requirements-scalability/

2) Choose your automation approach

3) Write your testing scripts according to the approach you chose

Note. QTP Repository way or Descriptive Programming belong to GUI recognition part of front-end functional test automation. They matter in terms of robustness and maintenance. Technically, it's nearly the same. In both cases you should understand GUI recognition concept well, or you will have problems no matter the approach.

  • You can store GUI object recognition properties in XML-like data structure and map the record to an English-like name. Whenever the original object's properties change, you update your record in repository, while a code still refers to a mapped name.
  • Or you can address GUI objects by directly putting same recognition properties into a function call. Whenever the original object's properties change, you have to do code change. But you don't have to maintain extra files along with your scripts.

A good framework should support both GUI-mapped and descriptive programming notations by operating at object reference level. I.e. you should keep object recognition and object interaction tasks separate.

Note that depending on context Descriptive Programming notation may slowdown performance of your scripts and it always demands extra maintenance effort while in other cases using Object Repositories only may lead to unwanted duplication of objects' descriptions or it may limit recognition of dynamically changing GUI.
I illustrate some points made above in the following article: A little QTP performance test: Object Repository vs. Descriptive Programming

Straight code examples (for a practical automation I recommend GUI Function Wrapping).

Descriptive programming - addressing objects by physical description properties.

Dim sProfile
sProfile = "Guest"

Set objWebParent = Browser("title:=Select Profile").Page("title:=Select Profile")
Set objWebObject = objWebParent.Link("text:="&sProfile) 
boolRC = objWebObject.Exist(0) 
If Not boolRC Then
'error-handling
End If
objWebObject.Click

Addressing objects by mapped GUI names

Browser("Select Profile").Page("Select Profile").Link("Guest").Click

Thank you,
Albert Gareev
http://automation-beyond.com/