Tuesday, December 15, 2009

How to work with QTP

Sponsored Ad

Working with Large Object Hierarchies (Siebel Objects)

I received an e-mail from Suni Reddy, who asked me to share with her an easy way of working with Siebel objects – primarily because of their giant object hierarchy. I have thought about it several times, but because our work on Siebel goes on a temporary basis, I was never able to come up with something. Until now. This news story will portray how you can generate a single library with all the parent objects and call those objects on demand.
Normally, if you would like to select an item from a SiebList, you would do something like:


SiebApplication("MyApplication").SiebScreen("MyScreen").SiebView("MyView")_
    .SiebApplet("MyApplet").SiebList("MyList").Select "Open"


The above hierarchy can be greatly simplified – and this editorial will show a few ways how it can be achieved. Also, the way we’re going to structure our hierarchy, changing two object in a single place will account for an overall alter. In other words, in lieu of changing a single object multiple times (because something changed in the application) we’ll alter it only two times.

 

With Statements

This is by far the most common approach used when dealing with large hierarchies, and quite simple too. However, as the parent objects change, we end up creating more and more blocks of such statements. An example of With..End With statement in use:

 

  1.     With SiebApplication("MyApp").SiebScreen("MyScreen1").SiebView("MyView").SiebApplet("MyApplet")
  2.     .SiebList("MyList").Select "Open"
  3.     .SiebButton("MyButton").Click
  4. End With
  5. 'SibScreen changes from MyScreen1 to MyScreen99: re-write.
  6. With SiebApplication("MyApp").SiebScreen("MyScreen99").SiebView("MyView").SiebApplet("MyApplet")
  7.     'your code
  8. End With

Using Functions to Build Sieb Hierarchy

This technique uses several functions to create an entire hierarchy, but the result is good. Moreover, it also simplifies how events are performed on objects. Let's start building our first function of the database object (SiebApplication):

  1. 'Base Object: SiebApplication
  2. Function oSiebApplication
  3.     Set oSiebApplication = SiebApplication("MyApp")
  4. End function
  5. Let’s create instances for our Child objects:
  6. 'oSiebScreen retrieves its parent (oSiebApplication) from the function above
  7. Function oSiebScreen
  8.     Set oSiebScreen = oSiebApplication.SiebScreen("MyScreen")
  9. End Function
  10. 'oSiebView_ retrieves its parent (oSiebScreen) from the function above
  11. Function oSiebView
  12.     Set oSiebView = oSiebScreen.SiebView("MyView")
  13. End Functions
  14. 'oSiebApplet retrieves its parent (oSiebView) from the function above
  15. Function oSiebApplet
  16.     Set oSiebApplet = oSiebView.SiebApplet("MyApplet")
  17. End Function
  18. To demonstrate, if we want to set a value in the “lstApplication1″ SiebList, we can simply do the following:
  19. oSiebApplet.SiebList("lstApplication1").Select "Urgent"

Using Classes

This is my favorite, and very similar to what we have above, but the advantage of using this technique is that we have several multiple parenting classes or one class to the group at all. Suppose we have the following hierarchy, with an even

  1.     
  2.     SiebApplication("MyApp").SiebScreen("MyScreen").SiebView("MyView")_
  3.     .SiebApplet("MyApplet").SiebList("lstApplication1").Highlight
  4. First, let’s create a sample class for the Base object(s) that will be common for all classes.
  5. 'Demo class for the top-most object (Parent Class)
  6. Class clsSiebApplication
  7.     Public Property Get oSiebApplication
  8.         Set oSiebApplication = SiebApplication("MyApp")
  9.     End Property
  10. End Class
  11. Now, let’s build the child classes, that will use the base class to complete object hierarchies:
  12. 'Child Class: Derives its Base Object from clsSiebApplication (Parent Class)
  13. Class clsSiebObjects
  14.     Private oShared
  15.     'We will reuse the Base class to retrieve some common objects
  16.     'An instance of the base class will be initialized as the class loads
  17.     Private Sub Class_Initialize        
  18.         Set oShared = new clsSiebApplication
  19.     End Sub
  20.     'Terminate the instance while exiting.
  21.     Private Sub Class_Terminate        
  22.         Set oShared = Nothing
  23.     End Sub    
  24.     'oSiebScreen Property will retrieve its parent from oSiebApplication
  25.     Public Property Get oSiebScreen
  26.         Set oSiebScreen = oShared.oSiebApplication.SiebScreen("MyScreen")
  27.     End Property
  28.     'oSiebView Property will retrieve its parent from oSiebScreen (above)
  29.     Public Property Get oSiebView
  30.         Set oSiebView = oSiebScreen.SiebView("MyView")
  31.     End Property
  32.     'oSiebApplet Property will retrieve its parent from oSiebView (above)
  33.     Public Property Get oSiebApplet
  34.         Set oSiebView = oSiebView.SiebApplet("MyApplet")
  35.     End Property
  36. End Class

This can be used in a way that makes it very easy for the reader to understand the objects with which the script is working. We will use the same example we used above with the "lstApplication1" SiebList:

  1.     
  2.     Dim oSieb
  3. 'Create an instance of clsSiebObjects
  4. Set oSieb = New clsSiebObjects
  5. 'Performing an event on the SiebList Object
  6. oSieb.SiebApplet.SiebList("lstApplication1").Highlight

Using an Object Dictionary

This technique is based on Article Meir, Implementation of a layer of graphical user interface classes. I would recommend you read the article to better understand this approach. I used a high-level approach to this concept, and to better utilize this process, the article should be read carefully. This technique can be used as follows to simplify a large object hierarchy:

  1. Class clsSiebObjects
  2.     Private m_htContext
  3.     'Loads the Object Dictionary
  4.     Public Function Load
  5.         LoadContext
  6.         Set Load = m_htContext
  7.     End Function
  8.     'Represents the Object Context
  9.     Private Function LoadContext
  10.         m_Context = CreateObject("Scripting.Dictionary")
  11.         'Loading objects in the dictionary.
  12.         With m_Context
  13.             'SiebApplication
  14.             .Add "SiebApplication", SiebApplication("MyApp")
  15.             'SiebScreen (Parent: SiebApplication)
  16.             .Add "SiebScreen", .Item("SiebApplication").SiebScreen("MyScreen")
  17.             'SiebView (Parent: SiebScreen)
  18.             .Add "SiebView", .Item("SiebScreen").SiebView("MySiebView")
  19.             'SiebApplet (Parent: SiebView)
  20.             .Add "SiebApplet", .Item("SiebView").SiebApplet("MySiebApplet")
  21.         End With
  22.     End Function
  23.     'Property Get/Let m_Context
  24.     Private Property Let m_Context(ByVal Val)
  25.         Set m_htContext = Val
  26.     End Property
  27.     Private Property Get m_Context()
  28.         Set m_Context = m_htContext
  29.     End Property
  30. End Class
  31. The snippet below shows usage of the above class to simplify Siebel Hierarchy:
  32. Dim oSieb
  33. 'Instance of the Class
  34. Set oSieb = New clsSiebObjects
  35. Set oSieb = oSieb.Load
  36. oSieb.Item("SiebApplet").SiebPickList("lstApplication1").Select "Open"

Summary

In the examples above, you may notice why only the top 4 objects (Application, Screen, View, Applet) of the hierarchy have been included. This is because, including all the objects will water your libraries and make spotting the right object a cumbersome task. Thus, by including only the top 4 hierarchies, they can simplify our work on a great scale. If the hierarchy changes, they would basically need to alter the elements at one place, only.
For developers who wish to use descriptive programming with Siebel applications, please note that you will have to write descriptions of the objects of the parents only once. When these changes in the descriptions, the update in one place will be the only maintenance required. I am using descriptive programming 100%, with our Siebel application and techniques in this article have really simplified my job much care only for the parent objects.
I hope Automation Developers using Siebel with QTP find this news story useful. Thanks for visiting Relevant Codes.

Continue reading...

What is QTP

Sponsored Ad

Mercury Quick Test Professional offers the best solution in the industry for performance testing and regression testing automation - addressing every major program applications and environment. This next-generation automated solution deploys the concept of evidence-driven testing to radically simplify keyword creation and maintenance check. Distinctive to Quick Test Professional's Keyword-driven approach of verification automation experts have full access to the basic verification and properties of the object, a script integrated debugging environment that is round-trip synchronized with the Keyword View.QuickTest professional meets the needs of technical and nontechnical users. Allows you to deploy higher quality applications faster, cheaper and less risky. It works hand-in-hand with Mercury Business Method Testing™ to bring non-technical subject matter experts in to the quality method in a meaningful way. And, it empowers the entire testing team to generate sophisticated check suites with minimal training.The deployment of Mercury Quick Test Professional is optimized through the use of Mercury best practices. Mercury best practices cover all aspects of deployment, including product installation and operation, organizational design, method implementation, continual method improvement and measurement of return on investment (ROI). Throughout your implementation Mercury applies these best practices to your specific situation, generating world-class procedures for you that drive long-term success source.

Learning basics of QTP automation tool and preparation of QTP:-

This post is in continuation with QTP interview questions series.

What are the features and benefits of Quick Test Pro(QTP)

•    Key word driven testing
•    Suitable for both client server and web based application
•    VB script as the script language
•    Better error handling mechanism
•    Excellent data driven testing features

How to handle the exceptions using recovery scenario manager in QTP

You can instruct QTP to recover unexpected events or errors that occurred in your testing environment during the period of verification. Recovery Scenario Manager provides a wizard that guides you through the recovery scenario definition. Recovery scenario consists of six steps

•    Triggered Events
•    Recovery steps
•    Post Recovery Test-Run

What is the use of Text output value in QTP

The output enable values for the values that talks to the application at runtime. When parameters, the change of values for each iteration. Thus, by generating output values, you can capture the values that the application has for each race and the output to the information desk.

What is the file extension of the code file and object repository file in QTP

File extension of
Per test object rep: filename.mtr
Shared Object rep: filename.tsr
Code file extension id: script.mts

What are the properties you would use for identifying a browser and page when using descriptive programming

“name” would be another property apart from “title” that we can use. OR
We can also use the property “micClass”.
ex: Browser(”micClass:=browser”).page(”micClass:=page”)

What are the different scripting languages you could use when working with QTP

You can write scripts using following languages:
Visual Basic (VB), XML, JavaScript, Java, HTML

Explain the keyword create object with an example.

creates and returns a reference to an Automation object
syntax: CreateObject (servername.typename, [place])
Arguments
ServerName: Required. The name of the application providing the object.
class: Required. The type or class of object to create.
Location: Optional. The name of the network server where the object being created.

Continue reading...