<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Relevant Codes (by Anshoo Arora) &#187; QTP/DP</title>
	<atom:link href="http://relevantcodes.com/category/qtpdp/feed/" rel="self" type="application/rss+xml" />
	<link>http://relevantcodes.com</link>
	<description>A Test Development Resource for HP QuickTest Professional.</description>
	<lastBuildDate>Fri, 30 Dec 2011 07:07:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>QuickTest&#8217;s Custom CheckPoints and Beyond</title>
		<link>http://relevantcodes.com/quicktests-custom-checkpoints-and-beyond/</link>
		<comments>http://relevantcodes.com/quicktests-custom-checkpoints-and-beyond/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 22:39:41 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[.Exist]]></category>
		<category><![CDATA[Custom Checkpoint]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[QTP CheckPoints]]></category>
		<category><![CDATA[QTP Custom CheckPoints]]></category>
		<category><![CDATA[QTP Reporter]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=1647</guid>
		<description><![CDATA[This article will discuss the concepts of Custom Checkpoints, their benefits, when to use them and how they provide us with greater flexibility in script development. Custom CheckPoints offer an easier and highly flexible way of construction your object verifications, which is a core concept of test automation. The concepts below, when coupled together can help you build extremely robust scripts, with enough information that your user desires. ]]></description>
			<content:encoded><![CDATA[<p></p><p>
This article will discuss the concepts of Custom Checkpoints, their benefits, when to use them and how they provide us with greater flexibility in script development. Custom CheckPoints offer an easier and highly flexible way of constructing your object verifications, which is a core concept of test automation. The concepts below, when coupled together can help you build extremely robust scripts, with enough information that your user desires.
</p>
<p>
Before we begin creating CheckPoints as we would for our application(s), let&#8217;s do a quick walk-through of the Reporter Object.
</p>
<p>
<span class="postheading">Reporter Object</span><br />
According to QTP help:
</p>
<blockquote><p>Description: The object used for sending information to the test results. </p></blockquote>
<p>
We use the Reporter object along with its ReportEvent method to send the necessary information to the test results:
</p>
<blockquote><p>ReportEvent: Reports an event to the test results. </p></blockquote>
<p>
Below is the syntax of Reporter.ReportEvent method:
</p>
<blockquote><p>Reporter.ReportEvent EventStatus, ReportStepName, Details [, Reporter]</p></blockquote>
<p>
Possible choices for ReportEvent are:
</p>
<blockquote><p>
0 or micPass:    Causes the status of this step to be passed and sends the specified message to the report.<br />
1 or micFail:    Causes the status of this step to be failed and sends the specified message to the report. When this step runs, the test fails.<br />
2 or micDone:    Sends a message to the report without affecting the pass/fail status of the test.<br />
3 or micWarning: Sends a warning message to the report, but does not cause the test to stop running, and does not affect the pass/fail status of the test.
</p></blockquote>
<p>
Example:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Reporter.ReportEvent micDone, <span style="color: #800000;">&quot;Step 1&quot;</span>, <span style="color: #800000;">&quot;Step Done.&quot;</span></pre></div></div>

<p>
I wanted to cover the Reporter object real quick because its a core-concept in creating custom checkpoints. We&#8217;ll begin creating them now!
</p>
<p>
<span class="postheading">Custom CheckPoints and the Exist Method</span><br />
This is an extremely important concept, and in my opinion, it should serve as the base to all CheckPoints. It checks whether an object <i>exists</i> on the page or not, and before we can start verifying an object&#8217;s properties, it&#8217;s important that we check if it is even available to us to perform our verifications. Also, if the object is found in the applicantion, the Exist method returns true, else, it returns false. Syntax:
</p>
<pre>
Object.Exist(Timeout)
</pre>
<p>
In the syntax above, <i>Timeout</i> is the amount of time you would like QTP to wait for the object before it returns a boolean output. Let&#8217;s see 2 examples of its use.
</p>
<p>
<strong>1.</strong> Case where an object is found:
</p>
<p class="centeralign">
<input type="text" name="txtExistTest" style="width:100px;"/></p>
<p>
To check if the Text box exists, we can formulate the following code that will wait for a max of 5 seconds before the WebEdit appears on the page:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">MsgBox Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)_
        .WebEdit(<span style="color: #800000;">&quot;name:=txtExistTest&quot;</span>).Exist(5)</pre></div></div>

<p>
<strong>2.</strong> Case where an object is not found.</p>
<p>Let&#8217;s use the same example above, and run the same check for the text box below:
</p>
<p class="centeralign">
<input type="text" name="txtNotFound" style="width:100px;" /></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">MsgBox Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)_
        .WebEdit(<span style="color: #800000;">&quot;name:=txtNotFound&quot;</span>).Exist(5) '<span style="color: #0000A6;">False</span></pre></div></div>

<p>
You may spy on the WebEdit above (just to make sure), and notice that there is actually a textbox with the description we provided. But, still, QuickTest returns a failed status. That is because, for this example, I created 2 such text boxes with the exact same description, so if you just provide the property without an <a href="http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/">Ordinal Identifier</a>, your code will not work. However still, I feel the above is quite a good example of a scenario that can very well happen in many applications and its a good test of an automation engineer to be cautious from the start.
</p>
<p>
However, we still haven&#8217;t created a CheckPoint yet. A CheckPoint is a conditional method that information the user of an objects&#8217; status during testing. Thus, we must create a conditional method here:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">If</span> Browser(<span style="color: #800000;">&quot;title:=.*Relevant.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=txtNotFound&quot;</span>).Exist(5)
	Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;WebEdit CheckPoint&quot;</span>, <span style="color: #800000;">&quot;WebEdit was found. Step Passed.&quot;</span>
<span style="color: #0000A6;">Else</span>
	Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;WebEdit CheckPoint&quot;</span>, <span style="color: #800000;">&quot;WebEdit was not found. Step failed.&quot;</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span></pre></div></div>

<p>
There you go! You have just created a custom CheckPoint. If you would like to know more about the Reporter object, please use the QTP help, which is an excellent source of information.
</p>
<p>
<span class="postheading">Custom CheckPoints and the GetROProperty Method</span><br />
GetROProperty is short for Get-Runtime-Object-Property. In other words, this method can be used to retrieve the value that the object has, at present. Please note that, in some dynamic applications, runtime object properties can change on various factors. Also, with Descriptive Programming (DP), regardless of what property you retrieve, it will always be a runtime property. Obviously, and I bet you know this, but just to reiterate, all these properties can be viewed from the Object Spy. You can find more information on it in my article <a href="http://relevantcodes.com/descriptive-programming-concepts-1/">Descriptive Programming 1</a>. Below is a snapshot of the TO Properties Tab in Object Spy:
</p>
<div class="wp-caption aligncenter" style="width: 379px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/TOPropertiesTab.PNG"><img alt="QTP Object Spy TO Properties" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/TOPropertiesTab.PNG" title="QTP Object Spy TO Properties" width="379" height="779" /></a>
	<p class="wp-caption-text">QTP Object Spy TO Properties</p>
</div>
<p>
You will notice that even though I mentioned RO (RunTime Object) properties, I am looking at the TO (Test Object) tab. This is because, when we use the Object Spy to retrieve an objects&#8217; properties, we are doing it on a runtime object, thus, what we see in the image above are all RunTime object properties with their image in the TO Object properties tab. We will use the GetROProperty method with TO properties.
</p>
<p>
Also, when writing custom checkpoints, we will (almost) always use RO properties instead of TO properties. That is because, we would like to know what the object contains <i>at present, or at runtime</i> as opposed to what the object contained during record time. However, if you are using Descriptive Programming, regardless of what property you retrieve from your application, it will be a runtime property.
</p>
<p>
The textbox below should have a value of 10, for the maxLength property. We will create a checkPoint to test that assumption.
</p>
<p class="centeralign">
<input type="text" maxlength="9" name="txtMaxLen" style="width:100px;" /></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">If</span> Browser(<span style="color: #800000;">&quot;title:=.*Relevant.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=txtMaxLen&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;max length&quot;</span>)=10 <span style="color: #0000A6;">Then</span>
	Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;WebEdit MaxLength Text&quot;</span>, <span style="color: #800000;">&quot;Test Passed.&quot;</span>
<span style="color: #0000A6;">Else</span>
	Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;WebEdit MaxLength Text&quot;</span>, <span style="color: #800000;">&quot;Test Failed.&quot;</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span></pre></div></div>

<p>
Result:
</p>
<div class="wp-caption aligncenter" style="width: 259px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/TextboxCheck_Details.PNG"><img alt="QTP Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/TextboxCheck_Details.PNG" title="QTP Results" width="259" height="101" /></a>
	<p class="wp-caption-text">QTP Results</p>
</div><br />
<div class="wp-caption aligncenter" style="width: 493px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/TextboxCheck_Summary.PNG"><img alt="QTP Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/TextboxCheck_Summary.PNG" title="QTP Results" width="493" height="92" /></a>
	<p class="wp-caption-text">QTP Results</p>
</div>
<p>
When you open your Test Results after the above statement executes, you will notice that, the test failed. It will always fail because the maxLength for our WebEdit is not 10, but 9. When you you use Object spy to retrieve the <i>max length</i> property, you will notice that it is indeed not 10, but its 9. However, in the real-world, we may not always know the properties these objects will have at runtime, and most of the times you will come to find of errors after your regression suites complete their execution.
</p>
<p>
Let&#8217;s create another CheckPoint, and verify if the Link has the correct color:
</p>
<p class="centeralign"><a href="http://relevantcodes.com">Relevant Codes: Test Color</a></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).Link(<span style="color: #800000;">&quot;text:=Relevant Codes: Test Color&quot;</span>)
	<span style="color: #0000A6;">If</span> .Exist(5) <span style="color: #0000A6;">Then</span>
		<span style="color: #0000A6;">If</span> .GetROProperty(<span style="color: #800000;">&quot;color&quot;</span>) = <span style="color: #800000;">&quot;#0000ff&quot;</span> <span style="color: #0000A6;">Then</span>
			Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;RelevantCodes Link&quot;</span>, <span style="color: #800000;">&quot;Correct color.&quot;</span>
		<span style="color: #0000A6;">Else</span>
			Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;RelevantCodes Link&quot;</span>, <span style="color: #800000;">&quot;Incorrect color.&quot;</span>
		<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
	<span style="color: #0000A6;">Else</span>
		Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;RelevantCodes Link&quot;</span>, <span style="color: #800000;">&quot;Link was not found.&quot;</span>
	<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<p>
Result:
</p>
<div class="wp-caption aligncenter" style="width: 628px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/LinkCheck_Details.PNG"><img alt="QTP Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/LinkCheck_Details.PNG" title="QTP Results" width="628" height="91" /></a>
	<p class="wp-caption-text">QTP Results</p>
</div><br />
<div class="wp-caption aligncenter" style="width: 461px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/LinkCheck_Summary.PNG"><img alt="QTP Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/LinkCheck_Summary.PNG" title="QTP Results" width="461" height="102" /></a>
	<p class="wp-caption-text">QTP Results</p>
</div>
<p>
<span class="postheading">CheckPoints for Multiple Objects</span><br />
There are circumstances where you need to create CheckPoints for multiple objects at once. For instance, if you are creating a Login Function, you may need to create a CheckPoint for the UserName Textbox, Password Textbox and the Submit button. This section of the article details how CheckPoints can be created for multiple objects.
</p>
<p class="alert">
<a href="http://relevantcodes.com/qtp-verify-multiple-object-properties-an-elegant-approach/">This article</a> shows a way to verify multiple Object Properties through a single Class at once, and reports all Checks in a tabular form to QuickTest Results.
</p>
<p>
Below, you will see a scenario that I just mentioned above. These objects won&#8217;t do anything, but, they show a way you can create CheckPoints to be run for multiple objects together.
</p>
<p class="centeralign">
<input type="text" maxlength="9" name="txtUser" value="UserName" style="width:100px;" />
<input type="text" maxlength="9" name="txtPassword" value="Password" style="width:100px;" />
<input type="button" name="btnSubmit" value="Submit" style="width:100px;" /></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)
    <span style="color: #0000A6;">If</span> .WebEdit(<span style="color: #800000;">&quot;name:=txtUser&quot;</span>).Exist(1) <span style="color: #0000A6;">And</span> .WebEdit(<span style="color: #800000;">&quot;name:=txtPassword&quot;</span>).Exist(1) <span style="color: #0000A6;">Then</span>
        Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;UserName/Password&quot;</span>, <span style="color: #800000;">&quot;Objects found.&quot;</span>
    <span style="color: #0000A6;">Else</span>
        Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;UserName/Password&quot;</span>, <span style="color: #800000;">&quot;Objects not found.&quot;</span>
    <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<div class="wp-caption aligncenter" style="width: 237px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/MultipleChecks_Summary.PNG"><img alt="Multiple Checks - Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/MultipleChecks_Summary.PNG" title="Multiple Checks - Results" width="237" height="125" /></a>
	<p class="wp-caption-text">Multiple Checks - Results</p>
</div><br />
<div class="wp-caption aligncenter" style="width: 606px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/MultipleChecks_Details.PNG"><img alt="Multiple Checks - Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/MultipleCheck_Details.PNG" title="Multiple Checks - Results" width="606" height="90" /></a>
	<p class="wp-caption-text">Multiple Checks - Results</p>
</div>
<p>
Similarly, if we want to verify objects&#8217; properties instead of checking whether they exist, we can do this:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)
    <span style="color: #0000A6;">If</span> .WebEdit(<span style="color: #800000;">&quot;name:=txtUser&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;max length&quot;</span>) = 9 <span style="color: #0000A6;">And</span> _
     .WebEdit(<span style="color: #800000;">&quot;name:=txtPassword&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;max length&quot;</span>) = 9 <span style="color: #0000A6;">Then</span>
        Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;UserName/Password&quot;</span>, <span style="color: #800000;">&quot;Correct MaxLength&quot;</span>
    <span style="color: #0000A6;">Else</span>
        Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;UserName/Password&quot;</span>, <span style="color: #800000;">&quot;Incorrect MaxLength&quot;</span>
    <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<div class="wp-caption aligncenter" style="width: 230px">
	<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/MultipleChecks_MaxLength_Summary.PNG"><img alt="QTP Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/MultipleChecks_MaxLength_Summary.PNG" title="QTP Results" width="230" height="94" /></a>
	<p class="wp-caption-text">QTP Results</p>
</div><br />
<div class="wp-caption aligncenter" style="width: 575px">
	<img alt="QTP Results" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/MultipleChecks_MaxLength_Details.PNG" title="QTP Results" width="575" height="88" />
	<p class="wp-caption-text">QTP Results</p>
</div>
<p>
<span class="postheading">CheckPoints for Hidden Objects</span><br />
Let&#8217;s create another CheckPoint. This time, things will get a little complex. Below you will see a Textbox, but indeed there are 2. One of them is hidden. Is there a way to know that one of these Text boxes is hidden? The answer is: Yes.
</p>
<p class="centeralign">
<input type="text" name="txtIsVisible" style="width:100px;" /></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>)
<span style="color: #008000;">'If the first text box, that is, the text box with index 0 is hidden then.. set value in Text Box #2
</span>    <span style="color: #0000A6;">If</span> .WebEdit(<span style="color: #800000;">&quot;name:=txtIsVisible&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;visible&quot;</span>) = <span style="color: #0000A6;">False</span> <span style="color: #0000A6;">Then</span>
        Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=txtIsVisible&quot;</span>, <span style="color: #800000;">&quot;index:=1&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;2nd&quot;</span>
    <span style="color: #0000A6;">Else</span>
        <span style="color: #008000;">'Else, set value in Text Box #1
</span>        Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=txtIsVisible&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;1st&quot;</span>
    <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<p>
In practice, many people make the mistake of omitting an ordinal identifier in such cases. When you run the same code without an ordinal identifier:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Error
</span>MsgBox Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=txtIsVisible&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;visible&quot;</span>)</pre></div></div>

<p>
<a href="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/RunError.PNG"><img alt="" src="http://relevantcodes.com/Articles/CustomCheckPointsAndBeyond/RunError.PNG" title="Run Error" class="aligncenter" width="585" height="178" /></a>
</p>
<p>
You can generally run the following bit of code to find out which object is hidden:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc(<span style="color: #800000;">&quot;name&quot;</span>).value = <span style="color: #800000;">&quot;txtIsVisible&quot;</span>
&nbsp;
<span style="color: #0000A6;">Set</span> colObject = Browser(<span style="color: #800000;">&quot;title:=.*Relevant Codes.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).ChildObjects(oDesc)
&nbsp;
<span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> colObject.Count - 1
	<span style="color: #0000A6;">Print</span> <span style="color: #800000;">&quot;Object &quot;</span> &amp; x &amp; <span style="color: #800000;">&quot;: &quot;</span> &amp; colObject(x).GetROProperty(<span style="color: #800000;">&quot;visible&quot;</span>)
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
In your print log, you will have the following information:
</p>
<pre>
'Object with Index = 0 is Hidden
Object 0: False

'Object with Index = 1 is not Hidden
Object 1: True
</pre>
<p>
There are more ways to hide objects, and there are several techniques that can be used to spot them. However, I will let my readers explore those scenarios and find the many possibilities available to them.
</p>
<p>
I hope this article clarifies some doubts, and gives you more confidence using them in your everyday development.
</p>
<p>
<span class="postheading">References</span><br />
1. QuickTest Professional Help<br />
<input type="text" name="txtIsVisible" id="txtIsVisible" style="visibility:hidden;" />
<input type="text" name="txtNotFound" id="txtNotFound" style="visibility:hidden;" /><br/>
</p>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
<p> .</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/quicktests-custom-checkpoints-and-beyond/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
		<item>
		<title>QTP: Creating Object Descriptions &#8220;On The Fly&#8221;</title>
		<link>http://relevantcodes.com/qtp-creating-object-descriptions-on-the-fly/</link>
		<comments>http://relevantcodes.com/qtp-creating-object-descriptions-on-the-fly/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 14:00:41 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[Descriptive Programming]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[RunTime Descriptions]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=1345</guid>
		<description><![CDATA[This article outlines how and when descriptions can be created at run-time to minimize code, and ease maintenance. Examples and Demos included.]]></description>
			<content:encoded><![CDATA[<p></p><div class="photo_right"><a href="http://www.flickr.com/photos/16230215@N08/3942293740/" title="On The Fly" ><img src="http://farm3.static.flickr.com/2513/3942293740_e86e5f5463_m.jpg" alt="On The Fly"  /></a><br /><small><a href="http://creativecommons.org/licenses/by-nd/2.0/" title="Attribution-NoDerivs License" ><img src="http://relevantcodes.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" width="16" height="16"  /></a> <a href="http://www.photodropper.com/photos/" >photo</a> credit: <a href="http://www.flickr.com/photos/16230215@N08/3942293740/" title="h.koppdelaney" >h.koppdelaney</a></small></div>
<p>
This article is a follow-up to the <a href="http://relevantcodes.com/category/qtpdp/">Descriptive Programming Series</a> and will discuss a simple way of creating Object Descriptions on the fly. There are several reasons for using this approach, such as overcoming the need to write extra code and having the ability to make the change in only a single place while performing maintenance. This article includes the concepts and working examples of how and <i>when</i> we can must use this approach.
</p>
<p>
There are instances where object descriptions are incremented in a numerical context. In other words, a part of the object description stays the same, but these descriptions increment starting at a number, generally 0.
</p>
<p>
To illustrate, consider the below HTML_IDs for 4 list boxes in a Web Application:
</p>
<pre>
List Box 1 HTML ID -> lstBox0
List Box 1 HTML ID -> lstBox1
List Box 1 HTML ID -> lstBox2
List Box 1 HTML ID -> lstBox3
</pre>
<p>
Notice how the descriptions above increment. <i>lstBox</i> is common in all 4 descriptions, but there is a numerical increment after each, starting at 0. When creating an object description in such a scenario, you may tend to do the following:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstBox0&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstBox1&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstBox2&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstBox3&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span></pre></div></div>

<p>
The above is a common usage, and completely acceptable. But in practice, we may have more than 4 Objects with such descriptions and creating the same line of code over and over again, and maintaining everything can be quite a task. In such situations, the concept in this article can be quite beneficial. For example, the above code snippet can be condensed into:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'use a variable to increment from 0 to 3
</span><span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> 3
	Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstBox&quot;</span> &amp; x).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
Now, if the HTML_ID of this object changes, we have to make the change only once as opposed to several times. For example, if the HTML_ID of the list box above was to change from <i>lstBox</i> to <i>lstObject</i>, we would simply update our code like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">For</span> x = 1 <span style="color: #0000A6;">to</span> 4
	<span style="color: #008000;">'lstBox becomes lstObject
</span>	Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstObject&quot;</span> &amp; x).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
Instead of updating it 4 times:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstObject0&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstObject1&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstObject2&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span>
Browser(<span style="color: #800000;">&quot;SomeBrowser&quot;</span>).Page(<span style="color: #800000;">&quot;SomePage&quot;</span>).WebList(<span style="color: #800000;">&quot;html id:=lstObject3&quot;</span>).<span style="color: #0000A6;">Select</span> <span style="color: #800000;">&quot;Item&quot;</span></pre></div></div>

<p>
<span class="postheading">Numeric Increments</span><br />
Let&#8217;s see a working example. Please open a new IE browser and navigate to the following <a href="http://relevantcodes.com/Articles/DP_At_Runtime/SimilarObjects1.htm">Page: Demo 1</a>. You can simply set values in all of the text boxes using the following snippet:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;name:=SimpleDemo1.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)
	<span style="color: #0000A6;">For</span> x = 1 <span style="color: #0000A6;">to</span> 6
		.WebEdit(<span style="color: #800000;">&quot;html id:=txtDemo&quot;</span> &amp; x ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Text Box &quot;</span> &amp; x
	<span style="color: #0000A6;">Next</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<p>
<span class="postheading">Alphabetic Increments</span><br />
Now imagine a similar situation where numeric increments are replaced with alphabets. There are several ways of working with such scenarios, but what I generally do is create an array with all the alphabets and increment elements of that array to work with runtime objects:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> arrAlphabets: <span style="color: #0000A6;">ReDim</span> arrAlphabets(25)
&nbsp;
arrAlphabets = Array(<span style="color: #800000;">&quot;a&quot;</span>, <span style="color: #800000;">&quot;b&quot;</span>, <span style="color: #800000;">&quot;c&quot;</span>, <span style="color: #800000;">&quot;d&quot;</span>, <span style="color: #800000;">&quot;e&quot;</span>, <span style="color: #800000;">&quot;f&quot;</span>, <span style="color: #800000;">&quot;g&quot;</span>, <span style="color: #800000;">&quot;h&quot;</span>, _
		<span style="color: #800000;">&quot;i&quot;</span>, <span style="color: #800000;">&quot;j&quot;</span>, <span style="color: #800000;">&quot;k&quot;</span>, <span style="color: #800000;">&quot;l&quot;</span>, <span style="color: #800000;">&quot;m&quot;</span>, <span style="color: #800000;">&quot;n&quot;</span>, <span style="color: #800000;">&quot;o&quot;</span>, <span style="color: #800000;">&quot;p&quot;</span>, <span style="color: #800000;">&quot;q&quot;</span>, <span style="color: #800000;">&quot;r&quot;</span>, _
		<span style="color: #800000;">&quot;s&quot;</span>, <span style="color: #800000;">&quot;t&quot;</span>, <span style="color: #800000;">&quot;u&quot;</span>, <span style="color: #800000;">&quot;v&quot;</span>, <span style="color: #800000;">&quot;w&quot;</span>, <span style="color: #800000;">&quot;x&quot;</span>, <span style="color: #800000;">&quot;y&quot;</span>, <span style="color: #800000;">&quot;z&quot;</span>)</pre></div></div>

<p>
Now, we can use the array of alphabets using the exact same approach we used for numeric descriptions on <a href="http://relevantcodes.com/Articles/DP_At_Runtime/SimilarObjects3.htm">Demo Page 2</a>.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;name:=SimpleDemo2.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)
    <span style="color: #0000A6;">For</span> x = 1 <span style="color: #0000A6;">to</span> 6
        .WebEdit(<span style="color: #800000;">&quot;html id:=txtDemo_&quot;</span> &amp; arrAlphabets(x-1)).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Text Box &quot;</span> &amp; UCase(arrAlphabets(x-1))
    <span style="color: #0000A6;">Next</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<p class="alert">
If you are starting off with Descriptive Programming and VBScript Arrays, and would like to learn how the above approach works, please ask your questions in the comments section and I will try my best to help you.
</p>
<p>
<span class="postheading">Complex Increments</span><br />
The above 2 uses of this technique are quite basic, and chances are that in your environment, you may not see such simple instances. Let&#8217;s create another scenario then, with a little complex description. Please open a new browser, and navigate to <a href="http://relevantcodes.com/Articles/DP_At_Runtime/SimilarObjects3.htm">Demo Page 3</a>.
</p>
<p>
When you spy on the WebEdits on this page, you will see a long description for the &#8216;name&#8217; property. The <i>name</i> property of the six WebEdits are:
</p>
<pre>
txt_applicant[0]BuyProductBox_answerString_A
txt_applicant[1]BuyProductItem_answerString_B
txt_applicant[2]BuyProductBall_answerString_C
txt_applicant[3]BuyProductBat_answerString_D
txt_applicant[4]BuyProductSpoon_answerString_E
txt_applicant[5]BuyProductFork_answerString_F
</pre>
<p>
How can the description for this object be created such that, we can get our work done through a single line of code, instead of creating 6 different statements to set a value in each text box? Notice the descriptions closely, not only are the applicant numbers incrementing in numerical and alphabetical context, but the product lines are changing as well (Box, Item, Ball etc).
</p>
<p class="alert">
The trick here is to use RegularExpressions/WildCards to make the description generic so it becomes available to all 6 WebEdits. There are several ways this generic description can be created, and if you solved this using a different description, please feel free to share it.
</p>
<p>
Below is one possible solution for our complex scenario:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> arrAlphabets: <span style="color: #0000A6;">ReDim</span> arrAlphabets(25)
<span style="color: #0000A6;">Dim</span> sName
&nbsp;
arrAlphabets = Array(<span style="color: #800000;">&quot;a&quot;</span>, <span style="color: #800000;">&quot;b&quot;</span>, <span style="color: #800000;">&quot;c&quot;</span>, <span style="color: #800000;">&quot;d&quot;</span>, <span style="color: #800000;">&quot;e&quot;</span>, <span style="color: #800000;">&quot;f&quot;</span>, <span style="color: #800000;">&quot;g&quot;</span>, <span style="color: #800000;">&quot;h&quot;</span>, _
		<span style="color: #800000;">&quot;i&quot;</span>, <span style="color: #800000;">&quot;j&quot;</span>, <span style="color: #800000;">&quot;k&quot;</span>, <span style="color: #800000;">&quot;l&quot;</span>, <span style="color: #800000;">&quot;m&quot;</span>, <span style="color: #800000;">&quot;n&quot;</span>, <span style="color: #800000;">&quot;o&quot;</span>, <span style="color: #800000;">&quot;p&quot;</span>, <span style="color: #800000;">&quot;q&quot;</span>, <span style="color: #800000;">&quot;r&quot;</span>, _
		<span style="color: #800000;">&quot;s&quot;</span>, <span style="color: #800000;">&quot;t&quot;</span>, <span style="color: #800000;">&quot;u&quot;</span>, <span style="color: #800000;">&quot;v&quot;</span>, <span style="color: #800000;">&quot;w&quot;</span>, <span style="color: #800000;">&quot;x&quot;</span>, <span style="color: #800000;">&quot;y&quot;</span>, <span style="color: #800000;">&quot;z&quot;</span>)
&nbsp;
<span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;name:=SimpleDemo3.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)
    <span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> 5
        sName = <span style="color: #800000;">&quot;txt_applicant\[&quot;</span> &amp; x &amp; <span style="color: #800000;">&quot;\].*_&quot;</span> &amp; arrAlphabets(x)
        .WebEdit(<span style="color: #800000;">&quot;name:=&quot;</span> &amp; sName).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Text Box &quot;</span> &amp; UCase(arrAlphabets(x))
    <span style="color: #0000A6;">Next</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<p>
<span class="postheading">Summary</span><br />
This article summarized how working with objects with similar descriptions can be achieved in a simple manner. This approach may not be feasible for all environments, and should only be used when possible. You&#8217;re most likely to see Approach#3 in this article used most often, and at times, it does get a little tricky to write descriptions to work with all objects having similar properties.
</p>
<p>
This article is the last in the Introductory DP series, and future articles will cover advanced concepts and techniques of working with real-life applications.
</p>
<p>
I hope you guys find this article useful. Thanks for reading :)
</p>
<p class="alert">If you have any questions, please ask them in the comments section. If your information is to be treated as confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-creating-object-descriptions-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>QTP: Understanding the Description Object (Description.Create)</title>
		<link>http://relevantcodes.com/qtp-all-about-the-description-object-description-create/</link>
		<comments>http://relevantcodes.com/qtp-all-about-the-description-object-description-create/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 16:53:40 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[ChildObjects]]></category>
		<category><![CDATA[Description Object]]></category>
		<category><![CDATA[Description.Create]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[QTP Description Object]]></category>
		<category><![CDATA[QTP Description.Create]]></category>
		<category><![CDATA[Set oDesc]]></category>
		<category><![CDATA[Set oDesc = Description.Create]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=865</guid>
		<description><![CDATA[This article covers the principles of creating a Description Object in QTP and its amazing use with the ChildObjects method. We will see how we can create an object description with a single property, with multiple properties, by using regular expressions and finally putting all these concepts into their application with the ChildObjects method.]]></description>
			<content:encoded><![CDATA[<p></p><div class="photo_right"><a title="Learning Zone" href="http://www.flickr.com/photos/45936582@N00/3892026127/"><img src="http://farm3.static.flickr.com/2464/3892026127_4b3e2e08dd_m.jpg" alt="Learning Zone" /></a><br />
<small><a title="Attribution License" href="http://creativecommons.org/licenses/by/2.0/"><img src="http://relevantcodes.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" width="16" height="16" /></a> <a href="http://www.photodropper.com/photos/">photo</a> credit: <a title="SideLong" href="http://www.flickr.com/photos/45936582@N00/3892026127/">SideLong</a></small></div>
<p>
<span class="postheading">Introduction</span><br />
In this article, we will cover the basics of Description Object and the ChildObjects method. This is a very powerful approach to creating robust automation test suites. It is also a very important principle of Descriptive Programming in QTP.
</p>
<p>
We will see how we can create an object description with a single property, with multiple properties, by using regular expressions and finally putting all these concepts into their application with the ChildObjects method.
</p>
<p>
Before we see how it is done, we must first understand the following statement:
</p>
<pre>Set oDesc = Description.Create</pre>
<p>
Above, we are using the variable <em>oDesc</em> to create a description of something. Since, <em>oDesc</em> is preceeded by a <em>Set</em> statement, it must be an object reference. Therefore, when the above statement executes, <em>oDesc</em> will become an object reference to a description object. We will use the description object with the ChildObjects method to retrieve object collections. These object collections are nothing but arrays of objects with the exact properties of the description object.
</p>
<p class="alert">If you are starting with DP, please read the article on <a href="http://relevantcodes.com/descriptive-programming-concepts-1/">Descriptive Programming Concepts</a> on Relevant Codes for a quick walk-through on Descriptive Programming before continuing with this article.
</p>
<p>
<span class="postheading">I. Creating a Description Object for a Parent (Browser/Window)</span><br />
To create an object description for a parent, we will simply use the &#8220;Class&#8221; of the parent object and add the property-value combination:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
<span style="color: #008000;">'Remember to always use 'micclass' and not 'class name'
</span>oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Browser&quot;</span>
&nbsp;
<span style="color: #008000;">'We used Desktop as the parent here because, the Desktop Object holds all the Windows
</span><span style="color: #0000A6;">Set</span> colObject = Desktop.ChildObjects( oDesc )</pre></div></div>

<p>
When the above snippet execute, <em>colObject</em> will contain a collection of all browsers visible on the desktop.
</p>
<p>
But, since we have done this, how will we know how many browser objects exist on the desktop through code? Also, how will we retrieve their information? The answer is quite simple: <em>colObject</em> contains the necessary information and methods we can use to perform events on our target objects.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Retrieve # of open browsers
</span>MsgBox colObject.Count
&nbsp;
<span style="color: #008000;">'Retrieve Titles of all open browsers
</span><span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> colObject.Count - 1
	MsgBox colObject(x).GetROProperty(<span style="color: #800000;">&quot;title&quot;</span>)
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
As I mentioned above, <em>colObject</em> is nothing but an array of all objects having the exact same properties as the description object. Therefore, <em>colObject(0)</em> points to the first object in the collection, <em>colObject(1)</em> points to the second object in the collection, and so on. This is demonstrated in the <em>For..Next</em> loop in the snippet above.
</p>
<p>
<span class="postheading">II. Creating a Description Object for an Object contained in a Browser/Window</span><br />
Using the same approach above, we will retrieve collection of all <em>Link</em> objects on a page. Notice here that instead of <em>Desktop</em>, we have used the entire Browser-Page hierarchy. This is because, a <em>link</em> object is present somewhere inside the Page, instead of the desktop :).
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Link&quot;</span>
&nbsp;
<span style="color: #008000;">'Using the entire Browser-Page hierarchy
</span><span style="color: #0000A6;">Set</span> colObject = Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).ChildObjects( oDesc )</pre></div></div>

<p>
By executing the snippet above, we will use <em>colObject</em> to perform some events on these objects. Let&#8217;s retrieve the number of link objects present in our browser:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Returns 30
</span>MsgBox colObject.Count</pre></div></div>

<p>
The above example is created for the <em>Google</em> page, and if you want to test it for some other browser, do not forget to change the Browser and Page titles to the correct values.
</p>
<p>
<span class="postheading">III. Creating a Description Object for an Object contained in a Browser/Window Using Multiple Properties</span><br />
If you saw the above example, we created a description object using only the <em>class</em> of the <em>Link</em> object. Now, we will retrieve a more specific object collection. We are going to specify an additional property and narrow down the search results- this is because, even though there can be multiple <em>Link</em> objects on a page, its not necessary that there would be the same number of objects with the text &#8220;Hello, I am a Link!&#8221;.
</p>
<p>
This approach helps us retrieve only the objects that we really want for our automation, since having a collection of all objects can be quite cumbersome to work with. Also, if we provide relevant information to our Description Object, QTP will return a narrowed-down collection, which is the easiest to work with. This is similar to how you search Google. If you specify &#8220;QTP&#8221; in Google Search, you will have a huge array of search results. You can narrow down the search results (and find information faster) if you add &#8220;QTP + Browser + DP&#8221; instead.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Link&quot;</span>
<span style="color: #008000;">'Additional property- for more focused and controlled collection
</span>oDesc( <span style="color: #800000;">&quot;text&quot;</span> ).value = <span style="color: #800000;">&quot;Images&quot;</span>
&nbsp;
<span style="color: #0000A6;">Set</span> colObject = Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).ChildObjects( oDesc )
&nbsp;
Msgbox colObject.Count    'Returns 1</pre></div></div>

<p>
Now, <em>colObject</em> will only contain the Link objects that have the text: <em>Images</em>. Also, if you notice Google page, there is only one link with the <em>Images</em> text. This is a good example of finding the target object dynamically. Suppose, if there were 2 links on the page instead, we would have both of them in our collection <em>colObject</em>. Let&#8217;s highlight our found object:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">colObject(0).Highlight</pre></div></div>

<p>
Executing the statement above, we will highlight the first object in the collection. I know there is only one object in the collection, but we can make sure by doing this:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> colObject.Count - 1
	colObject(x).Highlight
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
<span class="postheading">IV. Creating a Description Object using WildCards</span><br />
If we have dynamic objects in our application, then we may not always have the luxury to feed their properties as we have done in the example above. Sometimes, we would need to create dynamic descriptions and retrieve our target objects from resulting (dynamic) collections. I say dynamic collections because at one time, your collection may hold 9 objects, whereas during the next session, it may hold 10.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Link&quot;</span>
oDesc( <span style="color: #800000;">&quot;text&quot;</span> ).value = <span style="color: #800000;">&quot;I.*age.*&quot;</span>  <span style="color: #008000;">'Images
</span><span style="color: #008000;">'.regularExpression is 'True' by default
</span>oDesc( <span style="color: #800000;">&quot;text&quot;</span> ).regularExpression = <span style="color: #0000A6;">True</span>
&nbsp;
<span style="color: #0000A6;">Set</span> colObject = Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).ChildObjects( oDesc )</pre></div></div>

<p class="alert">You may want to read the article on <a href="http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/">Regular Expressions</a> to better understand how these work in Descriptive Programming.</p>
<p>
After executing the snippet above, we will have a collection object with all object that match the regular expression. Let&#8217;s see the count of the objects:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Returns 1 because our supplied pattern only matches with the word: Images
</span>MsgBox colObject.Count</pre></div></div>

<p>
Let&#8217;s replace the &#8220;text&#8221; with &#8220;ma&#8221; instead and see if we still retrieve a collection with a single object:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Link&quot;</span>
oDesc( <span style="color: #800000;">&quot;text&quot;</span> ).value = <span style="color: #800000;">&quot;.*ma.*&quot;</span>  <span style="color: #008000;">'Images
</span><span style="color: #008000;">'.regularExpression is 'True' by default
</span>oDesc( <span style="color: #800000;">&quot;text&quot;</span> ).regularExpression = <span style="color: #0000A6;">True</span>
&nbsp;
<span style="color: #0000A6;">Set</span> colObject = Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).ChildObjects( oDesc )</pre></div></div>

<p>
To see what has changed, let&#8217;s execute the following:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Will return 4
</span>MsgBox colObject.Count</pre></div></div>

<p>
If you do execute the snippet above, the count would be 4. Why is that? To see the new objects in our collection, let&#8217;s do this:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> colObject.Count - 1
	MsgBox <span style="color: #800000;">&quot;x:&quot;</span> &amp; x &amp; <span style="color: #800000;">&quot; || &quot;</span> &amp; colObject(x).GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
Below are our outputs:
</p>
<table border="0">
<tbody>
<tr>
<td><a href="http://relevantcodes.com/Articles/DescriptionObject/X0.JPG"><img class="alignnone" title="X=0" src="http://relevantcodes.com/Articles/DescriptionObject/X0.JPG" alt="" width="104" height="100" /></a></td>
<td><a href="http://relevantcodes.com/Articles/DescriptionObject/X1.JPG"><img class="alignnone" title="X=1" src="http://relevantcodes.com/Articles/DescriptionObject/X1.JPG" alt="" width="104" height="100" /></a></td>
<td><a href="http://relevantcodes.com/Articles/DescriptionObject/X2.JPG"><img class="alignnone" title="X=2" src="http://relevantcodes.com/Articles/DescriptionObject/X2.JPG" alt="" width="104" height="100" /></a></td>
<td><a href="http://relevantcodes.com/Articles/DescriptionObject/X3.JPG"><img class="alignnone" title="X=3" src="http://relevantcodes.com/Articles/DescriptionObject/X3.JPG" alt="" width="189" height="100" /></a></td>
</tr>
</tbody>
</table>
<p>
Interesting, isn&#8217;t it? Our description for the <em>text</em> property matched all links that had the letters <em>ma</em> in them.
</p>
<p>
<span class="postheading">V. Negating WildCards</span><br />
Sometimes we have an object description with <em>wildcards</em> in it. Here, we want to turn off the Description Object&#8217;s ability to register the description as a regular expression. This is quite simple, and we do it by turning regular expression as False:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Link&quot;</span>
oDesc( <span style="color: #800000;">&quot;text&quot;</span> ).value = <span style="color: #800000;">&quot;.*ma.*&quot;</span>  <span style="color: #008000;">'Images
</span>oDesc( <span style="color: #800000;">&quot;text&quot;</span> ).regularExpression = <span style="color: #0000A6;">False</span>
&nbsp;
<span style="color: #0000A6;">Set</span> colObject = Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).ChildObjects( oDesc )
&nbsp;
MsgBox colObject.Count    'Returns 0</pre></div></div>

<p>
Now, the above snippet will <em>not</em> identify <em>Images</em> or <em>Maps</em>. Instead, it will only identify objects that have the <em>exact</em> text <em>.*ma.*</em> which really doesn&#8217;t exist anywhere on the Google homepage.
</p>
<p>
<span class="postheading">VI. Creating a Description Object for Integer-Types</span><br />
So far, we have only learned various ways to work with description objects using Strings. Here, we will see how they transform into integer-types. Let&#8217;s bring up the properties of the <em>Images</em> link again using the Object spy and feed its &#8220;x&#8221; coordinate to see whether we can find the link:
</p>
<div class="wp-caption aligncenter" style="width: 376px">
	<a href="http://relevantcodes.com/Articles/DescriptionObject/Images_X51.JPG"><img title="Object Spy Snapshot: Images Link (Google)" src="http://relevantcodes.com/Articles/DescriptionObject/Images_X51.JPG" alt="Object Spy Snapshot: Images Link (Google)" width="376" height="378" /></a>
	<p class="wp-caption-text">Object Spy Snapshot: Images Link (Google)</p>
</div>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Link&quot;</span>
oDesc( <span style="color: #800000;">&quot;x&quot;</span> ).value = 51             <span style="color: #008000;">'It should always be 51, not &quot;51&quot;.
</span>
<span style="color: #0000A6;">Set</span> colObject = Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).ChildObjects( oDesc )
&nbsp;
<span style="color: #008000;">'Will return 1
</span>MsgBox colObject.Count
&nbsp;
<span style="color: #008000;">'Will return Images
</span><span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> colObject.Count - 1
	MsgBox colObject(x).GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
Notice that <em>51</em> above is not within <em>quotation marks</em>. This should always be the case. Notice when we replace it with a string-type below:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Link&quot;</span>
oDesc( <span style="color: #800000;">&quot;x&quot;</span> ).value = <span style="color: #800000;">&quot;51&quot;</span>
&nbsp;
<span style="color: #0000A6;">Set</span> colObject = Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).ChildObjects( oDesc )
&nbsp;
MsgBox colObject.Count
&nbsp;
<span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> colObject.Count - 1
	MsgBox colObject(x).GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
The collection is an empty one:
</p>
<div class="wp-caption aligncenter" style="width: 533px">
	<a href="http://relevantcodes.com/Articles/DescriptionObject/Integer.JPG"><img title="(Mis)Using Integers as Strings" src="http://relevantcodes.com/Articles/DescriptionObject/Integer.JPG" alt="(Mis)Using Integers as Strings" width="533" height="350" /></a>
	<p class="wp-caption-text">(Mis)Using Integers as Strings</p>
</div>
<p>
So, always remember to treat integers as they are. This always holds true for <em>x, y, abs_x, abs_y</em>.
</p>
<p>
<span class="postheading">VII. Building Object hierarchy with ChildObjects</span><br />
We will use the Browser Object Collection to set a value in a text box to demonstrate this:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc        <span style="color: #008000;">'Description Object
</span><span style="color: #0000A6;">Dim</span> colObject    <span style="color: #008000;">'Object Collection
</span>
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
oDesc( <span style="color: #800000;">&quot;micclass&quot;</span> ).value = <span style="color: #800000;">&quot;Browser&quot;</span>
oDesc( <span style="color: #800000;">&quot;title&quot;</span> ).value = <span style="color: #800000;">&quot;Google&quot;</span>
&nbsp;
<span style="color: #008000;">'Notice we used the Desktop Object again for retrieving Window collection
</span><span style="color: #0000A6;">Set</span> colObject = Desktop.ChildObjects( oDesc )
&nbsp;
<span style="color: #008000;">'Retrieve the count
</span>iCount = colObject.Count
&nbsp;
<span style="color: #008000;">'Set value in the WebEdit of the last Window object in the collection
</span><span style="color: #0000A6;">For</span> x = 0 <span style="color: #0000A6;">to</span> iCount - 1
   <span style="color: #008000;">'Verify if the Browser title equals &quot;Google&quot;
</span>   <span style="color: #0000A6;">If</span> Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; x).GetROProperty(<span style="color: #800000;">&quot;title&quot;</span>) = <span style="color: #800000;">&quot;Google&quot;</span> <span style="color: #0000A6;">Then</span>
      <span style="color: #008000;">'Set Description.Create in the search TextBox
</span>      Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span>&amp;x).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Description.Create&quot;</span>
   <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">Next</span></pre></div></div>

<p>
When the above snippet executes, we will have the following value set in the Search TextBox in Google HomePage:
</p>
<div class="wp-caption aligncenter" style="width: 375px">
	<a href="http://relevantcodes.com/Articles/DescriptionObject/DescriptionCreateSet.JPG"><img title="Using Description.Create to Set Value" src="http://relevantcodes.com/Articles/DescriptionObject/DescriptionCreateSet.JPG" alt="Using Description.Create to Set Value" width="375" height="69" /></a>
	<p class="wp-caption-text">Using Description.Create to Set Value</p>
</div>
<p>
I hope this article will help you guys understand the concepts of one of the most important concepts in Descriptive Programming: the Description Object. Thanks for visiting Relevant Codes :)
</p>
<p class="alert">If you have any questions, please ask them in the comments section. If your information is to be treated as confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-all-about-the-description-object-description-create/feed/</wfw:commentRss>
		<slash:comments>119</slash:comments>
		</item>
		<item>
		<title>Descriptive Programming (DP) &#8211; 4 (Creating a Test Script)</title>
		<link>http://relevantcodes.com/descriptive-programming-dp-4-creating-a-test-script/</link>
		<comments>http://relevantcodes.com/descriptive-programming-dp-4-creating-a-test-script/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 01:13:34 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[Descriptive Programming]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[QTP Test Script]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=222</guid>
		<description><![CDATA[This is the 4th article in the series and will show how DP can be used to create a test module in QTP. ]]></description>
			<content:encoded><![CDATA[<p></p><div class="photo_right"><a href="http://www.flickr.com/photos/40564275@N04/3896051441/" title="Back to work!"><img src="http://farm3.static.flickr.com/2549/3896051441_e06cd307c6_m.jpg" alt="Back to work!" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" ><img src="http://relevantcodes.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" width="16" height="16" /></a> <a href="http://www.photodropper.com/photos/">photo</a> credit: <a href="http://www.flickr.com/photos/40564275@N04/3896051441/" title="Francisco Javier Martín" >Francisco Javier Martín</a></small></div>
<p>This is the last article in our Descriptive Programming series and will cover a simple login process using 100% DP. I have purposely created the example to be very high-level to make sure its quit easy to understand. However, if you feel more examples on this concept will help, I&#8217;ll be more than happy to create a Part V of this series with only real-world examples of DP in action.</p>
<p>We will use the <a href="http://newtours.demoaut.com">HP/Mercury Demo Website</a> for this example.</p>
<p>Following is the process I am going to follow to complete this process. In your application however, you can use the process that best suits your needs, but for the purposes of this lesson, I will keep it quite basic:</p>
<ol>
<li>Launch Browser.</li>
<li>Check whether the correct browser opened.</li>
<li>Ensure the userName, password edits and the Sign-In button exist.</li>
<li>Set the userName and password and Click Sign-In.</li>
<li>Make sure the browser navigated to the correct page.</li>
</ol>
<p><strong>Step 1</strong>: Launch Browser</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'We will use SystemUtil.Run to launch our target browser
</span>SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://newtours.demoaut.com/&quot;</span></pre></div></div>

<p><strong>Step 2</strong>: Checking if the correct browser opened</p>
<p>The 2 new concepts in this step are:</p>
<ol>
<li><b>Reporter Object</b>: This object is used to send individual reports to the test results. In other words, when the test ends, you can see the reported events in your Test results.</li>
<li><b>ExitTest</b>: A utility statement available to QTP that enables it to complete exit a Test. In other words, when this statement executes, the test execution ends.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">If</span> Browser( <span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span> ).Exist( 15 ) <span style="color: #0000A6;">Then</span>
   Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;Step 1- Launch&quot;</span>, <span style="color: #800000;">&quot;Correct browser was launched.&quot;</span>
<span style="color: #0000A6;">Else</span>
   Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Step 1- Launch&quot;</span>, <span style="color: #800000;">&quot;Browser failed to launch.&quot;</span>
   ExitTest
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span></pre></div></div>

<p><strong>Step 3</strong>: Ensure the userName, password edits and the Sign-In button exist.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Notice the use of the wildcard character below
</span><span style="color: #0000A6;">If</span> Browser(<span style="color: #800000;">&quot;title:=Welcome:.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).Exist(0) <span style="color: #0000A6;">Then</span>
   <span style="color: #008000;">'set username
</span>   <span style="color: #0000A6;">If</span> Browser(<span style="color: #800000;">&quot;title:=Welcome:.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).Exist(0) <span style="color: #0000A6;">Then</span>
      <span style="color: #008000;">'set password
</span>      <span style="color: #0000A6;">If</span> Browser(<span style="color: #800000;">&quot;title:=Welcome:.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).Image(<span style="color: #800000;">&quot;name:=login&quot;</span> ).Exist(0) <span style="color: #0000A6;">Then</span>
         <span style="color: #008000;">'click button
</span>      <span style="color: #0000A6;">Else</span>
         <span style="color: #008000;">'report that Sign-In button was not found
</span>      <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
   <span style="color: #0000A6;">Else</span>
      <span style="color: #008000;">'report that the password edit was not found
</span>   <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">Else</span>
   <span style="color: #008000;">'report that the userName edit was not found
</span><span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span></pre></div></div>

<p><strong>Step 4</strong>: Set the userName and password and Click Sign-In.</p>
<p>The following will complete the snippet above:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Notice the use of the wildcard character below
</span><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;title:=Welcome:.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>)
   <span style="color: #0000A6;">If</span> .WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).Exist(0) <span style="color: #0000A6;">Then</span>
      .WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
      <span style="color: #0000A6;">If</span> .WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).Exist(0) <span style="color: #0000A6;">Then</span>
         .WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
         <span style="color: #0000A6;">If</span> .Image(<span style="color: #800000;">&quot;name:=login&quot;</span> ).Exist(0) <span style="color: #0000A6;">Then</span>
            .Image(<span style="color: #800000;">&quot;name:=login&quot;</span> ).Click
         <span style="color: #0000A6;">Else</span>
            Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Sign-In Button Error&quot;</span>, <span style="color: #800000;">&quot;Button not found.&quot;</span>
         <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
      <span style="color: #0000A6;">Else</span>
         Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Password Edit Error&quot;</span>, <span style="color: #800000;">&quot;EditBox not found.&quot;</span>
      <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
   <span style="color: #0000A6;">Else</span>
      Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;UserName Edit Error&quot;</span>, <span style="color: #800000;">&quot;EditBox not found.&quot;</span>
   <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span></pre></div></div>

<p><strong>Step 5</strong>: Make sure the browser navigated to the correct page</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Synchronize with a browser
</span>Browser( <span style="color: #800000;">&quot;title:=.*&quot;</span> ).Sync
&nbsp;
<span style="color: #008000;">'Wait 1 second for browser with &quot;Find a Flight&quot; title to exist
</span><span style="color: #0000A6;">If</span> Browser( <span style="color: #800000;">&quot;title:=Find a Flight.*&quot;</span> ).Exist( 1 ) <span style="color: #0000A6;">Then</span>
   Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;Login&quot;</span>, <span style="color: #800000;">&quot;Login successful&quot;</span>
<span style="color: #0000A6;">Else</span>
   Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Login&quot;</span>, <span style="color: #800000;">&quot;Login failed&quot;</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span></pre></div></div>

<p>Putting it all together</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'We will use SystemUtil.Run to launch our target browser
</span>SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://newtours.demoaut.com/&quot;</span>
&nbsp;
<span style="color: #0000A6;">If</span> Browser( <span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span> ).Exist( 15 ) <span style="color: #0000A6;">Then</span>
   Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;Step 1- Launch&quot;</span>, <span style="color: #800000;">&quot;Correct browser was launched.&quot;</span>
<span style="color: #0000A6;">Else</span>
   Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Step 1- Launch&quot;</span>, <span style="color: #800000;">&quot;Browser failed to launch.&quot;</span>
   ExitTest
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
&nbsp;
<span style="color: #008000;">'Notice the use of the wildcard character below
</span><span style="color: #0000A6;">With</span> Browser(<span style="color: #800000;">&quot;title:=Welcome:.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>)
   <span style="color: #0000A6;">If</span> .WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).Exist(0) <span style="color: #0000A6;">Then</span>
      .WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
      <span style="color: #0000A6;">If</span> .WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).Exist(0) <span style="color: #0000A6;">Then</span>
         .WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
         <span style="color: #0000A6;">If</span> .Image(<span style="color: #800000;">&quot;name:=login&quot;</span>).Exist(0) <span style="color: #0000A6;">Then</span>
            .Image(<span style="color: #800000;">&quot;name:=login&quot;</span>).Click
         <span style="color: #0000A6;">Else</span>
            Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Sign-In Button Error&quot;</span>, <span style="color: #800000;">&quot;Button not found.&quot;</span>
         <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
      <span style="color: #0000A6;">Else</span>
         Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Password Edit Error&quot;</span>, <span style="color: #800000;">&quot;EditBox not found.&quot;</span>
      <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
   <span style="color: #0000A6;">Else</span>
      Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;UserName Edit Error&quot;</span>, <span style="color: #800000;">&quot;EditBox not found.&quot;</span>
   <span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">With</span>
&nbsp;
Browser( <span style="color: #800000;">&quot;title:=.*Mercury.*&quot;</span> ).Sync
&nbsp;
<span style="color: #0000A6;">If</span> Browser( <span style="color: #800000;">&quot;title:=Find a Flight.*&quot;</span> ).Exist( 1 ) <span style="color: #0000A6;">Then</span>
   Reporter.ReportEvent micPass, <span style="color: #800000;">&quot;Login&quot;</span>, <span style="color: #800000;">&quot;Login successful&quot;</span>
<span style="color: #0000A6;">Else</span>
   Reporter.ReportEvent micFail, <span style="color: #800000;">&quot;Login&quot;</span>, <span style="color: #800000;">&quot;Login failed&quot;</span>
<span style="color: #0000A6;">End</span> <span style="color: #0000A6;">If</span></pre></div></div>

<p>If you have any doubt in the content above, please feel free to post a comment about it. I hope this article helps understand further the principles of Descriptive Programming and using it in your everyday work.</p>
<p class="custPostHeading">Descriptive Programming Series</p>
<ol>
<li><a href="http://relevantcodes.com/descriptive-programming-concepts-1/">Descriptive Programming (DP) Concepts – 1</a></li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/">Descriptive Programming (DP) Concepts – 2 {Regular Expressions}</a></li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/">Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}</a></li>
<li>Descriptive Programming (DP) – 4 {Creating a Test Script)</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/descriptive-programming-dp-4-creating-a-test-script/feed/</wfw:commentRss>
		<slash:comments>105</slash:comments>
		</item>
		<item>
		<title>Descriptive Programming (DP) Concepts &#8211; 3 (Ordinal Identifiers)</title>
		<link>http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/</link>
		<comments>http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 01:08:07 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[Descriptive Programming]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DP Ordinal Identifier]]></category>
		<category><![CDATA[Ordinal Identifiers]]></category>
		<category><![CDATA[QTP Descriptive Programming Ordinal Identifier]]></category>
		<category><![CDATA[QTP Ordinal Identifier]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=215</guid>
		<description><![CDATA[This article outlines the concepts of Ordinal Identifiers used in QTP. We will also create a simple test module (step by step) for a login process using only Descriptive Programming (DP).]]></description>
			<content:encoded><![CDATA[<p></p><p>This is the third article in the Descriptive Programming series, and will outline the concepts of Ordinal Identifiers used in QTP. We will also create a simple test module (step by step) for a login process using only Descriptive Programming (DP).</p>
<p><h2>Ordinal Identifiers &#8211; What are they?</h2>
<p>Let me quote QTP Reference here:</p>
<blockquote><p>An ordinal identifier assigns a numerical value to a test object that indicates its order or location relative to other objects with an otherwise identical description (objects that have the same values for all properties). This ordered value provides a backup mechanism that enables QuickTest to create a unique description to recognize an object when the defined properties are not sufficient to do so.</p></blockquote>
<p>Let&#8217;s break the above definition from Mercury/HP into several parts to clarify the concept.</p>
<blockquote><p>An ordinal identifier assigns a numerical value to a test object</p></blockquote>
<p>From the quote above, we can conclude that an ordinal identifier is a numerical entity. In other words, its simply a number that is assigned to a test object.</p>
<blockquote><p>that indicates its order or location relative to other objects with an otherwise identical description (objects that have the same values for all properties)</p></blockquote>
<p>This means, an Ordinal Identifier works quite differently in relation to the properties we learned in the <a href="http://relevantcodes.com/descriptive-programming-concepts-1/">1st part</a> of this series. This identifier, or a property if you will, works according to the <i>order</i> or <i>location</i> of test objects. Objects&#8217; order and location are unique characteristics. For example, in a coordinate system, generally only a single object exists on a given &#8216;x,y&#8217; coordinate. Thus, an ordinal identifier will always be unique. Index defines the order, and location defines location.</p>
<blockquote><p>This ordered value provides a backup mechanism that enables QuickTest to create a unique description to recognize an object when the defined properties are not sufficient to do so.</p></blockquote>
<p>The quote above is a good way to conclude this concept of Ordinal Identifiers in QTP. Since it is always unique for an object, it can become extremely useful including these with objects&#8217; mandatory and assisstive properties to prevent falling into object recognition problems. The 3 types of ordinal identifiers are: Location, Index and CreationTime (browser only).</p>
<p><h2>Location Ordinal Identifier</h2>
<p>Let&#8217;s use an example to understand how the Location Identifier works. Consider the 4 WebEdits below:
</p>
<table>
<tr>
<td>Text Box 1:<br />
<input type="text" name="dpTest" class="dpTest" size="10" />&nbsp;&nbsp;</td>
<td>Text Box 2:<br />
<input type="text" name="dpTest" class="dpTest" size="10" /></td>
</tr>
<tr>
<td>Text Box 3:<br />
<input type="text" name="dpTest" class="dpTest" size="10" />&nbsp;&nbsp;</td>
<td>Text Box 4:<br />
<input type="text" name="dpTest" class="dpTest" size="10" /></td>
</tr>
</table>
<p><br/></p>
<p>All the edits above have exactly the same properties. This property works vertically, from <i>top to bottom</i>, and left to right. Thus, &#8216;Text Box <b>1</b>&#8216; will have a location value of 0, &#8216;Text Box <b>3</b>&#8216; will have 1, &#8216;Text Box <b>2</b>&#8216; will have 2, and &#8216;Text Box <b>4</b>&#8216; will have 3. Note that VBScript is zero based, so the location property would start at 0. This can be verified by running the following statements:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Text Box 1
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>,<span style="color: #800000;">&quot;location:=0&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;1&quot;</span>
&nbsp;
<span style="color: #008000;">'Text Box 3
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>,<span style="color: #800000;">&quot;location:=1&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;2&quot;</span>
&nbsp;
<span style="color: #008000;">'Text Box 2
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>,<span style="color: #800000;">&quot;location:=2&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;3&quot;</span>
&nbsp;
<span style="color: #008000;">'Text Box 4
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>,<span style="color: #800000;">&quot;location:=3&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;4&quot;</span></pre></div></div>

<pre>
Text Box 1: location=0
Text Box 2: location=2
Text Box 3: location=1
Text Box 4: location=3
</pre>
<p><h2>Index Ordinal Identifier</h2>
<p>Index is quite similar to location, but it works pertaining to appearance of objects in the source code<sup><a href="http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/#comment-3451">1</a></sup>. An object appearing prior in the source code will have a smaller Index value as compared to another object that comes later in the source. Thus, for the same group of edit boxes above: &#8216;Text Box 1&#8242; will have an index of 0, &#8216;Text Box 2&#8242; will have 1, &#8216;Text Box 3&#8242; will have 2 and &#8216;Text Box 4&#8242; will have 3. Let&#8217;s test our statements:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Text Box 1
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;1&quot;</span>
&nbsp;
<span style="color: #008000;">'Text Box 2
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>, <span style="color: #800000;">&quot;index:=1&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;2&quot;</span>
&nbsp;
<span style="color: #008000;">'Text Box 3
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>, <span style="color: #800000;">&quot;index:=2&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;3&quot;</span>
&nbsp;
<span style="color: #008000;">'Text Box 4
</span>Browser(<span style="color: #800000;">&quot;title:=.*Descriptive.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=dpTest&quot;</span>, <span style="color: #800000;">&quot;index:=3&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;4&quot;</span></pre></div></div>

<pre>
Text Box 1: index=0
Text Box 2: index=1
Text Box 3: index=2
Text Box 4: index=3
</pre>
<p>That was quite easy, wasn&#8217;t it? Now, let&#8217;s move on to CreationTime, which is an ordinal identifier strictly reserved for the browser object.</p>
<p><h2>CreationTime Ordinal Identifier</h2>
<p>Again, let&#8217;s use the description given by HP/Mercury in QTP&#8217;s helpfile:
</p>
<blockquote><p>If there are several open browsers, the one with the lowest CreationTime is the first one that was opened and the one with the highest CreationTime is the last one that was opened.</p></blockquote>
<p>That means, the first browser you open will have a creationtime of 0. The second browser will have a creationtime of 1. The third browser will have a creationtime of 2 and so on.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://www.HP.com&quot;</span>               <span style="color: #008000;">'CreationTime 0
</span>SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://www.AdvancedQTP.com&quot;</span>      <span style="color: #008000;">'CreationTime 1
</span>SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://www.LinkedIn.com&quot;</span>         <span style="color: #008000;">'CreationTime 2
</span>
Browser( <span style="color: #800000;">&quot;creationtime:=&quot;</span> ).Highlight     <span style="color: #008000;">'Highlight HP.com
</span>Browser( <span style="color: #800000;">&quot;creationtime:=1&quot;</span> ).Highlight    <span style="color: #008000;">'Highlight AdvancedQTP.com
</span>Browser( <span style="color: #800000;">&quot;creationtime:=2&quot;</span> ).Highlight    'Highlight LinkedIn.com</pre></div></div>

<p>When you run the above code in QTP, you will find that the first browser QTP highlights on is HP.com, the second is AdvancedQTP.com and the third is LinkedIn.com. Even this is quite simple, isn&#8217;t it?</p>
<p>As promised, we must create a simple login process using the concepts we have learned so far in the next article.</p>
<p><h2>Descriptive Programming Series</h2>
<ol>
<li><a href="http://relevantcodes.com/descriptive-programming-concepts-1/">Descriptive Programming (DP) Concepts – 1</a></li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/">Descriptive Programming (DP) Concepts – 2 {Regular Expressions}</a></li>
<li>Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}</li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-4-creating-a-test-script/">Descriptive Programming (DP) – 4 {Creating a Test Script)</a></li>
</ol>
<p><sup>1.</sup> Credits go to <a href="http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/#comment-3451">Harish</a> for finding this error. Thank you Harish!!</p>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/feed/</wfw:commentRss>
		<slash:comments>73</slash:comments>
		</item>
		<item>
		<title>Descriptive Programming (DP) vs Object Repository (OR)</title>
		<link>http://relevantcodes.com/dp-vs-or/</link>
		<comments>http://relevantcodes.com/dp-vs-or/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:48:35 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[Descriptive Programming]]></category>
		<category><![CDATA[Descriptive Programming vs Object Repository]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DP vs OR]]></category>
		<category><![CDATA[Object Repository]]></category>
		<category><![CDATA[OR]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=99</guid>
		<description><![CDATA[This article compares the uses of Descriptive Programming vs Object Repository in QTP. ]]></description>
			<content:encoded><![CDATA[<p></p><div class="photo_right"><a href="http://www.flickr.com/photos/26455260@N06/3814424271/" title="Comparison"><img src="http://farm4.static.flickr.com/3105/3814424271_fb99f5dc51_m.jpg" alt="Comparison" /></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License"><img src="http://relevantcodes.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" width="16" height="16" /></a> <a href="http://www.photodropper.com/photos/">photo</a> credit: <a href="http://www.flickr.com/photos/26455260@N06/3814424271/" title="dkalo">dkalo</a></small></div>
<p>DP vs OR: Which is better?</p>
<p>This has been a never ending debate and if you follow QTP forums, you will see a thread pop-up every few days. Most commonly, the OP is trying to inquire which one would be better (vague?), which one would require less maintenance time, which one is more user-friendly, which has the performance upside, which one will my boss admire more etc.</p>
<p>The answer isn&#8217;t simple.</p>
<p>That&#8217;s why this has been a never ending debate :)</p>
<p>I do not guarantee that after reading this post, you will have an answer, but I am sure with some planning, you will be able to make up your mind as to which one would be the better alternative in the long run.</p>
<p><b>1.</b> In Expert View, DP and OR statements are written in the following manner:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'OR
</span>Browser( <span style="color: #800000;">&quot;Google&quot;</span> ).Page( <span style="color: #800000;">&quot;Google&quot;</span> ).WebEdit( <span style="color: #800000;">&quot;q&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Google Search&quot;</span>
&nbsp;
<span style="color: #008000;">'DP
</span>Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span> ).Page( <span style="color: #800000;">&quot;title:=Google&quot;</span> ).WebEdit( <span style="color: #800000;">&quot;name:=q&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Google Search&quot;</span></pre></div></div>

<p>With DP, the properties are written with their corresponding values. OR, on the other hand, shows only a logical description of the object.</p>
<p><b>2.</b> A DP parent will only recognize a child that has DP style layout. In other words, you CANNOT add a child to a DP parent that has its properties stored in the OR. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Will not work: Browser is DP whereas Page and WebEdit are OR
</span>Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span> ).Page( <span style="color: #800000;">&quot;Google&quot;</span> ).WebEdit( <span style="color: #800000;">&quot;q&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Google Search&quot;</span>
&nbsp;
<span style="color: #008000;">'Will not work: Browser and Page are DP whereas WebEdit is OR
</span>Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span> ).Page( <span style="color: #800000;">&quot;title:=Google&quot;</span> ).WebEdit( <span style="color: #800000;">&quot;q&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Google Search&quot;</span></pre></div></div>

<p>However, an OR parent will recognize both OR and DP style children:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Will work: Browser is OR whereas Page and WebEdit are DP
</span>Browser( <span style="color: #800000;">&quot;Google&quot;</span> ).Page( <span style="color: #800000;">&quot;title:=Google&quot;</span> ).WebEdit( <span style="color: #800000;">&quot;name:=q&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Google Search&quot;</span>
&nbsp;
<span style="color: #008000;">'Will work: Browser and Page are OR whereas WebEdit is DP
</span>Browser( <span style="color: #800000;">&quot;Google&quot;</span> ).Page( <span style="color: #800000;">&quot;Google&quot;</span> ).WebEdit( <span style="color: #800000;">&quot;name:=q&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;Google Search&quot;</span></pre></div></div>

<p><b>3.</b> Writing good DP for Objects takes experience and skill. Even though DP has become extremely popular, improperly written DP can lead to performance issues, maintenance headaches etc. Its quite a different story with OR where you record the objects and QTP creates the hierarchy.</p>
<p><b>4.</b> The user must be careful when using DP: it is case sensitive (except in the case of Web Applications). Do not confuse this with how VBScript works. If the value of a property &#8216;html id&#8217; is &#8216;txtZip&#8217; then it must be coded as &#8216;txtZip&#8217;, not &#8216;txtzip&#8217; or &#8216;TXTZIP&#8217;. QTP will only find the object if the value is written exactly as in the Object Spy. Example (WebEdit&#8217;s name property is retrieved as &#8216;editNewName&#8217;):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'Correct description for WebEdit
</span>Window(<span style="color: #800000;">&quot;nativeclass:=Test&quot;</span>).WinEdit( <span style="color: #800000;">&quot;name:=editNewName&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;DP&quot;</span>
&nbsp;
<span style="color: #008000;">'Incorrect description for WebEdit
</span>Window(<span style="color: #800000;">&quot;nativeclass:=Test&quot;</span>).WinEdit( <span style="color: #800000;">&quot;name:=editnewname&quot;</span> ).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;DP&quot;</span>
&nbsp;
<span style="color: #008000;">'Incorrect description for WebEdit
</span>Window(<span style="color: #800000;">&quot;nativeclass:=Test&quot;</span>).WinEdit( <span style="color: #800000;">&quot;name:=EDITNEWNAME&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;DP&quot;</span></pre></div></div>

<p><b>5.</b>Unlike OR, DP does not have auto-complete. All object descriptions must be coded out manually. This can be quite time consuming, and even frustrating for people who&#8217;re used to working with OR.</p>
<div class="wp-caption aligncenter" style="width: 292px">
	<a href="http://relevantcodes.com/Articles/DPvsOR/OR-AutoComplete.JPG"><img title="Object Repository Auto Complete Feature" src="http://relevantcodes.com/Articles/DPvsOR/OR-AutoComplete.JPG" alt="Object Repository Auto Complete Feature" width="292" height="67" /></a>
	<p class="wp-caption-text">Object Repository Auto Complete Feature</p>
</div>
<p><b>6.</b>Unlike OR&#8217;s &#8216;Highlight in Application&#8217; feature, when searching for an object hierarchy written in DP, you must execute the line of code to locate the object in the application. Another way would be to keep a record of all objects, which can be quite tedious.</p>
<div class="wp-caption aligncenter" style="width: 178px">
	<a href="http://relevantcodes.com/Articles/DPvsOR/OR-HighlightInApplication.JPG"><img title="Object Repository Highlight in Application Feature" src="http://relevantcodes.com/Articles/DPvsOR/OR-HighlightInApplication.JPG" alt="Object Repository Highlight in Application Feature" width="178" height="80" /></a>
	<p class="wp-caption-text">Object Repository Highlight in Application Feature</p>
</div>
<p><b>7.</b> DP supports ChildObjects (to create the description object, you MUST use DP). Description object example:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oDesc
&nbsp;
<span style="color: #0000A6;">Set</span> oDesc = Description.Create
<span style="color: #008000;">'Add a name property to the description
</span>oDesc( <span style="color: #800000;">&quot;name&quot;</span> ).Value = <span style="color: #800000;">&quot;q&quot;</span>
<span style="color: #008000;">'Add a html tag property to the description
</span>oDesc( <span style="color: #800000;">&quot;html tag&quot;</span> ).Value = <span style="color: #800000;">&quot;INPUT&quot;</span></pre></div></div>

<p><b>8.</b> On average, DP is slower than OR (note: on average!). With DP, QTP creates the an object from the provided hierarchy of DP and locates the object in the application before performing an event. Demo:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'OR: 9.74 seconds
</span><span style="color: #0000A6;">For</span> i = 0 <span style="color: #0000A6;">to</span> 99
	Browser(<span style="color: #800000;">&quot;Google&quot;</span>).Page(<span style="color: #800000;">&quot;Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;q&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;QTP&quot;</span>
<span style="color: #0000A6;">Next</span>
&nbsp;
<span style="color: #008000;">'DP: 14.64 seconds
</span><span style="color: #0000A6;">For</span> i = 0 <span style="color: #0000A6;">to</span> 99
	Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;QTP&quot;</span>
<span style="color: #0000A6;">Next</span></pre></div></div>

<p><b>9.</b> OR has a GUI which makes is easy to understand object hierarchies and maintain objects. DP hierarchies are code statements. Example:</p>
<div class="wp-caption aligncenter" style="width: 215px">
	<a href="http://relevantcodes.com/Articles/DPvsOR/OR-FrontEndGUI.JPG"><img title="Object Repository Front End GUI" src="http://relevantcodes.com/Articles/DPvsOR/OR-FrontEndGUI.JPG" alt="Object Repository Front End GUI" width="215" height="127" /></a>
	<p class="wp-caption-text">Object Repository Front End GUI</p>
</div>
<div class="wp-caption aligncenter" style="width: 457px">
	<a href="http://relevantcodes.com/Articles/DPvsOR/DP-WhiteBox.JPG"><img title="WhiteBox style DP" src="http://relevantcodes.com/Articles/DPvsOR/DP-WhiteBox.JPG" alt="WhiteBox style DP" width="457" height="29" /></a>
	<p class="wp-caption-text">WhiteBox style DP</p>
</div>
<p><b>10.</b> <em>.Object</em> is available to both DP and OR:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'OR
</span>Browser(<span style="color: #800000;">&quot;Google&quot;</span>).Page(<span style="color: #800000;">&quot;Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;q&quot;</span>).<span style="color: #0000A6;">Object</span>.Value = <span style="color: #800000;">&quot;QTP&quot;</span>
&nbsp;
<span style="color: #008000;">'DP
</span>Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0000A6;">Object</span>.Value = <span style="color: #800000;">&quot;QTP&quot;</span></pre></div></div>

<p><b>11.</b> Objects have logical names in OR which makes it easy to identify them. Sadly, DP doesn&#8217;t, since its based on principles of a white-box.</p>
<p><b>12.</b> This is strictly for OR, but at times you will notice that when working with applications, objects are added as: WebEdit_1, WebEdit_2, WebEdit_3 &#8230; WebEdit_n and so on. This can be extremely cumbersome to deal with, and it takes quite long to rename all the objects in OR to give them meaningful names.</p>
<p><b>13.</b> Code written with DP can be easily copied/pasted onto other scripts or functions. With OR based scripts, a simple copy/paste will not result in a working script. All the repositories (local/shared) would have to be associated with the test to make it executable. Therefore, when creating test with many reusable components, its generally easier to work with DP in comparison to OR unless there is a comprehensive use of Shared Object Repositories <strong>[Credits: <a href="http://relevantcodes.com/dp-vs-or/comment-page-1/#comment-831">Yogindernath</a></strong>.</p>
<p><b>14.</b> Object Repositories have capabilities to perform single-point maintenance, whereas with DP, during changes, all objects undergo manual updates. In situations where there are several changes in the AUT, OR can prove to be a better performer <strong>[Credits: <a href="http://relevantcodes.com/dp-vs-or/comment-page-1/#comment-1320">Marc Miedemo</a>]</strong>.</p>
<p>If you feel I have missed something and must be added or corrected, please post a comment and I will update this post, giving full credit to you. Thanks :)</p>
<p>
<strong>References</strong><br />
1. <a href="http://www.connectedtesting.com/Presentations/QTP%20-%20OR_DP%20presentation.ppt">Connected Testing</a>
</p>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/dp-vs-or/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>Descriptive Programming (DP) Concepts &#8211; 2 (Regular Expressions)</title>
		<link>http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/</link>
		<comments>http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:46:04 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[Descriptive Programming]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[QTP DP Regular Expression]]></category>
		<category><![CDATA[QTP Regex]]></category>
		<category><![CDATA[QTP RegExp]]></category>
		<category><![CDATA[QTP Regular Expression]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=91</guid>
		<description><![CDATA[This topic provides an excellent introduction to Regular Expressions with DP in QTP. It also discusses the famous wild card character in detail.]]></description>
			<content:encoded><![CDATA[<p></p><p>A wildcard character can be used to substitute for any other character or characters in a string.<sup>1</sup>  This means, we can use a wildcard to make our descriptions more generic. For example, if the property &#8216;file name&#8217; of an Image is &#8216;getAllAttributes.JPG&#8217;, we can use a wildcard several ways:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">' Only using the first 2 words: getAll
</span>Browser( <span style="color: #800000;">&quot;title:=MyTitle&quot;</span> ).Page( <span style="color: #800000;">&quot;title:=MyTitle&quot;</span> ).Image( <span style="color: #800000;">&quot;file name:=getAll.*&quot;</span> ).Click
<span style="color: #008000;">' Using 1 word (Attributes) with the extension (JPG)
</span>Browser( <span style="color: #800000;">&quot;title:=MyTitle&quot;</span> ).Page( <span style="color: #800000;">&quot;title:=MyTitle&quot;</span> ).Image( <span style="color: #800000;">&quot;file name:=.*Attributes.*JPG&quot;</span> ).Click</pre></div></div>

<p>Let&#8217;s put this technique into practice. Let&#8217;s use <a href='http://newtours.demoaut.com' >Mercury Tours</a> for this test. Let&#8217;s try to identify the banner image (banner2.gif) having the following text embed: &#8216;one cool summer ARUBA&#8217;.</p>
<div class="wp-caption aligncenter" style="width: 488px">
	<a href="http://newtours.demoaut.com"><img alt="This image is the property of http://newtours.demoaut.com (HP/Mercury)" src="http://relevantcodes.com/Articles/DP_Regex/banner2.gif" width="488" height="63" /></a>
	<p class="wp-caption-text">This image is the property of http://newtours.demoaut.com (HP/Mercury)</p>
</div>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=banner2.gif&quot;</span>).Highlight
&nbsp;
Browser(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=banner2.*&quot;</span>).Highlight
&nbsp;
Browser(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=banner.*&quot;</span>).Highlight
&nbsp;
Browser(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=ban.*gif&quot;</span>).Highlight
&nbsp;
Browser(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=ban.*f&quot;</span>).Highlight</pre></div></div>

<p>Ofcourse, there are more ways to identify the banner image, but I&#8217;ve only used the above 5. Similarly, we can use this wildcard character for the Browser and Page objects:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">' Without wildcard(s): 0.20 seconds
</span>Browser(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome: Mercury Tours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=banner2.gif&quot;</span>).Click
&nbsp;
<span style="color: #008000;">' With wildcard(s): 0.30 seconds
</span>Browser(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=.*Mercury Tours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=banner2.gif&quot;</span>).Highlight   
&nbsp;
<span style="color: #008000;">' 0.28 seconds
</span>Browser(<span style="color: #800000;">&quot;title:=Welcome:.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=banner2.*&quot;</span>).Highlight          
&nbsp;
<span style="color: #008000;">' 0.56 seconds
</span>Browser(<span style="color: #800000;">&quot;title:=.*Mercury Tours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=.*: Mercury.*&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=banner.*&quot;</span>).Highlight  
&nbsp;
<span style="color: #008000;">' 0.61 seconds
</span>Browser(<span style="color: #800000;">&quot;title:=.*Mercury Tour.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welcome:.*&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=ban.*gif&quot;</span>).Highlight    
&nbsp;
<span style="color: #008000;">' 0.51 seconds
</span>Browser(<span style="color: #800000;">&quot;title:=.*: Mercury.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=.*Mercury Tour.*&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=ban.*f&quot;</span>).Highlight</pre></div></div>

<p>You might notice a little drop in performance for some of the above statements. This is quite obvious though. Using a real world example:</p>
<p><strong>Scenario 1</strong><br />
If you were asked to deliver a letter to John and you had the following piece of information provided: Building 184, Floor 5, Room 120, Desk 9. You would know that you first have to find Building A, then take an elevator to the 5th floor, find Room 120, and once you&#8217;re inside room 120, John sits on Desk # 9. This is quite straight-forward and ofcourse you&#8217;ll be able to quickly find John. </p>
<p><strong>Scenario 2</strong><br />
In another scenario, if you were asked to deliver a letter to John who is in Building 184 and on the 5th floor, how would you find John? You would have to go to each room and ask for John, and make sure it is the correct John before delivering the letter to him. This might take longer.</p>
<p>This is roughly what happens in our scripts. As our descriptions get more and more generic, the time it takes to identify the object increases. Therefore, even though wildcard characters can simplify our work, we should be a little careful how we use them.</p>
<p><a href="http://www.regular-expressions.info/">Regular-Expressions.Info</a> is a good source to learn regular-expressions. We will now do the exact same test we did about with Banner2.gif, but this time using some more regex style characters.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">' Using the first few characters of the title and the first few characters of the image
</span>Browser(<span style="color: #800000;">&quot;title:=Welc\w+\D+\w+&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Welc\w+\D+\w+&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=ban\w+\d+\.\w+&quot;</span>).Highlight
&nbsp;
<span style="color: #008000;">' Using the last few characters of the title with first and last characters of the image
</span>Browser(<span style="color: #800000;">&quot;title:=\w+\D+\w+ours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=\w+\D+\w+ours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=b\w+2\.gif&quot;</span>).Highlight
&nbsp;
<span style="color: #008000;">' Same as above for Browser and Page, but '...' for image
</span>Browser(<span style="color: #800000;">&quot;title:=\w+\D+\w+ours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=\w+\D+\w+ours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=b\w+2\....&quot;</span>).Highlight
&nbsp;
<span style="color: #008000;">' Same as above, but replaced 'b' with a '.'
</span>Browser(<span style="color: #800000;">&quot;title:=\w+\D+\w+ours&quot;</span>).Page(<span style="color: #800000;">&quot;title:=\w+\D+\w+ours&quot;</span>).Image(<span style="color: #800000;">&quot;file name:=.\w+2\....&quot;</span>).Highlight</pre></div></div>

<p>In the proceeding article we will cover Ordinal Identifiers and also see how to create a simple test module for a login process.</p>
<p>
<span class="postheading">Descriptive Programming Series</span></p>
<ol>
<li><a href="http://relevantcodes.com/descriptive-programming-concepts-1/">Descriptive Programming (DP) Concepts – 1</a></li>
<li>Descriptive Programming (DP) Concepts – 2 {Regular Expressions}</li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/">Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}</a></li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-4-creating-a-test-script/">Descriptive Programming (DP) – 4 {Creating a Test Script)</a></li>
</ol>
<p>
<span class="postheading">References</span></p>
<ol>
<li><a href='http://en.wikipedia.org/wiki/Wildcard_character'>Wildcard Character, Wikipedia</a></li>
<li>QuickTest Professional Help </li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>Descriptive Programming (DP) Concepts &#8211; 1</title>
		<link>http://relevantcodes.com/descriptive-programming-concepts-1/</link>
		<comments>http://relevantcodes.com/descriptive-programming-concepts-1/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:45:25 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/DP]]></category>
		<category><![CDATA[Descriptive Programming]]></category>
		<category><![CDATA[Descriptive Programming Introduction]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DP Introduction]]></category>
		<category><![CDATA[DP Lesson]]></category>
		<category><![CDATA[DP Tutorial]]></category>
		<category><![CDATA[QTP Descriptive Programming]]></category>
		<category><![CDATA[QTP Descriptive Programming Tutorial]]></category>
		<category><![CDATA[QTP DP]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=89</guid>
		<description><![CDATA[Descriptive programming has become the technique of choice for many QTP test developers. This topic provides an excellent introduction to DP with QTP.]]></description>
			<content:encoded><![CDATA[<p></p><p><span class="postheading">Introduction</span><br />
Descriptive programming has become the technique of choice for many QTP test developers. We can talk about its advantages and disadvantages all day, but here, we&#8217;ll only discuss the concepts and come up with our own idea of what it does better, and what it doesn&#8217;t :). This is going to be a very quick refresher before we move on to its everyday application by completing an end-to-end testcase.</p>
<p>The idea behind descriptive programming is for automation developers to instruct QTP which properties they would like to use to identify an object, instead of having QTP to choose them itself. If done correctly, this can help create robustness in scripts, ultimately requiring less maintenance-time and more development time.</p>
<p>Let&#8217;s begin.</p>
<p>But wait, before we really begin, we must understand QTP&#8217;s Object Spy. It is an inbuilt tool that enlists all of the test-object and runtime-object properties. These properties are different for different types for objects. For example, an image has a property called &#8216;file name&#8217; whereas a listbox doesn&#8217;t. Instead, a listbox has a special &#8216;all items&#8217; property whereas the image doesn&#8217;t. This discussion will be limited to the usage test-object properties to identify objects. Below are 2 snapshots of the Object Spy:</p>
<div class="wp-caption aligncenter" style="width: 23px">
	<a href="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_Icon.JPG"><img title="Object Spy Icon" src="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_Icon.JPG" alt="Object Spy Icon" width="23" height="24" /></a>
	<p class="wp-caption-text">Object Spy Icon</p>
</div>
<div class="wp-caption aligncenter" style="width: 335px">
	<a href="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_Window.JPG"><img title="Object Spy Window" src="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_Window.JPG" alt="Object Spy Window" width="335" height="570" /></a>
	<p class="wp-caption-text">Object Spy Window</p>
</div>
<p>Now, let&#8217;s open www.Google.com and use the object spy to retrieve all properties of the search box:</p>
<div class="wp-caption aligncenter" style="width: 352px">
	<a href="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_AllEditBoxProperties.JPG"><img title="Object Spy: WebEdit Properties" src="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_AllEditBoxProperties.JPG" alt="Object Spy: WebEdit Properties" width="352" height="795" /></a>
	<p class="wp-caption-text">Object Spy: WebEdit Properties</p>
</div>
<p>Notice the image above. The editbox has a HTML TAG property with its corresponding value &#8216;INPUT&#8217;. This means, the editbox takes some input from the user &#8211; which is true because we do set some value in it! It also has a &#8216;MAX LENGTH&#8217; property, with a value of &#8217;2048&#8242;. This means, you can enter a maximum of 2048 characters in it (the best source to see all of the Test-Object properties of objects is the QTP help itself). Below you will see an editBox which can contain a maximum of 9 characters:</p>
<p class="centeralign">Test maxLength:<br />
<input maxlength="9" name="enterSomeVal" type="text" /></p>
<p>You can really use all these properties to identify this editbox, but, do we really need to use all of them? No. That is the most important idea behind descriptive programming &#8211; we only use what we need. Below is how we write descriptions for objects:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">ObjectClassName(<span style="color: #800000;">&quot;property:=value&quot;</span>, <span style="color: #800000;">&quot;property:=value&quot;</span>)
&nbsp;
<span style="color: #008000;">' ofcourse we're not limited to only 2 properties. We can write more:
</span>ObjectClassName(<span style="color: #800000;">&quot;property:=value&quot;</span>, <span style="color: #800000;">&quot;property:=value&quot;</span>, <span style="color: #800000;">&quot;property:=value&quot;</span>)</pre></div></div>

<p>Above, ObjectClassName (in Web applications) can be Browser, Page, Frame, WebEdit, Image etc. Properties come from the left column the ObjectSpy column whereas values are in the right column. We can include as many properties as we want, but in reality, we only need to add a few to uniquely identify the object. Knowing which properties should suffice to uniquely identify can object will come from experience and practice. Below is a description I created for this editbox (WebEdit):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'ObjectClassName( &quot;property1:=value1&quot;, &quot;property2:=value2&quot; )
</span>WebEdit( <span style="color: #800000;">&quot;name:=q&quot;</span>, <span style="color: #800000;">&quot;html tag:=INPUT&quot;</span> )</pre></div></div>

<p>I already mentioned the HTML TAG and its value INPUT above. We&#8217;ve also added a new property/value here: &#8216;name:=q&#8217;. Is this enough to uniquely identify the object? Yes. But is it enough to make our script work? No, sadly its not.. and that is because, we haven&#8217;t yet created descriptions for its parent objects: Browser &amp; Page. Below are the snapshots of the spied browser and page objects:</p>
<div class="wp-caption aligncenter" style="width: 355px">
	<a href="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_BrowserProperties.JPG"><img title="Object Spy: Browser Properties" src="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_BrowserProperties.JPG" alt="Object Spy: Browser Properties" width="355" height="687" /></a>
	<p class="wp-caption-text">Object Spy: Browser Properties</p>
</div>
<div class="wp-caption aligncenter" style="width: 355px">
	<a href="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_PageProperties.JPG"><img title="Object Spy: Page Properties" src="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_PageProperties.JPG" alt="Object Spy: Page Properties" width="355" height="687" /></a>
	<p class="wp-caption-text">Object Spy: Page Properties</p>
</div>
<p>Browser description:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'ObjectClassName( &quot;property1:=value1&quot; )
</span>Browser( <span style="color: #800000;">&quot;title:=Google&quot;</span> )</pre></div></div>

<p>Page description:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Page( <span style="color: #800000;">&quot;title:=Google&quot;</span> )</pre></div></div>

<p>Now, we will connect all these descriptions and form a hierarchical tree:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>,<span style="color: #800000;">&quot;html tag:=INPUT&quot;</span>)</pre></div></div>

<p>You might wonder why I have omitted the WebTable below the Page and above the WebEdit object. In practice, we can also skip the Page object to identify the WebEdit. But, why did I skip the WebTable after all!? When you experiment more with DP, you will discover that some objects are embedded in many WebTables, and it will become cumbersome if we were to include all WebTables in the hierarchy to get to the object of interest (thanks to the person who thought that will be a terrible idea!). Example of the previously mentioned scenario:</p>
<div class="wp-caption aligncenter" style="width: 367px">
	<a href="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_MultipleWebTables.JPG"><img title="Object Spy: Multiple WebTables" src="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_MultipleWebTables.JPG" alt="Object Spy: Multiple WebTables" width="367" height="635" /></a>
	<p class="wp-caption-text">Object Spy: Multiple WebTables</p>
</div>
<p>To complete the statement above, we will add an event. In QTP, events can be described as actions on target objects. For example, a WebEdit has a &#8216;Set&#8217; event. we use the &#8216;Set&#8217; method of a WebEdit to set a value:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>,<span style="color: #800000;">&quot;html tag:=INPUT&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;DP&quot;</span></pre></div></div>

<p><span class="highlight">Set</span> is a QTP event to put in a value in the edit box. Different objects have different events. For example: an Image has a &#8216;Click&#8217; event associated with it.</p>
<p>This, we did without using Object Repository. The same concept applies to all objects regardless of what your environment is. We perform actions on child objects by accessing their object hierarchies. Let&#8217;s complete the above example by searching for our keywords (use the spy again on the search button):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>, <span style="color: #800000;">&quot;html tag:=INPUT&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;DP&quot;</span>
Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebButton(<span style="color: #800000;">&quot;name:=Google Search&quot;</span>).Click</pre></div></div>

<p>This is how the same code will look like if we had recorded this process:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(<span style="color: #800000;">&quot;Google&quot;</span>).Page(<span style="color: #800000;">&quot;Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;q&quot;</span>).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;DP is great&quot;</span>
Browser(<span style="color: #800000;">&quot;Google&quot;</span>).Page(<span style="color: #800000;">&quot;Google&quot;</span>).WebButton(<span style="color: #800000;">&quot;Google Search&quot;</span>).Click</pre></div></div>

<p>These properties are now stored in QTP&#8217;s Object Repository (OR). There is another way we can create object descriptions, which is done by setting a reference:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">' Creating Browser description
</span><span style="color: #008000;">' &quot;title:=Google&quot;
</span><span style="color: #0000A6;">Set</span> oGoogBrowser = Description.Create
oGoogBrowser( <span style="color: #800000;">&quot;title&quot;</span> ).value = <span style="color: #800000;">&quot;Google&quot;</span>
&nbsp;
<span style="color: #008000;">' Creating Page description
</span><span style="color: #008000;">' &quot;title:=Google&quot;
</span><span style="color: #0000A6;">Set</span> oGoogPage = Description.Create
oGoogPage( <span style="color: #800000;">&quot;title&quot;</span> ).Value = <span style="color: #800000;">&quot;Google&quot;</span>
&nbsp;
<span style="color: #008000;">'* Creating WebEdit description
</span><span style="color: #008000;">' &quot;html tag:=INPUt&quot;, &quot;name:=q&quot;
</span><span style="color: #0000A6;">Set</span> oGoogWebEdit = Description.Create
oGoogWebEdit( <span style="color: #800000;">&quot;html tag&quot;</span> ).Value = <span style="color: #800000;">&quot;INPUT&quot;</span>
oGoogWebEdit( <span style="color: #800000;">&quot;name&quot;</span> ).Value = <span style="color: #800000;">&quot;q&quot;</span></pre></div></div>

<p>Once we do the above, we can use this descriptions in our script:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;">Browser(oGoogBrowser).Page(oGoogPage).WebEdit(oGoogWebEdit).<span style="color: #0000A6;">Set</span> <span style="color: #800000;">&quot;DP is great&quot;</span></pre></div></div>

<p>The only time I use this technique is to retrive object collections through ChildObjects (we will discuss this in the coming tutorials).</p>
<p>Let&#8217;s do another example. Again, we will use Google, but instead of setting a value, we will click an object. You can choose any Link on the page; I chose the link &#8216;Images&#8217;:</p>
<div class="wp-caption aligncenter" style="width: 367px">
	<a href="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_Link_GoogImages.JPG"><img title="Object Spy: Google Images Link" src="http://www.relevantcodes.com/Articles/DPEndToEnd1/ObjectSpy_Link_GoogImages.JPG" alt="Object Spy: Google Images Link" width="367" height="635" /></a>
	<p class="wp-caption-text">Object Spy: Google Images Link</p>
</div>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #008000;">'ClassName(&quot;property:=value&quot;).ClassName(&quot;propert1:=value&quot;).ClassName(&quot;property:=value&quot;).Event
</span>Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Link(<span style="color: #800000;">&quot;innertext:=Images&quot;</span>, <span style="color: #800000;">&quot;html tag:=A&quot;</span>).Click</pre></div></div>

<p>This time, instead of &#8216;Set&#8217; we used &#8216;Click&#8217;. Following is a list of events we perform on Web objects:</p>
<table style="border: 1px solid #999999;" cellpadding="5" >
<tbody>
<tr style="background: #ececec">
<th>Object</th>
<th>Event</th>
</tr>
<tr style="background: #dcdcdc">
<td>Image</td>
<td>Click</td>
</tr>
<tr style="background: #ececec">
<td>WebButton</td>
<td>Click</td>
</tr>
<tr style="background: #dcdcdc">
<td>WebCheckBox</td>
<td>Set</td>
</tr>
<tr style="background: #ececec">
<td>WebEdit</td>
<td>Set</td>
</tr>
<tr style="background: #dcdcdc">
<td>WebElement</td>
<td>Click</td>
</tr>
<tr style="background: #ececec">
<td>WebList</td>
<td>Select</td>
</tr>
<tr style="background: #dcdcdc">
<td>WebRadioGroup</td>
<td>Select</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>Descriptive Programming Series</strong></p>
<ol>
<li>Descriptive Programming (DP) Concepts – 1</li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/">Descriptive Programming (DP) Concepts – 2 {Regular Expressions}</a></li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-concepts-3-ordinal-identifiers-demo/">Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}</a></li>
<li><a href="http://relevantcodes.com/descriptive-programming-dp-4-creating-a-test-script/">Descriptive Programming (DP) – 4 {Creating a Test Script)</a></li>
</ol>
<p><strong>References</strong></p>
<ol>
<li>QuickTest Professional Help</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/descriptive-programming-concepts-1/feed/</wfw:commentRss>
		<slash:comments>123</slash:comments>
		</item>
	</channel>
</rss>

