Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Index page for QA Automation and QTP

Below are the useful navigation links for this website and helps user know how to navigate through various topics on this posts are available on this blog

Automation Concepts in QTP

Software Testing Tutorial

Descriptive Programming and Document Object Model in QTP

Working With Objects

Working with Database


Working With Actions 


Working with Automation Object Model

Working with Test Data

QTP Tutorials

Descriptive programming in QTP: Questions Answers

This post discusses on concepts of descriptive programming in QTP through questions and answers. Difference between DP and OR, types of DP, various examples are explained in this article


Question  1: What is descriptive Programming?

Answer: Descriptive programming allows working on an object by describing properties of the object at run time. Descriptive Programming provides flexibility to select properties. For e.g.: Suppose we have Web Object, we can use only html Id if defined for the object and some other properties if html id is not defined such that description of object is unique.

Question 2:  What are different types in which descriptive programming can be implemented?

Answer: Descriptive programming can be implemented using string based description or object based description:
               a.  String based Description
               b.  Using Description Object

Question 3: What is String based Description approach for descriptive programming?

Answer: In String based description, we create a description string similar to the tree structure we get on recording in QTP. So what we do is replace the tree structure with description string:


e.g:  Browser(“Google”).Page(“Google”).WebEdit(“q”).set “nitin” 
In Case of Object Repository(Recording) is expressed in Descriptive Programming as :Browser(“name:=Google”).Page(“name:=Google”).WebEdit(“html id:=qq”,”index:=0”).Set “nitin”

Note: We can have parent object defined using OR and child object using DP, but vice versa is not possible, i.e Parent object description using DP and child object using OR.
Browser(“Google”).Page(“Google”).WebEdit(“html id:=qq”,”index:=0”).Set “nitin” is correct but
Browser(“name:=Google”).Page(“Google”).WebEdit(“html id:=qq”,”index:=0”).Set “nitin” is incorrect

Question 4: How is Descriptive programming implemented using description object?

Answer:  Using description object, we create description object and add properties to the object


e.g: Set objdesc = description.create
objdesc(“name”).value =”google”
Browser(Objdesc).Close
Or
Set objdesc = description.create
objdesc(“name”).value =”search”
Browser("Google").Page("title:=.*").WebButton(objdesc)

Question 5: I want to know number of links in a page, how Can I found the same using description object

Answer: Code to find number of links in a page is:
Set objLink=Description.Create ‘’Create a description object
objLink("html tag").value="A"    ‘’Now the description object will refer to collection of object with tagName as “A”
set olnk=Browser("Google").Page("Google").ChildObjects(objLink) ‘’Collection of all links in page(“Google”)
iCount = olnk.Count ‘’Count of all links in the page.
MsgBox “Count of links in Page are” & iCount
Similar to number of link, we can find number of Editbox (tagname as Input), Image(Img) and so on in a page

Question 6: I want to know, if certain object exist in a page and create a generic function to verify object of various types, How to code for this?

Answer: Function below can be used to create a common function to verify existence of various types of objects in the page:
Call Func_IsExistsObject(“Html id>abcd”,”WebEdit”,)
Public Function Func_IsExistsObject(strobjDescObj,strObjType,)
On error resume next
Func_IsExistsObject = "False"  ‘’ Set the flag as ‘False’ at start of test execution
Set objDesc= Description.create ‘’create  description  object
strobjDesc = split(strobjDescObj,">")
objdesc(strobjDesc(0)).value = strobjDesc(1)
objdesc("index").value = 0
If(ucase(strObjType) = "WEBBUTTON") Then
Func_IsExistsObject = Browser("Google").Page("title:=.*").WebButton(objdesc).Exist
ElseIf(ucase(strObjType) = "IMAGE") Then
Func_IsExistsObject = Browser("Google").Page("title:=.*").Image(objdesc).Exist
ElseIf(ucase(strObjType) = "CHECKBOX") then
Func_IsExistsObject = Browser("Google").Page("title:=.*").WebCheckBox(objdesc).Exist
ElseIf(ucase(strObjType) = "PAGE") then
Func_IsExistsObject = Browser("Google").Page(objdesc).Exist
ElseIf(ucase(strObjType) = "WEBELEMENT") then
Func_IsExistsObject = Browser("Google").Page("title:=.*").WebElement(objdesc).Exist
ElseIf(ucase(strObjType) = "WEBTABLE") then
Func_IsExistsObject = Browser("Google").Page("title:=.*").WebTable(objdesc).Exist
ElseIf(ucase(strObjType) = "WEBLIST") Then
Func_IsExistsObject = Browser("Google").Page("title:=.*").WebList(objdesc).Exist
ElseIf(ucase(strObjType) = "WEBEDIT") Then
Func_IsExistsObject = Browser("Google").Page("title:=.*").WebEdit(objdesc).Exist
ElseIf(ucase(strObjType) = "LINK") then
Func_IsExistsObject = Browser("Google").Page("title:=.*").Link(objdesc).Exist
End If
Exit Function

Question 7: How to close all browsers except QC using descriptive programming?

Answer:  Below lines of code can be used to close all browsers except QC using descriptive programming:
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
Set ColBrowser= Desktop.Childobjects(oBrowser)
For i = 0 to CollBrowser.count -1 step 1
                If Instr(CollBrowser (i).GetROProperty("Name"), "Quality Center") = 0 Then
                                CollBrowser(i).Close
                End If
Next

Question 8: What are the advantage and disadvantage of descriptive Programming compared to Object Repository?

Answer: Using Descriptive Programming helps in Portability and helps to identify object in case of dynamic object or creating objective library of description objects in case application is not developed completely but we know the properties of objects. For further details of comparison of Object Repository , Refer to  below links:


How to work with Actions in QTP - Question in QTP

Question 1: What are Actions in QTP?

Answer: When we create a test in QTP, An action is created by default.  A test comprises call to multiple actions. Action helps divide the test into logical units and can be called multiple times within the test by some other actions. To understand this better, suppose I have an application that calls to login into application, then create a deal, viewing the deal, editing the deal, viewing the deal , and log out from application. So we can divide the test into actions as shown in screenshot below and call the actions from a main action.
 
Example

Question 2: Functions also help divide the test into logical units, so how Actions are different from functions?

Answer: We can understand the difference between an action and function by below comparisons:

1.   As we create a test in QTP, An action is created by default. Inside an action we can write multiple functions or call functions from external vbs libraries.
2.   Action is a QTP Feature whereas Function is a VB Script feature.
3.   Action are integral part of QTP Test, artifacts such as data table, object repository, checkpoint are associated to the action and are specific to the action, whereas we cannot associate these artifacts with a function,  but can be used by function if function is called within the action with which the object repository is associated.
4.   Since Action have data table, and object repository, there take lot more space to functions, and are not useful in case we are using DOM or Descriptive programming for object identification and external test data in the form of excel sheets or database.
5.   There is no limit to the number of functions that can be created or called within an action, but we can create a maximum of 120 actions in QTP 11.
6.   We can return complex values from a function including arrays and object which is not possible in action parameters.
7.   Editing an external function is much easier compared to an external action called by an action at runtime.
8.   We can load both the external test actions and function libraries at run time.For external test action: use statement LoadandRunAction, whereas for loading external libraries use LoadFunctionLibrary.

Question 3: How do we return value from an action?

Answer: We can return value from an action using Input Parameter and output parameters.

Question 4: What are the various types of Actions in QTP?

Answer:  Following are the types of actions in QTP:

Reusable action – A newly created action in QTP is reusable by default. A reusable action can be called by other action within the test or external actions.


Non-reusable action – By default, an action is reusable in QTP, but can be made non-reusable by changing action Properties. A non-reusable action cannot be called from other actions.


External action- This is a reusable action stored in another test. This is explained earlier in this article how to call an external action.


Nested action - An action can call another action. This is known as nesting an action. For e.g : Multiple action called from an action and specific action being executed based on some condition using conditional looping.


Question 5: What is difference between Calls to Copy of Actions and Calls to existing actions?

Answer: Both Call to Copy of Action and calls to existing action are used to call another reusable action.
On inserting a call to copy of an action, the called action is completely copied in the test together with resources including Object Repositories, data, and checkpoint. We can edit the script stored in action and make changes to the resources like Object repositories associated with the action. Changing the action does not have any impact on the original action and change in original action will not modify the copied action.
Inserting a call to existing action allows viewing the steps of the action, but user cannot modify them. The called action’s local object repository is also read-only.

Question 6: Which of the following can be used to transfer data between actions in a QTP test?

a.    Using Global Data Sheet
b.    Using Dictionary Object
c.    Using Action or Test Output Parameters
d.    Using Environment Variable
e.     All of the above
Answer: We can transfer data between actions using any of the above.

Question 7: What is syntax for running an action in QTP?

Answer: An action can be called from another action within the same test using RunAction.

The syntax for RunAction is :  

RunAction ActionName, IterationQuantity, Parameter

Where IterationQuantity and Parameters are optional.

e.g:   RunAction "Action1", oneIteration, Parameter("output"),DataTable("Outparam", dtLocalSheet)

 Similarly, if we need to run action from external test, we can use use 

LoadandRunAction.Syntax : LoadandrunAction(Test Path, ActionName , iterations, Parameters)


Question 8: Which of the following are specific to action and are created/associated at action level?

a.      Object Repository
b.      Local Data table
c.      Checkpoints
d.      Recovery Scenario.

Answer: All except Recovery Scenario are associated at action level, recovery scenario are associated for the test.