RSS Feed

QTP Tutorial in Descriptive programming(Cont……)

Posted on

Hierarchy of test description:

When using programmatic descriptions from a specific point within a test objecthierarchy, you must continue to use programmatic descriptionsfrom that point onward within the same statement. If you specify a test object byits object repository name after other objects in the hierarchy havebeen described using programmatic descriptions, QuickTest cannot identify the object.

For example, you can use Browser(Desc1).Page(Desc1).Link(desc3), since it uses programmatic descriptions throughout the entire test object hierarchy.You can also use Browser(“Index“).Page(Desc1).Link(desc3), since it uses programmatic descriptions from a certain point in the description (starting from the Page object description).

However, you cannot use Browser(Desc1).Page(Desc1).Link(“Example1″), since it uses programmatic descriptions for the Browser and Page objects butthen attempts to use an object repository name for the Link test object(QuickTest tries to locate the Link object based on its name, but cannot locate it in the repository because the parent objects were specified using programmatic descriptions).

Getting Child Object:
We can use description object to get all the objects on the page that matches thatspecific description. Suppose we have to check all the checkboxes present on aweb page. So we will first create an object description for a checkboxe and thenget all the checkboxes from the page
Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”
Dim allCheckboxes, singleCheckBox
Set allCheckboxes = Browse(“Browser”).Page(“Page”).ChildObjects(obj_ChkDesc)
For each singleCheckBox in allCheckboxes
singleCheckBox.Set “ON”
Next
The above code will check all the check boxes present on the page. To get all the child objects we need to specify an object description i.e. we can’t use the string arguments that will be discussed later in the 2nd way of using the programming description.
Possible Operation on Description Object
Consider the below code for all the solutions
Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”
Q: How to get the no. of description defined in a collectionA:obj_ChkDesc.Count ‘Will return 2 in our caseQ: How to remove a description from the collectionA:obj_ChkDesc.remove “html tag” ‘would delete the html tag property fromthe collectionQ: How do I check if property exists or not in the collection?
A: The answer is that it’s not possible. Because whenever we try to access aproperty which is not defined its automatically added to the collection. The onlyway to determine is to check its value that is use a if statement “iobj_ChkDesc(“html tag”).value = empty then”
Q: How to browse through all the properties of a properties collection?
A: Two ways
1st
For each desc in obj_ChkDesc
Name=desc.Name
Value=desc.Value
RE = desc.regularexpression
Next
2nd:
For i=0 to obj_ChkDesc.count – 1
Name= obj_ChkDesc(i).Name
Value= obj_ChkDesc(i).Value
RE = obj_ChkDesc(i).regularexpression
Next
2.By giving the description in form of the string arguments.
You can describe an object directly in a statement by specifying  property:=value pairs describing the object instead of specifying an object’sname. The general syntax is  TestObject(PropertyName1:=PropertyValue1, “...” ,“PropertyNameX:=PropertyValueX”)
TestObject—the test object class could be WebEdit, WebRadioGroup etc….
PropertyName:=PropertyValue—the test object property and its value.
Each property:=value pair should be separated by commas and quotationmarks. Note that you can enter a variable name as the property value if youwant to find an object based on property values you retrieve during a runsession.
Consider the HTML Code given below:
<INPUT type=”textbox” name=”txt_Name”>
<INPUT type=”radio” name=”txt_Name”>
Now to refer to the textbox the statement would be as given below 
Browser(“Browser”).Page(“Page”).WebEdit(“Name:=txt_Name”,”htmltag:=INPUT”).set “Test”
Q: How to browse through all the properties of a properties collection?
A: Two ways
1st
For each desc in obj_ChkDesc
Name=desc.Name
Value=desc.Value
RE = desc.regularexpression
Next
2nd
For i=0 to obj_ChkDesc.count – 1
Name= obj_ChkDesc(i).NameValue= obj_ChkDesc(i).Value
RE = obj_ChkDesc(i).regularexpression
Next
2.By giving the description in form of the string arguments.
You can describe an object directly in a statement by specifying  property:=value pairs describing the object instead of specifying an object’sname. The general syntax is: 
TestObject(PropertyName1:=PropertyValue1, “...” ,“PropertyNameX:=PropertyValueX”)
TestObject—the test object class could be WebEdit, WebRadioGroup etc….
PropertyName:=PropertyValue—the test object property and its value. Each  property:=value
pair should be separated by commas and quotationmarks. Note that you can enter a variable name as the property value if youwant to find an object based on property values you retrieve during a runsession.
 Consider the HTML Code given below:
<INPUT type=”textbox” name=”txt_Name”>
<INPUT type=”radio” name=”txt_Name”>
Now to refer to the textbox the statement would be as given below
Browser(“Browser”).Page(“Page”).WebEdit(“Name:=txt_Name”,”htmltag:=INPUT”).set “Test”
And to refer to the radio button the statement would be as given below
Browser(“Browser”).Page(“Page”).WebRadioGroup(“Name:=txt_Name”,”htmltag:=INPUT”).set “Test”
If we refer to them as a web element then we will have to distinguish between the 2 using the index property
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”htmltag:=INPUT”,”Index:=0”).set “Test” ‘ Refers to the textbox 
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”htmltag:=INPUT”,”Index:=1”).set “Test” ‘ Refers to the radio button
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: