<?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</title>
	<atom:link href="http://relevantcodes.com/category/qtp/feed/" rel="self" type="application/rss+xml" />
	<link>http://relevantcodes.com</link>
	<description>A Resource for Test Automation Development</description>
	<lastBuildDate>Thu, 10 May 2012 10:32:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Testing Web Services using QTP, VBScript</title>
		<link>http://relevantcodes.com/working-with-webservices/</link>
		<comments>http://relevantcodes.com/working-with-webservices/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 20:55:09 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[CreateXML]]></category>
		<category><![CDATA[CreateXMLFromFile]]></category>
		<category><![CDATA[Distance Matrix]]></category>
		<category><![CDATA[Get]]></category>
		<category><![CDATA[Google API]]></category>
		<category><![CDATA[LoadXML]]></category>
		<category><![CDATA[Post]]></category>
		<category><![CDATA[ResponseText]]></category>
		<category><![CDATA[WebService]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XMLDOM]]></category>
		<category><![CDATA[XMLHTTP]]></category>
		<category><![CDATA[XMLHTTPRequest]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4994</guid>
		<description><![CDATA[This article was originally requested by one of our visitors - Dhup Chaya. It shows a way to work with Web Services (Google's Distance Matrix API) using XMLHTTPRequest (sending request &#038; receiving response) and parsing the response with both XMLUtil and XMLDOM.]]></description>
			<content:encoded><![CDATA[<p></p><p>W3C defines a Web service as &#8220;a standard means of interoperating between different software applications, running on a variety of platforms and/or frameworks&#8221;. In simple terms, a Web service can be used to integrate web applications. In this exchange of data, XML is used to tag data, SOAP is used to transfer data, WSDL is used to describe how data is exchanged and finally, UDDI lists the services available. For further reading, you can visit <a href="http://msdn.microsoft.com/en-us/library/ms996507.aspx">XML Web Services Basics</a>.</p>
<p>In this topic, we will be using 3 important objects and provide their overview before diving deep into this topic. They are:</p>
<ol>
<li>XMLUtil</li>
<li>XMLDOM</li>
<li>XMLHTTPRequest</li>
</ol>
<h3>XMLUtil</h3>
<p>XMLUtil object provided with QTP is used to access and return XML objects. In other words, XMLUtil can be used to access or expose the contents of an XML file. XMLUtil supports the following 2 methods to create and return an object of type XMLData:</p>
<ol>
<li>CreateXML Method</li>
<li>CreateXMLFromFile</li>
</ol>
<p>More information regarding XMLUtil can be located at QuickTest Professional Object Model Reference.</p>
<h3>XMLDOM</h3>
<p>Similar to XMLUtil object used in QTP, XMLDOM also provides methods and properties to access and return XML objects. I am more accustomed to using this object as opposed to XMLUtil, but they can be both used interchangeably. For further reading, you can visit <a href="http://msdn.microsoft.com/en-us/library/aa468547.aspx">A Beginner&#8217;s Guide to the XML DOM</a>. To create an instance of XMLDOM, CreateObject must be used.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Set</span> xmlParser = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLDOM&quot;</span>)</pre></div></div>

<h3>XMLHTTPRequest</h3>
<p>Unlike XMLUtil and XMLDOM, which are both XML parsers, the XMLHTTPRequest object is an API used to send HTTP or HTTPS requests directly to a Web Server and receiving the response using its Post, Send and Get methods. For further reading, you can visit <a href="http://msdn.microsoft.com/en-us/library/ie/ms535874%28v=vs.85%29.aspx">XMLHttpRequest object</a>. To create an instance of XMLHTTPRequest, CreateObject must be used.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Set</span> XMLHTTPRequest = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLHTTP&quot;</span>)</pre></div></div>

<h2>Google Maps &#8211; The Distance Matrix API</h2>
<p>The Google <a href="https://developers.google.com/maps/documentation/distancematrix/">Distance Matrix API</a> is a Web service used to provide travel distance and time for travel start (origins) and end points (destinations). The response from the API consists of rows containing data for each origin and destination pair.</p>
<p>To request information from the Distance Matrix API, the following URL with <code>output</code> type and input <code>parameters</code> must be used:</p>
<pre>http://maps.googleapis.com/maps/api/distancematrix/output?parameters</pre>
<h3>Output</h3>
<p>Output may be in either <code>JSON</code> or <code>XML</code>. In this topic, <code>XML</code> will be used.</p>
<h3>Parameters</h3>
<p>There is a total of 7 parameters that can be used to request information back from the API. 4 of these parameters are optional.</p>
<ol>
<li>Origins (required)</li>
<li>Destinations (required)</li>
<li>Mode (optional)</li>
<li>Language (optional)</li>
<li>Avoid (optional)</li>
<li>Units (optional)</li>
<li>Sensor (required)</li>
</ol>
<p>For more information, you can refer to the Distance Matrix API <a href="https://developers.google.com/maps/documentation/distancematrix/">documentation</a>.</p>
<p>I feel we&#8217;ve covered enough basics and its time to dig into exchanging data with the Distance Matrix API and then, parse it to get values we&#8217;re concerned with. Below are the values we will be using to request data:</p>
<ul>
<li>output = xml</li>
<li>origins = Atlanta, GA, USA</li>
<li>destinations = Dallas, TX, USA</li>
<li>units = imperial (in miles)</li>
<li>sensor = False</li>
</ul>
<p>The final URL string:</p>
<pre>http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Atlanta+GA+USA&#038;destinations=Dallas+TX+USA&#038;units=imperial&#038;sensor=false</pre>
<p>I also computed the distance using the Google Maps UI (maps.google.com) and got the following result. The result below should match the result obtained from XMLHTTPRequest.</p>
<p><img alt="" class="imgborder" src="/Articles/WorkingWithWebServices/by_car.jpg" title="Google Maps output" class="aligncenter" width="319" height="335" /></p>
<h2>Requesting Information from Distance Matrix API</h2>
<p>In the following code, XMLHTTPRequest object is used to send the string above and receive the corresponding response from the Distance Matrix API.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">url = <span style="color: #800000;">&quot;http://maps.googleapis.com/maps/api/distancematrix/xml?&quot;</span> &amp; _
		<span style="color: #800000;">&quot;origins=Atlanta+GA+USA&amp;&quot;</span> &amp; _
		<span style="color: #800000;">&quot;destinations=Dallas+TX+USA&amp;&quot;</span> &amp; _
		<span style="color: #800000;">&quot;units=imperial&amp;&quot;</span> &amp; _
		<span style="color: #800000;">&quot;sensor=false&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oReq = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLHTTP&quot;</span>)
&nbsp;
oReq.<span style="color: #0600FF; font-weight: bold;">open</span> <span style="color: #800000;">&quot;POST&quot;</span>, url, <span style="color: #0600FF; font-weight: bold;">False</span>
oReq.send
&nbsp;
<span style="color: #008000;">'Response
</span>responseText = oReq.responseText
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Print</span> responseText</pre></div></div>

<h5>Output</h5>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DistanceMatrixResponse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OK<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;origin_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Atlanta, GA, USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/origin_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;destination_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dallas, TX, USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/destination_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OK<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;duration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>47410<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>13 hours 10 mins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/duration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;distance<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1254681<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>780 mi<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/distance<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DistanceMatrixResponse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Simple, isn&#8217;t it? Receiving the response is one thing, parsing it for data important to us is another. In the next part, parsing the above XML will be shown using both XMLUtil and XMLDOM objects.</p>
<h2>Parsing Information using XMLUtil, XMLDOM</h2>
<p>In the last section, we received some data from Google&#8217;s Distance Matrix API by using the <code>.responseText</code> method of XMLHTTPRequest. In this section, we will parse the ResponseText to retrieve the time taken and distance of travel. Below are the 2 nodes from the output above we&#8217;re concerned with:</p>
<pre>
DistanceMatrixResponse\row\element\duration\text
DistanceMatrixResponse\row\element\distance\text
</pre>
<p>I have used the method <code>GetValueByXPath</code> but you can also use <code>ChildElements</code> and <code>ChildElementsByPath</code> methods.</p>
<h5>XMLUtil</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">sNodeDistance = <span style="color: #800000;">&quot;row/element/distance/text&quot;</span>
sNodeDuration = <span style="color: #800000;">&quot;row/element/duration/text&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oParser = XMLUtil.CreateXML()
&nbsp;
<span style="color: #008000;">'Note: responseText comes from XMLHTTPRequest in the previous section
</span>oParser.Load responseText
&nbsp;
<span style="color: #008000;">'Using the XPath above to retrieve distance
</span>nodeDistance = oParser.GetRootElement.GetValueByXPath(sNodeDistance)
&nbsp;
<span style="color: #008000;">'Using the XPath above to retrieve duration
</span>nodeDuration = oParser.GetRootElement.GetValueByXPath(sNodeDuration)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDistance
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDuration</pre></div></div>

<h5>Output</h5>
<p><img alt="" class="imgborder" src="/Articles/WorkingWithWebServices/output.jpg" title="Output" class="aligncenter" width="312" height="153" /></p>
<p>With XMLDOM, I have used the method <code>selectSingleNode</code> but you could also use <code>selectNodes</code>, <code>getElementsByTagName</code> etc. to drill down to the target node.</p>
<h5>XMLDOM</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">sNodeDistance = <span style="color: #800000;">&quot;row/element/distance/text&quot;</span>
sNodeDuration = <span style="color: #800000;">&quot;row/element/duration/text&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oParser = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLDOM&quot;</span>)
&nbsp;
<span style="color: #008000;">'Note: responseText comes from XMLHTTPRequest in the previous section
</span>oParser.loadXML(responseText)
&nbsp;
<span style="color: #008000;">'Distance node: comes from XPath above
</span><span style="color: #0600FF; font-weight: bold;">Set</span> nodeDistance = oParser.documentElement.selectSingleNode(sNodeDistance)
&nbsp;
<span style="color: #008000;">'Duration node: comes from XPath above
</span><span style="color: #0600FF; font-weight: bold;">Set</span> nodeDuration = oParser.documentElement.selectSingleNode(sNodeDuration)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDistance.text
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDuration.text</pre></div></div>

<h5>Output</h5>
<p><img alt="" class="imgborder" src="/Articles/WorkingWithWebServices/output.png" title="Output" class="aligncenter" width="312" height="153" /></p>
<h2>Summary</h2>
<p>In this topic, we saw how to send a request and receive response using XMLHTTPRequest. Later, to parse the response, we used XMLDOM and XMLUtil to retrieve the results.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/working-with-webservices/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>IntelliSense for your Custom Class in 6 Steps</title>
		<link>http://relevantcodes.com/intellisense-for-your-custom-class-in-6-steps/</link>
		<comments>http://relevantcodes.com/intellisense-for-your-custom-class-in-6-steps/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 14:48:51 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Class Intellisense]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Creating Intellisense in QTP]]></category>
		<category><![CDATA[Intellisense]]></category>
		<category><![CDATA[QTP COM Intellisense]]></category>
		<category><![CDATA[QTP Intellisense]]></category>
		<category><![CDATA[QTP Intellisense with .NET]]></category>
		<category><![CDATA[RegAsm]]></category>
		<category><![CDATA[VBC]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4304</guid>
		<description><![CDATA[I have been researching this topic for a very long time and I finally have a workaround which I have tested for for the last 2 months with great success. The best part about this workaround is, I just need to create wrappers, without including any of the code I have in my QTP function libraries. If I add a new method to my class, all I do to update the Intellisense is add the method (without the QTP code) in my VB lib, create a DLL and Register the library for COM Interop.]]></description>
			<content:encoded><![CDATA[<p></p><p>
I have been using classes in my frameworks for a long time now, and my biggest gripe about QTP is its lack of Intellisense for custom classes. It also happens to be my biggest complaint. I understand this is not high priority for HP to include in its newer versions as there is a very small group of people who use OO techniques in test automation with QTP. There has been another workaround by Yaron, who used WSC to create intellisense.
</p>
<p>
I have been researching this topic and I finally have a workaround which I have tested for for the past few weeks with great success. The best part about this workaround is, I just need to create wrappers, without including any of the code I have in my QTP function libraries. If I add a new method to my class, all I do to update the Intellisense is add the method (without the QTP code) in my VB lib, create a DLL and Register the library for COM Interop.
</p>
<p>
Let&#8217;s get working then!
</p>
<h3>Step 1: Create your QTP Modular/Custom/Generic Class</h3>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> LoginClass
&nbsp;
<span style="color: #008000;">'#region Private Variables
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> UserName    <span style="color: #008000;">'As String
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> UserRole    <span style="color: #008000;">'As String
</span>
<span style="color: #008000;">'#region Public Variables
</span>    <span style="color: #0600FF; font-weight: bold;">Public</span> PageTitle    <span style="color: #008000;">'As String
</span>    <span style="color: #0600FF; font-weight: bold;">Public</span> LinksCount   <span style="color: #008000;">'As Integer
</span>    
<span style="color: #008000;">'#region Public Methods
</span>    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> CheckLinks()
        <span style="color: #0600FF; font-weight: bold;">Dim</span> arrLinks
&nbsp;
        arrLinks = Array(<span style="color: #800000;">&quot;Home&quot;</span>, <span style="color: #800000;">&quot;Register&quot;</span>, <span style="color: #800000;">&quot;Language&quot;</span>, <span style="color: #800000;">&quot;Sign-In&quot;</span>)
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Call</span> FunctionToCheckLinks(arrLinks)
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> IsPageFound() <span style="color: #008000;">'As Boolean
</span>        <span style="color: #0600FF; font-weight: bold;">If</span> Browser(<span style="color: #800000;">&quot;title:=MyApp&quot;</span>).Exist(15) <span style="color: #0600FF; font-weight: bold;">Then</span> IsPageFound = <span style="color: #0600FF; font-weight: bold;">True</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #008000;">'#region Class Constructor &amp; Destructor
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>()
        UserName = <span style="color: #800000;">&quot;test&quot;</span>
        UserRole = Global.UserRole
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span>
        <span style="color: #008000;">'code
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Public</span> LoginX: <span style="color: #0600FF; font-weight: bold;">Set</span> LoginX = <span style="color: #0600FF; font-weight: bold;">New</span> LoginClass</pre></div></div>

<h3>Step 2: Converting QTP Class into VB.NET code</h3>
<p>
The next step is converting the method and property names to VB.NET. If you have never used VB.NET, don&#8217;t be scared! The syntax is quite straight-forward. The only thing to note here is, you must return values for Functions and Property Get. Also, the syntax of the Property construct differs slightly in VB.NET. Still, all you are including here are the names. You do NOT have to add the code from your QTP methods.
</p>
<p class="info">Always remember to include the <strong>Microsoft.VisualBasic.ComClass()</strong> flag before the class, and also, remember to make the class <strong>Public</strong></p>
<p class="info">All that goes in the VB.NET code are the names of the properties and methods. Do not include any QTP code here!</p>
<p>
Below is a conversion of the QTP code above, to VB.NET. Notice that I have not included any of the code from my QTP class here:
</p>
<h5>Save the converted code in a .VB format file</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Namespace</span> RelevantCodes
    &lt;Microsoft.VisualBasic.ComClass()&gt; <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #6666CC; font-weight: bold;">Class</span> LoginClass
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> PageTitle <span style="color: #0600FF; font-weight: bold;">As</span> <span style="color: #6666CC; font-weight: bold;">String</span>
            <span style="color: #0600FF; font-weight: bold;">Get</span>
                return <span style="color: #800000;">&quot;title&quot;</span>
            <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Get</span>
            <span style="color: #0600FF; font-weight: bold;">Set</span>(<span style="color: #0600FF; font-weight: bold;">ByVal</span> value <span style="color: #0600FF; font-weight: bold;">As</span> <span style="color: #6666CC; font-weight: bold;">String</span>)
                <span style="color: #008000;">'code
</span>            <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Set</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> LinksCount <span style="color: #0600FF; font-weight: bold;">As</span> <span style="color: #6666CC; font-weight: bold;">Integer</span>
            <span style="color: #0600FF; font-weight: bold;">Get</span>
                return 10
            <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Get</span>
            <span style="color: #0600FF; font-weight: bold;">Set</span>(<span style="color: #0600FF; font-weight: bold;">ByVal</span> value <span style="color: #0600FF; font-weight: bold;">As</span> <span style="color: #6666CC; font-weight: bold;">Integer</span>)
            <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Set</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> CheckLinks()
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> IsPageFound() <span style="color: #0600FF; font-weight: bold;">As</span> <span style="color: #6666CC; font-weight: bold;">Boolean</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Namespace</span></pre></div></div>

<p>
Also remember that, your <strong>Public variables</strong> become <strong>Public Properties</strong> in VB.NET.
</p>
<h3>Step 3: Creating DLL from VB.NET Class using VBC.exe</h3>
<p>
Once our class is ready and we have saved it in <code>.vb</code> format, let&#8217;s create the DLL using VB&#8217;s command line compiler <code>VBC</code. To understand more about VBC, you can use the "VBC.exe /help" in your command prompt to see a full list of commands available. Using the <code>/target:library</code> creates a .NET code library (DLL), which is what we&#8217;re looking for.
</p>
<pre>
C:\windows\Microsoft.NET\Framework\v2.0.50727\vbc.exe /target:library c:\RelevantCodes.vb
</pre>
<p>
Executing the above syntax in cmd.exe will create a DLL file: RelevantCodes.DLL.
</p>
<p class="alert">The path to your VBC.exe file may be different than the one I have used.</p>
<h3>Step 4: Registering Class using RegAsm.exe</h3>
<p>
Next, we will use the .NET assembly registration tool RegAsm.exe that reads the metadata within an assembly (which we created using VBC.exe) and adds the necessary values to your registry. RegAsm.exe syntax: <code>regasm assemblyFile [options]</code>.
</p>
<pre>
C:\windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe c:\Relevantcodes.dll /codebase
</pre>
<p>
If QTP is already open, save all your tests and resources with libraries and re-open it. Launch it, and use CreateObject to create an instance of your class to see if its working. The syntax will be:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Set</span> InstanceName = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Namespace.Class&quot;</span>)
&nbsp;
<span style="color: #008000;">'for our class:
</span><span style="color: #0600FF; font-weight: bold;">Set</span> LoginX = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;RelevantCodes.LoginClass&quot;</span>)</pre></div></div>

<p><img class="imgborder" alt="" src="http://relevantcodes.com/Articles/ClassIntellisense/CreateObject.png" title="CreateObject" class="aligncenter" /></p>
<p>
You must see Intellisense for the instance to ensure everything has been a success until now. If this works, rest is just adding a few values to Registry and we&#8217;re done!
</p>
<h3>Step 5: Adding the Class Reference as a QTP Reserved Word</h3>
<p>
If the above works, <b>we&#8217;re almost done!</b> To get the intellisense for your class, we need to navigate to the registry key below and add a few values to the new key you create. Navigate to the following key in regedit.exe:
</p>
<pre>
HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\
</pre>
<p>
If the above tree does not exist, try this:
</p>
<pre>
HKEY_LOCAL_MACHINE\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\
</pre>
<p>
Once you&#8217;re there, add a new key under reserved objects. You can give this key any name. What I generally do is, I give the same name as my QTP class. My key, then, becomes <strong>LoginClass</strong>. Once the key is created, I create the following entries in the key: ProgID (string), UIName (string) and VisibleMode (DWord).
</p>
<pre>
<b>New Key in \ReservedObjects:</b> Name of your QTP Class

<b>String:</b> ProgID,      <b>Value</b>: Namespace.ClassName
<b>String:</b> UIName,      <b>Value</b>: Name of your reference for your custom QTP class
<b>DWord:</b>  VisibleMode, <b>Value</b>: 2
</pre>
<p>
Therefore, in our case, considering the above, we will have the following values:
</p>
<pre>
<b>New Key in \ReservedObjects:</b> LoginClass

<b>String:</b> ProgID,      <b>Value</b>: RelevantCodes.LoginClass
<b>String:</b> UIName,      <b>Value</b>: LoginX
<b>DWord:</b>  VisibleMode, <b>Value</b>: 2
</pre>
<table style='margin-left:auto; margin-right:auto;'>
<tr>
<td><img alt="" src="http://relevantcodes.com/Articles/ClassIntellisense/ProgID.png" title="ProgID" class="alignleft" /><img alt="" src="http://relevantcodes.com/Articles/ClassIntellisense/UIName.png" title="UIName" class="alignleft" /></td>
</tr>
</table>
<p><img alt="" src="http://relevantcodes.com/Articles/ClassIntellisense/VisibleMode.png" title="VisibleMode" class="aligncenter" /></p>
<p>
The final output of adding the key and all entries to it must look like below:
</p>
<p><img alt="" class="imgborder" src="http://relevantcodes.com/Articles/ClassIntellisense/AllRegValues.png" title="All Registry Values" class="aligncenter" /></p>
<h3>Step 6: Reference the Class Instance with another Keyword</h3>
<p>
Lastly, all you need to do now is add a new variable and reference your Class Instance with it (as shown by <strong>Login</strong> below):
</p>
<pre>
Public LoginX: Set LoginX = New LoginClass
Public Login : Set Login = LoginX
</pre>
<p><img alt="" class="imgborder" src="http://relevantcodes.com/Articles/ClassIntellisense/QTLib.png" title="QTP Library" class="aligncenter" /></p>
<p>
To create your tests and to get Intellisense, remember to associate your library with the test and use the <strong>Login</strong> keyword to see the intellisense.
</p>
<p><img alt="" class="imgborder" src="http://relevantcodes.com/Articles/ClassIntellisense/QTTest.png" title="QTP Test with Intellisense" class="aligncenter" /></p>
<h3>I need to add a new method to my existing class. How do I do that!?!!</h3>
<p>
Well, once you converted the code for your original VB.NET library, DO NOT delete it. Once you add a new Public method to your QTP class, just add it to your VB.NET code, create (update) DLL using VBC.exe and re-register it using RegAsm. The new methods will now be available.
</p>
<h3>Summary</h3>
<p>
In summary, you have to follow the below 6 steps to create Intellisense for your custom QTP class:
</p>
<ol>
<li>Create your QTP class</li>
<li>Convert &#8220;Public&#8221; QTP methods to VB.NET (only the method names required!)</li>
<ul>
<li>Public Class</li>
<li>Microsoft.VisualBasic.ComClass() attribute</li>
</ul>
<li>Use VBC.exe to create .NET library</li>
<ul>
<li>Creates a DLL in the same location as the .VB file</li>
</ul>
<li>Use RegAsm.exe Assembly Registration tool to add necessary values to Registry</li>
<li>Add the Class Instance as a Reserved word in Registry</li>
<li>Reference the class with another Keyword</li>
</ol>
<p>
I hope you will find this helpful. As always, thanks for visiting Relevant Codes :)
</p>
<p class="info">
A lot of time and effort has been put into this article, to research and to test it. The information here is available absolutely free of cost. If you like this article, and if it works for you, please make a donation to a charity of your choice. There is no way we will be able to check if you did, but we know you will. There is a lot of on-going crisis today, and your donation will only help. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/intellisense-for-your-custom-class-in-6-steps/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Get Row/Column Of An Object in a WebTable</title>
		<link>http://relevantcodes.com/get-rowcolumn-of-an-object-in-a-webtable/</link>
		<comments>http://relevantcodes.com/get-rowcolumn-of-an-object-in-a-webtable/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 05:03:28 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[cellIndex]]></category>
		<category><![CDATA[CellInfo]]></category>
		<category><![CDATA[Column]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Object inside Table]]></category>
		<category><![CDATA[QTP Object inside WebTable]]></category>
		<category><![CDATA[Row]]></category>
		<category><![CDATA[rowIndex]]></category>
		<category><![CDATA[td]]></category>
		<category><![CDATA[tr]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4218</guid>
		<description><![CDATA[This article shows a simple way of finding out in which cell a QTP's Test Object resides.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This article shows a simple way of finding out in which cell a QTP&#8217;s Test Object resides. I find the method shown in this article a more effective and faster way of finding the cell I&#8217;m looking for. I have found that this method performs better than traversing rows/cells of a WebTable using in-built WebTable methods such as ChildItem, ChildItemCount and GetCellData. Also, for test objects, it is also not possible to find an exact match with the methods provided for WebTable &#8211; it is only possible for strings.
</p>
<p>
A workaround to find objects inside WebTable using DOM table/tr/td is shown in this article. The code snippets below show how to retrieve the row and column of a given object from a WebTable.
</p>
<p>
Consider the element &#8220;Doe&#8221; in the table below. We can visually see that the link is in the 5th row (starting at the heading) and the 3rd column.
</p>
<table style='margin-left:auto; margin-right:auto;background: #fff;border-collapse: collapse;text-align: left;margin-bottom:27px;'>
<tr>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>ID</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>First Name</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>Last Name</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>Gender</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>Attending class?</td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12345</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>John</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Smith</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>M</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12346</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Anne</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Johnson</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>F</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12347</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Adam</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Roberts</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>M</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12348</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Mary</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Doe</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>F</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12349</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Tiffany</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Smith</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>F</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
</table>
<p>
Executing the following code will provide us our expected output:
</p>
<pre>
Set element = Browser("creationtime:=0").WebElement("innertext:=Doe", "index:=0")

MsgBox "Row# " &#038; element.GetRow()
MsgBox "Col# " &#038; element.GetColumn()
</pre>
<table style='margin-left: auto; margin-right: auto;'>
<tr>
<td><img alt="" src="http://relevantcodes.com/Articles/FindTableCellFromObject/row.png" title="Row Output" class="alignnone" width="154" height="154" /></td>
<td><img alt="" src="http://relevantcodes.com/Articles/FindTableCellFromObject/column.png" title="Column Output" class="alignnone" width="154" height="154" /></td>
</tr>
</table>
<p>
The above example uses WebElement, but <strong>this approach works for all Web objects.</strong> Similarly, the code for finding the 2nd WebCheckBox for Anne Johnson will give us:  <code>Row# 3</code> and <code>Column#5</code> with the following code:
</p>
<pre>
MsgBox Browser("creationtime:=0").WebCheckBox("name:=attending", "index:=1").GetRow
MsgBox Browser("creationtime:=0").WebCheckBox("name:=attending", "index:=1").GetColumn
</pre>
<h2>The Code</h2>
<p>
The following two methods can be used directly for the object and will retrieve &#8216;either&#8217; the row or the column. The below method retrieves the Row for an object residing in a WebTable:
</p>
<h5>Find Row of the Object from WebTable</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetRow(<span style="color: #0600FF; font-weight: bold;">ByVal</span> TObject)
    GetRow = -1
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.<span style="color: #6666CC; font-weight: bold;">Object</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TR&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
            GetRow = TObject.rowIndex + 1
            <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.parentNode
    <span style="color: #0600FF; font-weight: bold;">Loop</span> <span style="color: #0600FF; font-weight: bold;">Until</span> TObject.nodeName = <span style="color: #800000;">&quot;HTML&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Image&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;Link&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebEdit&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebCheckBox&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebElement&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebRadioGroup&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span></pre></div></div>

<h5>Example</h5>
<pre>
MsgBox Browser("title:=myBrowser").Link("innertext:=myLink", "index:=1").GetRow
</pre>
<p>
This method returns the column of the object inside a WebTable:
</p>
<h5>Find Column of the Object from WebTable</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetColumn(<span style="color: #0600FF; font-weight: bold;">ByVal</span> TObject)
    GetColumn = -1
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.<span style="color: #6666CC; font-weight: bold;">Object</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TD&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
            GetColumn = TObject.cellIndex + 1
            <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.parentNode
    <span style="color: #0600FF; font-weight: bold;">Loop</span> <span style="color: #0600FF; font-weight: bold;">Until</span> TObject.nodeName = <span style="color: #800000;">&quot;HTML&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Image&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;Link&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebEdit&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebCheckBox&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebElement&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebRadioGroup&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span></pre></div></div>

<h5>Example</h5>
<pre>
MsgBox Browser("title:=myBrowser").Link("innertext:=myLink", "index:=1").GetColumn
</pre>
<p>
The below implementation retrieves both row and column as a Scripting.Dictionary.
</p>
<h5>Find Row &#038; Column Info as Scripting.Dictionary</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> CellInfo(<span style="color: #0600FF; font-weight: bold;">ByVal</span> TObject)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> dic
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> dic = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
    dic.Add <span style="color: #800000;">&quot;row&quot;</span>, -1
    dic.Add <span style="color: #800000;">&quot;col&quot;</span>, -1
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.<span style="color: #6666CC; font-weight: bold;">Object</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TD&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span> dic(<span style="color: #800000;">&quot;col&quot;</span>) = TObject.cellIndex + 1
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TR&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
            dic(<span style="color: #800000;">&quot;row&quot;</span>) = TObject.rowIndex + 1
            <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.parentNode
    <span style="color: #0600FF; font-weight: bold;">Loop</span> <span style="color: #0600FF; font-weight: bold;">Until</span> TObject.nodeName = <span style="color: #800000;">&quot;HTML&quot;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> CellInfo = dic
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Image&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;Link&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebEdit&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebRadioGroup&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebElement&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebCheckBox&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span></pre></div></div>

<h5>Example</h5>
<pre>
Set cells = Browser("title:=myBrowser").Link("innertext:=myLink", "index:=1").CellInfo()

MsgBox cells("row")
MsgBox cells("col")

cells.RemoveAll
Set cells = Nothing
</pre>
<p>
I hope you find this helpful. As always, thanks for visiting Relevant Codes :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/get-rowcolumn-of-an-object-in-a-webtable/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
		<item>
		<title>ExcelUtil Class Library (MS Excel Utility Methods)</title>
		<link>http://relevantcodes.com/excelutil-class-library-excel-utility-methods/</link>
		<comments>http://relevantcodes.com/excelutil-class-library-excel-utility-methods/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 20:34:45 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Excel Utility]]></category>
		<category><![CDATA[ExcelUtil]]></category>
		<category><![CDATA[ExcelUtil Class Library]]></category>
		<category><![CDATA[RelevantCodes]]></category>
		<category><![CDATA[RelevantCodes.ExcelUtil]]></category>
		<category><![CDATA[SetFile]]></category>
		<category><![CDATA[VBScript Excel]]></category>
		<category><![CDATA[VBScript ExcelUtil]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4100</guid>
		<description><![CDATA[Over the past few years, I have read numerous threads and posts talking about working with Excel using VBScript. Not only have there been numerous threads, but also frameworks that use Excel as the input and/or driver engine. I wanted to work on this mini-project for a long time, and I finally have Version 1.0 of ExcelUtil ready for download! It comes with .CHM documentation.]]></description>
			<content:encoded><![CDATA[<p></p><p>
Over the past few years, I have read numerous threads and posts talking about working with Excel using VBScript. Not only have there been numerous threads, but also frameworks that use Excel as the input and/or driver engine. I wanted to work on this mini-project for a long time, and I finally have Version 1.0 of ExcelUtil ready for download! It comes with <a href="http://relevantcodes.com/Articles/ExcelUtil/Documentation.chm">.CHM documentation</a>.
</p>
<p>
I&#8217;m quite sure I have missed some methods that the community uses, which I have not been able to include in the 1st version. I, however, am open to suggestions and would gladly include your ideas for Version 2.0.
</p>
<p class="centeralign th-box download"><span style='font-weight:bold;'><a class="downloadlink" href="http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=11" title="Version1.0 downloaded 1302 times" >Download RelevantCodes.ExcelUtil Class Library (1302)</a></span></p>
<p>
<strong>IMPORTANT:</strong> To use any method of ExcelUtil, <strong>be sure to use <code>SetFile</code></strong>. This will set the Excel WorkBook and WorkSheet ready for use. To use a different WorkBook or WorkSheet, <code>SetFile</code> will have to be called again.
</p>
<h3>SetFile Property</h3>
<h5>Value Type</h5>
<p class="info">Read only.  A [RelevantCodes.ExcelUtil] object.</p>
<h5>Description</h5>
<p class="info">Sets the region instances for Excel WorkBook and WorkSheet. These instances for the Excel source are created only once and used by other methods. <strong>NOTE: For any method to execute, SetFile must be executed first to set the WorkBook and WorkSheet.</strong></p>
<h5>Syntax</h5>
<pre>
ExcelUtil.SetFile WorkBookPath, WorkSheet
</pre>
<h5>Examples</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Example 1
</span>ExcelUtil.SetFile <span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>
&nbsp;
<span style="color: #008000;">'Example 2:  Reading value directly from a file
</span>sCellValue = ExcelUtil.SetFile(<span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>).GetCellValue(1, 1)
&nbsp;
<span style="color: #008000;">'Example 3:  Reading values from 2 different files - Approach 1
</span>ExcelUtil.SetFile <span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>
var1 = ExcelUtil.GetCellValue(1, 1)
ExcelUtil.SetFile <span style="color: #800000;">&quot;C:\Teacher.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>
var2 = ExcelUtil.GetCellValue(1, 1)
&nbsp;
<span style="color: #008000;">'Example 4:  Reading values from 2 different files - Approach 2
</span>var1 = ExcelUtil.SetFile(<span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>).GetCellValue(1, 1)
var2 = ExcelUtil.SetFile(<span style="color: #800000;">&quot;C:\Teacher.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>).GetCellValue(1, 1)</pre></div></div>

<h3>I found a Bug. What should I do next?</h3>
<p>
Reporting the bug in the comments section will ensure the next version of this class library is more robust! It may not be possible to release the fixed code immediately, but notifying me and the readers of all potential bugs will be highly appreciated! Thank you.
</p>
<h3>I have something cool I would like you to add to ExcelUtil.</h3>
<p>
I would love to hear all ideas and suggestions to improve or enhance this library. Please use the comments section to share them with me and the community. Thank you.
</p>
<p class="centeralign th-box download"><span style='font-weight:bold;'><a class="downloadlink" href="http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=11" title="Version1.0 downloaded 1302 times" >Download RelevantCodes.ExcelUtil Class Library (1302)</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/excelutil-class-library-excel-utility-methods/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Executing QC TestSet via OTA API (QCRunTestSet)</title>
		<link>http://relevantcodes.com/executing-qc-testset-via-ota-api-qcruntestset/</link>
		<comments>http://relevantcodes.com/executing-qc-testset-via-ota-api-qcruntestset/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 12:10:31 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[Quality Center]]></category>
		<category><![CDATA[Custom Run TestSet Object]]></category>
		<category><![CDATA[QC Scheduler]]></category>
		<category><![CDATA[QC Scheduling]]></category>
		<category><![CDATA[QCRunTestSet]]></category>
		<category><![CDATA[Quality Center Scheduling]]></category>
		<category><![CDATA[Remote QC Scheduling]]></category>
		<category><![CDATA[Run TestSet on LocalHost]]></category>
		<category><![CDATA[Run TestSet Remotely]]></category>
		<category><![CDATA[RunTestSet]]></category>
		<category><![CDATA[Schedule Test Set]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4018</guid>
		<description><![CDATA[Over the past few weeks, I have been actively working on Quality Center (ALM) and its integration with QuickTest Professional. One of the mini-projects I've worked on is creating a custom object that executes a test set and sends an email to the supplied distribution list from ALM TestSet's Automation tab. VBScript code available for download. ]]></description>
			<content:encoded><![CDATA[<p></p><p>
For the past few weeks, I have been actively working on Quality Center (<strong>ALM</strong>) and its integration with QuickTest Professional. One of the mini-projects I&#8217;ve worked on is creating a custom object that executes a test set and sends an email to the supplied distribution list from ALM TestSet&#8217;s Automation tab (as shown below):
</p>
<p><img alt="" class="imgborder" src="http://relevantcodes.com/Articles/QCRunTestSet/EMailTo.PNG" title="EMailTo Field in QC TestSet&#039;s Automation tab" class="aligncenter" width="558" height="448" /></p>
<p>
Note: The above part (EMailTo) can be modified by either hard-coding it, or supplying an input from the Class Constructor.
</p>
<p>
I&#8217;ve extensively used the OTA API Reference to build this object and to understand how the API works. .NET developers having difficulty converting the VBScript code, please post in the comments section and I will mail you the class library (currently only C#).
</p>
<h2>Download (ALM Only)</h2>
<p>
QCRunTestSet is available for download, but comes as-is and currently executes TestSets on the localHost. However, I would be more than happy in helping you to modify this code to suit your needs.
</p>
<p class="centeralign th-box download"><span style='font-weight:bold;'><a class="downloadlink" href="http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=10" title=" downloaded 1610 times" >QCRunTestSet.cls.vbs.zip [for ALM] (1610)</a></span></p>
<p>
If you&#8217;re having issues creating an instance of the <code>TSScheduler</code> object, please read <a href="http://www.sqaforums.com/showflat.php?Cat=&#038;Board=UBB20&#038;Number=652599">this thread</a> carefully. You may need to upgrade to a higher patch or perform a client registration on the execution machine.
</p>
<h2>Running QCRunTestSet from CommandLine</h2>
<p>
If you would like to pass parameters from the CommandLine instead of hard-coding them in the code, use WScript to pass arguments and WScript.Arguments to retrieve them in the class library. Example:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Passing arguments
</span>wscript C:\QCRunTestSet.cls.vbs <span style="color: #800000;">&quot;http//&lt;server&gt;:8080/qcbin&quot;</span> myUser myPassword myDomain _
                                                  myProject myTestSetPath myTestSetName</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Retrieving arguments
</span><span style="color: #0600FF; font-weight: bold;">Set</span> args = WScript.Arguments
&nbsp;
QCServer = args(0)
UserName =  args(1)
Password = args(2)
QCDomain = args(3)
QCProject = args(4)
QCTestSetPath = args(5)
QCTestSetName = args(6)</pre></div></div>

<p>
I hope you find this helpful. Thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/executing-qc-testset-via-ota-api-qcruntestset/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>IE Error: A script is causing IE to run slowly</title>
		<link>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/</link>
		<comments>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 03:55:25 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[IE Error]]></category>
		<category><![CDATA[MaxScriptStatements]]></category>
		<category><![CDATA[QTP Web]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3973</guid>
		<description><![CDATA[This tip shows how to disable the Error message: "A script on this page is causing Internet Explorer to run slowly" with using VBScript.]]></description>
			<content:encoded><![CDATA[<p></p><p>
While testing a script on IE8, me and my colleague kept getting the error &#8220;A script on this page is causing Internet Explorer to run slowly&#8221;.  Below is a snapshot of the error:</p>
<p><img alt="" class="imgborder" src="http://relevantcodes.com/Articles/IEScriptRunningSlow/ie_error.JPG" title="IE Error: A script is causing IE to run slowly" class="aligncenter" width="340" height="155" /></p>
<p>After some research, I came across an article on MSDN which already had the solution: <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;175500">Microsoft KB # 175500</a>. The part we are concerned about is in the section &#8220;Let me fix it myself&#8221;:</p>
<p class="info">
1.Using a Registry Editor such as Regedt32.exe, open this key: <i>HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles</i><br />
Note: If the Styles key is not present, create a new key that is called Styles.<br />
2. Create a new DWORD value called &#8220;MaxScriptStatements&#8221; under this key and set the value to the desired number of script statements. If you are unsure of what value you need to set this to, you can set it to a DWORD value of 0xFFFFFFFF to completely avoid the dialog.
</p>
<p>
For the curious ones, the article states that, to encounter the error, the DWord value of <strong>0xFFFFFFFF</strong> must be added.  The value equates to -1, which is what has been used in the function below.
</p>
<h5>Code</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Sub</span> IE_ChangeScriptTimeOut()
	<span style="color: #0600FF; font-weight: bold;">Dim</span> Registry, sKeyPath, sValueName, dwValue, sComputer
	CONST HKEY_CURRENT_USER = &amp;H80000001
&nbsp;
	sKeyPath = <span style="color: #800000;">&quot;Software\Microsoft\Internet Explorer\Styles&quot;</span>
	sValueName = <span style="color: #800000;">&quot;MaxScriptStatements&quot;</span>
	dwValue = -1
	sComputer = <span style="color: #800000;">&quot;.&quot;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
		<span style="color: #0600FF; font-weight: bold;">Set</span> Registry = <span style="color: #0600FF; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot;</span> &amp;_ 
				sComputer &amp; <span style="color: #800000;">&quot;\root\default:StdRegProv&quot;</span>)
&nbsp;
		Registry.CreateKey HKEY_CURRENT_USER, sKeyPath
		Registry.SetDWORDValue HKEY_CURRENT_USER, sKeyPath, sValueName, CLng(dwValue)
	<span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Goto</span> 0
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">Set</span> Registry = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>
Thanks for reading, and thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>QTP CreationTime</title>
		<link>http://relevantcodes.com/creationtime/</link>
		<comments>http://relevantcodes.com/creationtime/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 11:34:51 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Browser Creationtime]]></category>
		<category><![CDATA[CreationTime]]></category>
		<category><![CDATA[Ordinal Identifier]]></category>
		<category><![CDATA[Ordinal Identifier CreationTime]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3930</guid>
		<description><![CDATA[This article explains how the Browser's CreationTime ordinal identifier works in QTP with examples.]]></description>
			<content:encoded><![CDATA[<p></p><p>
I&#8217;ve generally seen some confusion around CreationTime. I think between the 3 Ordinal Identifiers, this one may be the easiest to understand and implement. That&#8217;s mostly because CreationTime is used <span class="emphasis_u">only</span> for the Browser object. Below is how CreationTime is applied to browsers:
</p>
<pre>
1st open browser -> CreationTime of -> 0
2nd open browser -> CreationTime of -> 1
3rd open browser -> CreationTime of -> 2
4th open browser -> CreationTime of -> 3
</pre>
<p>
According to QTP help:
</p>
<p class="info">
This value indicates the order in which the browser was opened relative to other open browsers. For example, if QuickTest learns three browsers that are opened at 9:01 pm, 9:03 pm, and 9:05 pm, QuickTest assigns the CreationTime values, as follows: CreationTime = 0 to the 9:01 am browser, CreationTime = 1 to the 9:03 am browser, and CreationTime = 2 to the 9:06 am browser.
</p>
<p>
Really, that&#8217;s it! No tricks here! To test it for proof, you can open 4 browsers (with different websites) and run the following code in QTP:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">For</span> ix = 0 <span style="color: #0600FF; font-weight: bold;">to</span> 3
	<span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;CreationTime-&gt;&quot;</span> &amp; ix &amp; <span style="color: #800000;">&quot;-&gt;&quot;</span> &amp; Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; ix).GetROProperty(<span style="color: #800000;">&quot;title&quot;</span>)
<span style="color: #0600FF; font-weight: bold;">Next</span></pre></div></div>

<p>
On my desktop, I&#8217;ve 4 open IE windows in the following order: Google, Bing, Yahoo, Microsoft. See snapshot below:
</p>
<div class="wp-caption aligncenter" style="width: 675px">
	<a href="http://relevantcodes.com/Articles/CreationTime/Taskbar.png"><img alt="My taskbar" src="http://relevantcodes.com/Articles/CreationTime/Taskbar.png" title="My taskbar" width="675" height="22" /></a>
	<p class="wp-caption-text">My taskbar: Click to view original size</p>
</div>
<p>
After running the above code, this is what I see in my print log:
</p>
<div class="wp-caption aligncenter" style="width: 321px">
	<img alt="Print log" src="http://relevantcodes.com/Articles/CreationTime/Output.png" title="Print log" width="321" height="162" />
	<p class="wp-caption-text">Print log</p>
</div>
<p>
The output shows the order in which the IE windows are placed on the Desktop, which is same as the order in which they were opened.
</p>
<h2>The tricky part</h2>
<p>
The only tricky part in this concept is its applicability when there is only one browser open. With one open browser, regardless of the CreationTime value supplied, QTP will always identify the only open browser. This is because, CreationTime values are generated when there are multiple browsers open &#8211; with a single open browser, this value is generally has no usage. This is at least true for QTP 10.0 and previous versions.
</p>
<p>
As always, thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/creationtime/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>QTP GUI Objects, VBScript &amp; Try Catch Finally</title>
		<link>http://relevantcodes.com/gui-objects-vbscript-try-catch-finally/</link>
		<comments>http://relevantcodes.com/gui-objects-vbscript-try-catch-finally/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 06:31:17 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Catch]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Error Handling]]></category>
		<category><![CDATA[Finally]]></category>
		<category><![CDATA[Module]]></category>
		<category><![CDATA[QTP Module]]></category>
		<category><![CDATA[Test Module]]></category>
		<category><![CDATA[Try]]></category>
		<category><![CDATA[Try..Catch..Finally]]></category>
		<category><![CDATA[Wrapper]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3802</guid>
		<description><![CDATA[VBScript's error handling techniques have been quite limited to <code>On Error</code> statements, and even though they satisfy our needs to some extent, the lack of incorporating dynamic behavior with them has been a much bigger issue. In this article, I will implement a Try-Catch-Finally statement with QTP's GUI objects along with an On Error statement. This will enable dynamic behavior and enable us to easily divide flow depending on different error conditions.]]></description>
			<content:encoded><![CDATA[<p></p><p>
VBScript&#8217;s error handling techniques have been quite limited to <code>On Error</code> statements, and even though they satisfy our needs to some extent, the lack of incorporating dynamic behavior with them has been a much bigger issue. Lee Harvey <a href="http://my.opera.com/Lee_Harvey/blog/2007/04/21/try-catch-finally-in-vbscript-sure">here</a> shows how <code>Classes</code> can be extended to create simple Try-Catch-Finally statements with just a bit more work. I like this technique, and have been using it for the past few days with success. We know that this is not the best solution that is possible with a scripting language (JS does a lot better!), but its a start and a terrific workaround (thanks Lee!).
</p>
<h2>Creating Try-Catch-Finally Statements in VBScript</h2>
<p>
If you have already read Lee&#8217;s article, you can skip this part. Otherwise, a simple implementation is shown below:
</p>
<ol>
<li>As soon as the class executes, it enters Class_Initialize &#8211; Try statement</li>
<li>It encounters an error &#8211; Err.Raise 1002</li>
<li>As soon as it encounters an error, the Try statement (Class_Initialize) immediately ends execution</li>
<li>Because we&#8217;re releasing the Class reference using <code>Set NewTryCatchFinally = Nothing</code> right after initializing it, the Class enters Class_Terminate</li>
<li>Class_Terminate calls the Catch subroutine</li>
<li>When Catch runs in its entirety, Class_Terminate executes</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #6666CC; font-weight: bold;">Class</span> TryCatchFinally
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span> <span style="color: #008000;">'Try
</span>        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Try..&quot;</span> &amp; vbNewLine
&nbsp;
        Err.Raise 1002 <span style="color: #008000;">'Raise a Syntax Error
</span>        MsgBox <span style="color: #800000;">&quot;This line will not execute&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> Catch <span style="color: #008000;">'Catch
</span>        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number = 0 <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Catch..&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error caught: &quot;</span> &amp; Err.Description  &amp; vbNewLine
&nbsp;
        Err.Clear
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span> : Catch <span style="color: #008000;">'Finally
</span>        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Exiting..&quot;</span> 
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span>
&nbsp;
<span style="color: #008000;">'Enters Try (Error occurs)
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewTryCatchFinally = <span style="color: #0600FF; font-weight: bold;">New</span> TryCatchFinally 
&nbsp;
<span style="color: #008000;">'Enters Catch, then Finally
</span><span style="color: #008000;">'Catch will only execute if Error occured
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewTryCatchFinally = <span style="color: #0600FF; font-weight: bold;">Nothing</span></pre></div></div>

<p>
The output of executing the above code should be the following:
</p>
<div class="wp-caption aligncenter" style="width: 299px">
	<img alt="" src="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/TryCatchPrintLog.png" title="Try Catch Finally Implementation in VBScript" width="299" height="221" />
	<p class="wp-caption-text">Try Catch Finally Implementation in VBScript</p>
</div>
<p>
We can see from the result that as soon as the Class executes, it enters <code>Class_Initialize</code>. When it encounters an error, it enters into <code>Class_Terminate</code> which contains (and executes) the <code>Catch</code> method. A simple yet such an elegant solution!
</p>
<h2>Utility Class &#038; Error Handler</h2>
<p>
In this article, I will try to implement the technique with QTP&#8217;s GUI objects. To begin, let&#8217;s create a simple Login class with the following methods:
</p>
<ol>
<li><code>CheckPage</code></li>
<li><code>CheckImage</code></li>
<li><code>Login</code></li>
</ol>
<p>
The Login Class outputs the result through the <code>Result</code> property:
</p>
<h5>A simple Login Class</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #6666CC; font-weight: bold;">Class</span> Login
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> Result
        Result = CheckPage <span style="color: #0600FF; font-weight: bold;">And</span> CheckImage <span style="color: #0600FF; font-weight: bold;">And</span> Login
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckPage
        MsgBox <span style="color: #800000;">&quot;CheckPage&quot;</span> : CheckPage = <span style="color: #0600FF; font-weight: bold;">True</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckImage
        CheckImage = <span style="color: #0600FF; font-weight: bold;">False</span>
&nbsp;
        Browser(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).WebElement(<span style="color: #800000;">&quot;text:=Relevant Codes&quot;</span>).Click <span style="color: #008000;">'Error here!
</span>
        MsgBox <span style="color: #800000;">&quot;Error!&quot;</span> <span style="color: #008000;">'This will not execute
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #008000;">'This will not execute
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> Login
        MsgBox <span style="color: #800000;">&quot;Login&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Dim</span> NewLogin : <span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">New</span> Login</pre></div></div>

<p class="info">
Above, the Result property of the Login Class is called, which first executes CheckPage, then CheckImage and finally Login. Note that Login will only execute if CheckImage runs without any errors.
</p>
<p>
Let&#8217;s create another class that calls the methods of the original Login class, but with the error handling capabilities of a Try-Catch-Finally statement. This is also the Class that will always execute the original Login class because that&#8217;s where the actual error handling using Try-Catch-Finally exists.
</p>
<h5>Try..Catch..Finally with Class_Initialize &#038; Class_Terminate</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> LoginHandler <span style="color: #008000;">'LoginHandler start
</span>
    <span style="color: #0600FF; font-weight: bold;">Public</span> bResult
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>
         <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Try..&quot;</span> &amp; vbNewLine
         bResult = NewLogin.Result
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> CatchErr
        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number = 0 <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Catch..&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error: &quot;</span> &amp; Err.Description &amp; vbNewLine
&nbsp;
        Err.Clear
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span> : CatchErr
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Exiting..&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span> <span style="color: #008000;">'LoginHandler end
</span>
<span style="color: #008000;">'NewLoginHnder executes the Login Class in 'try'
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">New</span> LoginHandler
&nbsp;
<span style="color: #008000;">'Releasing the instances invokes CatchErr, then Class_Terminate()
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
&nbsp;
<span style="color: #008000;">'Release NowLogin instance
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">Nothing</span></pre></div></div>

<p class="info">
The <code>Class_Initialize</code> method of the class calls the Result property of the Login class. Once Result is called, it executes all the methods called by the Result property. If any error occurs, CatchErr is immediately called by <code>Class_Terminate</code> and later, all code inside the Class_Terminate method is executed.
</p>
<p>
Output of executing Login Class &#038; LoginHandler:
</p>
<div class="wp-caption aligncenter" style="width: 500px">
	<img alt="" src="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/PrintLog1.png" title="Print Log" width="500" height="199" />
	<p class="wp-caption-text">QTP Print Log</p>
</div>
<h2>Method Containing the Error?</h2>
<p>
By including the name of each method in the very first line, we can also find out where exactly the error occurred. This, however, I agree is quite time consuming and repetitive work. The only alternative to this has been shown by PowerDebug Beta. However, if you would like to extend the above approach in VBScript, this *may be* the only possible approach. I&#8217;ve been wrong before, and would love to see a technique which simplifies the method naming approach used below.
</p>
<h5>Login Class with Method Names</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #6666CC; font-weight: bold;">Class</span> Login <span style="color: #008000;">'Login start
</span>
    <span style="color: #0600FF; font-weight: bold;">Public</span> sMethod
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> Result
        Result = CheckPage <span style="color: #0600FF; font-weight: bold;">And</span> CheckImage <span style="color: #0600FF; font-weight: bold;">And</span> Login
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckPage
        Me.sMethod = <span style="color: #800000;">&quot;CheckPage&quot;</span>
&nbsp;
        MsgBox <span style="color: #800000;">&quot;CheckPage&quot;</span> : CheckPage = <span style="color: #0600FF; font-weight: bold;">True</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckImage
        Me.sMethod = <span style="color: #800000;">&quot;CheckImage&quot;</span>
&nbsp;
        CheckImage = <span style="color: #0600FF; font-weight: bold;">False</span>
        Browser(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).WebElement(<span style="color: #800000;">&quot;text:=Relevant Codes&quot;</span>).Click <span style="color: #008000;">'Error here!
</span>        
        MsgBox <span style="color: #800000;">&quot;Error!&quot;</span> <span style="color: #008000;">'This will not execute
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> Login <span style="color: #008000;">'This will not execute
</span>        Me.sMethod = <span style="color: #800000;">&quot;Login&quot;</span>
&nbsp;
        Msgbox <span style="color: #800000;">&quot;Login&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span> <span style="color: #008000;">'Login end
</span><span style="color: #0600FF; font-weight: bold;">Dim</span> NewLogin : <span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">New</span> Login</pre></div></div>

<h5>LoginHandler (Outputs Method Names)</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> LoginHandler <span style="color: #008000;">'LoginHandler start
</span>
    <span style="color: #0600FF; font-weight: bold;">Public</span> bResult
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>
         <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Try..&quot;</span> &amp; vbNewLine
         bResult = NewLogin.Result
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> CatchErr
        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number = 0 <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Catch..&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error occured in: &quot;</span> &amp; NewLogin.sMethod
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error: &quot;</span> &amp; Err.Description &amp; vbNewLine
&nbsp;
        Err.Clear
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span> : CatchErr
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Exiting..&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span> <span style="color: #008000;">'LoginHandler end
</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">New</span> LoginHandler
<span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">Nothing</span></pre></div></div>

<p>
View <a href="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/Example2.txt">code</a>.
</p>
<p>
Output of executing Login Class &#038; LoginHandler:
</p>
<div class="wp-caption aligncenter" style="width: 502px">
	<img alt="" src="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/PrintLog2.png" title="Print Log" width="502" height="211" />
	<p class="wp-caption-text">QTP Print Log</p>
</div>
<h2>Notes</h2>
<p>
After using this technique for several days and manipulating it a bit from the original work, I have found some success. However, implementing Handler classes when the scope of the utility class increases can be quite challenging, and time consuming. I still believe its a start to something that we haven&#8217;t witnessed in QTP (yet). To be honest, I still prefer the old way of doing things where I can branch out most of my GUI code in conditional statements &#8211; which has enabled me to always create more comprehensive reporting.</p>
<p>
My recommendation would be to use this approach with VBScript code instead of using it for QTP&#8217;s GUI objects, ofcourse, until absolutely necessary. Most of my usage for the above technique has been with pure VBScript code which has enabled me to create better error handling. In an upcoming article, I will show how this technique will be used to handle Excel errors and recover from them in the <code>CatchErr</code> method using a Select Case block. Including Try-Catch-Finally statements within Try-Catch-Finally statements is quite easily done in .NET, but its very complex to perform the same operation with VBScript. I&#8217;m still happy to have a start though.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/gui-objects-vbscript-try-catch-finally/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Browser: Not Required!</title>
		<link>http://relevantcodes.com/browser-not-required/</link>
		<comments>http://relevantcodes.com/browser-not-required/#comments</comments>
		<pubDate>Sun, 02 May 2010 17:23:14 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Page]]></category>
		<category><![CDATA[QTP Web]]></category>
		<category><![CDATA[Skip Browser]]></category>
		<category><![CDATA[Skip Page]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3685</guid>
		<description><![CDATA[There is a common perception that we must include the <code>Browser</code> object in hierarchies when working in the Web environment. The truth is that, we really don't need to include the <code>Browser</code> object <span class="emphasis_u">if</span> the <code>Page</code> object has been included in the hierarchy.]]></description>
			<content:encoded><![CDATA[<p></p><p class="info">
This has been tested to work correctly on QTP versions: 9.5+.
</p>
<p>
There is a common perception that we must include the <code>Browser</code> object in hierarchies when working in the Web environment. The truth is that, we really don&#8217;t need to include the <code>Browser</code> object <span class="emphasis_u">if</span> the <code>Page</code> object has been included in the hierarchy.
</p>
<p>
In other words, the commonly written inline statements for Web environment:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">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: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Test&quot;</span>
Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Test&quot;</span></pre></div></div>

<p>
can also be written like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Test&quot;</span></pre></div></div>

<p>
Quick tip! Thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/browser-not-required/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Eval Function &amp; Execute Statement</title>
		<link>http://relevantcodes.com/eval-function-execute-statement/</link>
		<comments>http://relevantcodes.com/eval-function-execute-statement/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 20:24:29 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Eval]]></category>
		<category><![CDATA[Eval Function]]></category>
		<category><![CDATA[Execute]]></category>
		<category><![CDATA[Execute Statement]]></category>
		<category><![CDATA[QTP Eval Function]]></category>
		<category><![CDATA[QTP Execute]]></category>
		<category><![CDATA[QTP Execute Statement]]></category>
		<category><![CDATA[VBScript Eval]]></category>
		<category><![CDATA[VBScript Eval Function]]></category>
		<category><![CDATA[VBScript Execute]]></category>
		<category><![CDATA[VBScript Execute Statement]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3447</guid>
		<description><![CDATA[This topic covers the concepts of the <code>Eval</code> function and <code>Execute</code> statement in depth. The function Eval is used to evaluate a string and return the result of the string expression. The Execute statement on the other hand, executes one or more statements in a string expression and enables creation of dynamic code. Multiple statements can be executed at once by using colons or line breaks to separate them.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This topic covers the concepts of the <code>Eval</code> function and <code>Execute</code> statement in depth. The function Eval is used to evaluate a string and return the result of the string expression. The Execute statement on the other hand, executes one or more statements in a string expression and enables creation of dynamic code. Multiple statements can be executed at once by using colons or line breaks to separate them.
</p>
<p>If you have had a chance to use <a href="http://relevantcodes.com/relevantcodes1one-qtp-automation-framework/">RelevantCodes[1]One</a> and went over the function libraries, you would find that all the events are controlled through <code>Execute</code> statement &#8211; data is retrieved from the Excel Table and parsed by the function libraries into string statements. Once parsed, these string statements are then executed in the same manner as QTP code.
</p>
<h5>Eval Syntax</h5>
<pre>
Eval(expression)
</pre>
<h5>Execute Syntax</h5>
<pre>
Execute statement
</pre>
<h2>Difference between Eval &#038; Execute</h2>
<p>
In the syntax above, both <code>expression</code> and <code>statement</code> arguments are string statements. Both expressions can be derived from VBScript or QTP code; the difference lies in the fact that Eval will always return the result of the string evaluation whereas Execute will execute a string statement for execution and will not retrieve the result (but there are workarounds). The following example demonstrates the main difference between the 2 functions:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">x = 9
y = 10
&nbsp;
bIsEqual = Eval(<span style="color: #800000;">&quot;x = y&quot;</span>)
Execute <span style="color: #800000;">&quot;x = y&quot;</span>
&nbsp;
MsgBox <span style="color: #800000;">&quot;bIsEqual: &quot;</span> &amp; bIsEqual
MsgBox <span style="color: #800000;">&quot;X is no longer 9. It is: &quot;</span> &amp; x</pre></div></div>

<table style='text-align:center; margin-left:auto; margin-right:auto;'>
<tr>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="bIsEqual" src="/Articles/EvalExecute/bIsEqual.png" title="bIsEqual" width="104" height="107" />
	<p class="wp-caption-text">Eval Function</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 146px">
	<img alt="New x" src="/Articles/EvalExecute/NewX.png" title="New x" width="146" height="107" />
	<p class="wp-caption-text">Execute Statement</p>
</div></td>
</tr>
</table>
<p>
Note that Eval returned a Boolean value whereas Execute function performed a variable assignment. This article will cover the usage of both techniques in depth through both VBS and QTP code.
</p>
<p>
You must be wondering why the syntax for Eval and Execute is different. The reason is that, Eval is a function. Execute is not. That means, the following statement for Eval: <code>bIsEqual = Eval("x = y")</code>, when written for Execute will return a Null value for bResult (but assignment will be performed for <code>x</code>):
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">bResult = Execute(<span style="color: #800000;">&quot;x = y&quot;</span>)
MsgBox bResult
MsgBox <span style="color: #800000;">&quot;x: &quot;</span> &amp; x</pre></div></div>

<table style="margin-left:auto; margin-right:auto; text-align:center;">
<tr>
<td><div class="wp-caption aligncenter" style="width: 104px">
	<img alt="Null Output" src="/Articles/EvalExecute/Null.png" title="Null Output" width="104" height="95" />
	<p class="wp-caption-text">Null Output</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Value Assigned" src="/Articles/EvalExecute/X.png" title="Value Assigned" width="104" height="107" />
	<p class="wp-caption-text">X = 10</p>
</div></td>
</tr>
</table>
<p>
With that said, let me share the workaround that can be used with Execute to return the evaluation just like we did with <code>Eval</code>. Here&#8217;s how:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">x = 9
y = 10
&nbsp;
Execute <span style="color: #800000;">&quot;z = (x = y)&quot;</span>
MsgBox <span style="color: #800000;">&quot;z: &quot;</span> &amp; z</pre></div></div>

<div class="wp-caption aligncenter" style="width: 104px">
	<img alt="Return Z (False)" src="/Articles/EvalExecute/ZFalse.png" title="Return Z (False)" width="104" height="107" />
	<p class="wp-caption-text">Return Z (False)</p>
</div>
<p>
More on this concept will be covered in the section <span class="emphasis_u">Evaluating Statements</span>.
</p>
<h2>Creating Variables</h2>
<p>
Let&#8217;s assume a scenario where you need to create the following variables: <code>var_1</code>, &#8230; , <code>var_5</code>. One way is to manually create the variables:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">var_1 = 1 : var_2 = 2 : var_3 = 3 : var_4 = 4: var_5 = 5</pre></div></div>

<p>
A quicker, and more dynamic way to achieve the same is through Execute statement:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">For</span> ix = 1 <span style="color: #0600FF; font-weight: bold;">to</span> 5
    Execute <span style="color: #800000;">&quot;var_&quot;</span> &amp; ix &amp; <span style="color: #800000;">&quot; = &quot;</span> &amp; ix
<span style="color: #0600FF; font-weight: bold;">Next</span></pre></div></div>

<h2>Option Explicit</h2>
<p>
Using the Execute statement also has a direct impact if the <code>Option Explicit</code> statement is ON. If a variable is not explicitly declared, an error will be occurred:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Option</span> <span style="color: #0600FF; font-weight: bold;">Explicit</span>
&nbsp;
iNumber = 9</pre></div></div>

<p><img alt="" src="/Articles/EvalExecute/OptionExplicit.png" title="Option Explicit" class="aligncenter" width="411" height="172" /></p>
<p>
When the same variable is created through Execute, the error will not occur and the variable will be created and value assigned successfully.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Option</span> <span style="color: #0600FF; font-weight: bold;">Explicit</span>
&nbsp;
Execute <span style="color: #800000;">&quot;iNumber = 9&quot;</span></pre></div></div>

<h2>Evaluating Statements</h2>
<p>
Instead of equating variables and values, we will evaluate statements using Eval. A quick example using <code>IsObject</code> is demonstrated below:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Set</span> dicObject = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">If</span> Eval(<span style="color: #800000;">&quot;IsObject(dicObject)&quot;</span>) <span style="color: #0600FF; font-weight: bold;">Then</span>
    MsgBox <span style="color: #800000;">&quot;Object created.&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">Set</span> dicObject = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span></pre></div></div>

<p>
Similarly, the above code can be broken into a <code>Select Case</code> block and variables can be evaluated by their type:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Sub</span> RetType(<span style="color: #0600FF; font-weight: bold;">ByVal</span> var)
	<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #0600FF; font-weight: bold;">Case</span> Eval(<span style="color: #800000;">&quot;TypeName(var)&quot;</span>)
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Integer&quot;</span> : MsgBox <span style="color: #800000;">&quot;Integer&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Dictionary&quot;</span> : MsgBox <span style="color: #800000;">&quot;Dictionary&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Nothing&quot;</span> : MsgBox <span style="color: #800000;">&quot;Nothing&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;String&quot;</span> : MsgBox <span style="color: #800000;">&quot;String&quot;</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Select</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">Nothing</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #800000;">&quot;Test&quot;</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>))
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(1)</pre></div></div>

<p>
Upon execution, the following results will be retrieved:
</p>
<table style='text-align:center; margin-left:auto; margin-right:auto;'>
<tr>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Nothing" src="/Articles/EvalExecute/Nothing.png" title="Nothing" width="104" height="107" />
	<p class="wp-caption-text">RetType(Nothing)</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="String" src="/Articles/EvalExecute/String.png" title="String" width="104" height="107" />
	<p class="wp-caption-text">RetType('Test')</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Dictionary" src="/Articles/EvalExecute/Dict.png" title="Dictionary" width="104" height="107" />
	<p class="wp-caption-text">RetType(CreateObject)</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Integer" src="/Articles/EvalExecute/Integer.png" title="Integer" width="104" height="107" />
	<p class="wp-caption-text">RetType(1)</p>
</div></td>
</tr>
</table>
<p>
The same function above can be written through Execute. However, with Execute, we cannot directly retrieve the result (it is not a function, unlike Eval). Therefore, we will create a variable and store the result with the variable; the variable will then be used as the <code>Select Case</code> condition.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Sub</span> RetType(<span style="color: #0600FF; font-weight: bold;">ByVal</span> var)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> bResult
&nbsp;
	Execute <span style="color: #800000;">&quot;bResult = TypeName(var)&quot;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #0600FF; font-weight: bold;">Case</span> bResult
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Integer&quot;</span> : MsgBox <span style="color: #800000;">&quot;Integer&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Dictionary&quot;</span> : MsgBox <span style="color: #800000;">&quot;Dictionary&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Nothing&quot;</span> : MsgBox <span style="color: #800000;">&quot;Nothing&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;String&quot;</span> : MsgBox <span style="color: #800000;">&quot;String&quot;</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Select</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">Nothing</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #800000;">&quot;Test&quot;</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>))
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(1)</pre></div></div>

<p>
In short then, with Execute, bResult is represented within the string statement:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Execute <span style="color: #800000;">&quot;bResult = TypeName(var)&quot;</span></pre></div></div>

<p>
With Eval, bResult is an actual variable that holds the result like below:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">bResult = Eval(<span style="color: #800000;">&quot;TypeName(var)&quot;</span>)</pre></div></div>

<h2>Creating Functions</h2>
<p>
I have seen this approach rarely used, but its important to know all the possibilities nonetheless. Yes, we can create Functions (really!) at run-time, as long as everything is a string and new lines are separated by colons or a line feed. This approach is generally fine for small functions, but it can get really confusing and hard to debug as the lines of code increase.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">sFunc = <span style="color: #800000;">&quot;Function ExecuteTest&quot;</span>
sFunc = sFunc &amp; vbLf
sFunc = sFunc &amp; <span style="color: #800000;">&quot;MsgBox &quot;</span><span style="color: #800000;">&quot;ExecuteTest executed.&quot;</span><span style="color: #800000;">&quot;&quot;</span>
sFunc = sFunc &amp; vbLf
sFunc = sFunc &amp; <span style="color: #800000;">&quot;End Function&quot;</span>
&nbsp;
Execute sFunc
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> ExecuteTest()</pre></div></div>

<p><img alt="" src="/Articles/EvalExecute/ExecuteTest.png" title="Execute Test output" class="aligncenter" width="140" height="107" /></p>
<p>
We can write the same code above using colons (<code>:</code>) as well:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Execute <span style="color: #800000;">&quot;Function ExecuteTest : MsgBox &quot;</span><span style="color: #800000;">&quot;ExecuteTest executed.&quot;</span><span style="color: #800000;">&quot; : End Function&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> ExecuteTest()</pre></div></div>

<h2>Executing QTP Statements</h2>
<p>
This is where the Execute statement absolutely shines. As stated before, <a href="http://relevantcodes.com/relevantcodes1one-qtp-automation-framework/">RelevantCodes[1]One</a> executes all keywords through Execute statement. It retrieves keywords from the Excel Table as strings at runtime, creates the relevant hierarchies, and executes the hierarchies with chosen events. The concept here and the concepts covered by previous examples will remain the same: we create action strings and execute them. The last example in this topic will show how different strings can be joined together to implement events on supplied test-objects (as strings).
</p>
<p>
Let&#8217;s start with a quick example to check if our target browser exists:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>
&nbsp;
Execute <span style="color: #800000;">&quot;MsgBox &quot;</span> &amp; strBrowser &amp; <span style="color: #800000;">&quot;.Exist(0)&quot;</span></pre></div></div>

<p>
The above code can also be written with Eval as well, enabling us to retrieve the value directly instead of using the workaround approach if we were to use Execute:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>
&nbsp;
bExist = Eval(strBrowser &amp; <span style="color: #800000;">&quot;.Exist(0)&quot;</span>)</pre></div></div>

<p>
The above statement when executed does the same operation as it would when you would verify the browser existence using an inline DP statement: <code>Msgbox Browser("title:=Google").Exist(0)</code>. Let&#8217;s consider another example where we create an event on a WebEdit object by creating an object hierarchy through strings at run time.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>  <span style="color: #008000;">'Browser(&quot;title:=Google&quot;)
</span>strPage    = <span style="color: #800000;">&quot;Page(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>     <span style="color: #008000;">'Page(&quot;title:=Google&quot;)
</span>strText    = <span style="color: #800000;">&quot;WebEdit(&quot;</span><span style="color: #800000;">&quot;name:=q&quot;</span><span style="color: #800000;">&quot;)&quot;</span>        <span style="color: #008000;">'WebEdit(&quot;name:=q&quot;)
</span>strEvent   = <span style="color: #800000;">&quot;Set &quot;</span><span style="color: #800000;">&quot;Execute Test&quot;</span><span style="color: #800000;">&quot;&quot;</span>        <span style="color: #008000;">'Set &quot;Execute Test&quot;
</span>
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strPage &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strText &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strEvent</pre></div></div>

<p>
It does look interesting, doesn&#8217;t it? The same approach can be used if you are using Object Repository instead of Descriptive Programming; simply replace the Programmatic Descriptions with the Logical Descriptions in your OR, parse everything in a string and Execute it!
</p>
<p>
The example below shows how QTP code can be executed into succession through strings. The last 4 statements show how all strings are combined together to 1. Enter the search terms, 2. Click Search Button, 3. Synchronize and 4. Navigate back to the Google search page.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=.*Google.*&quot;</span><span style="color: #800000;">&quot;)&quot;</span>      <span style="color: #008000;">'Browser(&quot;title:=Google&quot;)
</span>strPage    = <span style="color: #800000;">&quot;Page(&quot;</span><span style="color: #800000;">&quot;title:=.*Google.*&quot;</span><span style="color: #800000;">&quot;)&quot;</span>         <span style="color: #008000;">'Page(&quot;title:=Google&quot;)
</span>strText    = <span style="color: #800000;">&quot;WebEdit(&quot;</span><span style="color: #800000;">&quot;name:=q&quot;</span><span style="color: #800000;">&quot;)&quot;</span>                <span style="color: #008000;">'WebEdit(&quot;name:=q&quot;)
</span>strButton  = <span style="color: #800000;">&quot;WebButton(&quot;</span><span style="color: #800000;">&quot;value:=Google Search&quot;</span><span style="color: #800000;">&quot;)&quot;</span> <span style="color: #008000;">'WebButton(&quot;value:=Google Search&quot;)
</span>strEvent   = <span style="color: #800000;">&quot;Set &quot;</span><span style="color: #800000;">&quot;Execute Test&quot;</span><span style="color: #800000;">&quot;&quot;</span>                <span style="color: #008000;">'Set &quot;Execute Test&quot;
</span>strClick   = <span style="color: #800000;">&quot;Click&quot;</span>                               <span style="color: #008000;">'Click
</span>strSync    = <span style="color: #800000;">&quot;Sync&quot;</span>                                <span style="color: #008000;">'Sync
</span>strBack    = <span style="color: #800000;">&quot;Back&quot;</span>                                <span style="color: #008000;">'Back
</span>
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strPage &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strText &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strEvent
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strPage &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strButton &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strClick
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strSync
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strBack</pre></div></div>

<p>
The above strings are equivalent to the following QTP code:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">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: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Execute Test&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;value:=Google Search&quot;</span>).Click
Browser(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).Sync
Browser(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).Back</pre></div></div>

<h2>Closing Remarks</h2>
<p>
I hope this article has covered most of the common (and uncommon) uses of Eval and Execute. I&#8217;m sure you&#8217;ll find areas in your framework where these 2 techniques will make things cleaner and more dynamic. If there is something I have omitted, please feel free to share it with us. I hope you guys find this article useful :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/eval-function-execute-statement/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 10/59 queries in 0.124 seconds using disk: basic
Object Caching 798/971 objects using disk: basic
Content Delivery Network via N/A

Served from: relevantcodes.com @ 2012-05-19 10:45:20 -->
