{"id":920,"date":"2011-12-17T03:28:46","date_gmt":"2011-12-16T21:58:46","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=920"},"modified":"2011-12-17T03:33:45","modified_gmt":"2011-12-16T22:03:45","slug":"how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/","title":{"rendered":"How to achieve Method Overriding &#038; Reuse using RegisterUserFunc in QTP"},"content":{"rendered":"<div style=\"font-family: Verdana; text-align: justify;\">\n<p>Method Overriding is one of the core features of Object Oriented Programming where you can replace the original\/default implementation of a function with your own implementation. In other ways, your new function would override the code or logic of the original function. As an example, consider the addition operation which would give you the sum<!--more--> of a set of numbers. To override this operation, you can create a function (say &#8216;fnSum&#8217;) which would not only find the sum of numbers, but it would also save the sum in an external file or maybe display in a message box. Let&#8217;s see how you can do this in QTP.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" aligncenter\" style=\"border: 0pt none;\" title=\"Method Overriding &amp; reuse in QTP\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/method-override-and-reuse-in-qtp.png\" alt=\"Method Overriding &amp; reuse in QTP\" width=\"252\" height=\"72\" \/><\/p>\n<h3><span style=\"text-decoration: underline;\">Method Overriding in QTP<\/span><\/h3>\n<p>You can use QTP&#8217;s RegisterUserFunc statement to achieve method overriding in your scripts. Consider a scenario where you want to click on a web button in your application. Now you can override the default Click method with a function that first checks whether the web button exists or not. If it exists, then it checks that the button should be enabled. After both these validations are done, comes your code to click on the button. Let&#8217;s see the sample code for this scenario &#8211;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'===== Code in Function Library =====\r\nRegisterUserFunc &quot;WebButton&quot;, &quot;fnBtnClick&quot;, &quot;fnBtnClick&quot;\r\n\r\n'Function Definition\r\nFunction fnBtnClick(objControl)\r\n\r\n'Check if object exists\r\nIf objControl.Exist Then\r\n 'Check if the object is enabled or not\r\n If objControl.GetROProperty(&quot;disabled&quot;) &lt;&gt; 0 Then\r\n  'Click on the button\r\n  objControl.Click\r\n End If\r\nEnd If\r\n\r\nEnd Function\r\n\r\n'===== Sample code in your action =====\r\nBrowser(&quot;Browser&quot;).Page(&quot;Page&quot;).WebButton(&quot;btnSearch&quot;).fnBtnClick\r\n<\/pre>\n<p><em>From the above code, you would see that we have created a function fnBtnClick which overrides the default click operation. This function clicks on the button only when you it exists in the application as well as it is enabled. <\/em><\/p>\n<p><em><br \/>\n<\/em><\/p>\n<h3><span style=\"text-decoration: underline;\">Method Reuse in QTP<\/span><\/h3>\n<p>This is another cool feature that you can actually implement using RegisterUserFunc statement. This concept is slightly different from the normal function reuse where you create a function for a reusable scenario and then call this function wherever required. With RegisterUserFunc, you create a generic function and then bind this function with different controls. For example, you can create a generic fnClick function and then bind the function with a web button, link, image, web element etc. This way you can use the same function for different controls.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'===== Code in Function Library =====\r\nRegisterUserFunc &quot;WebButton&quot;, &quot;fnClick&quot;, &quot;fnClick&quot;\r\nRegisterUserFunc &quot;Link&quot;, &quot;fnClick&quot;, &quot;fnClick&quot;\r\nRegisterUserFunc &quot;Image&quot;, &quot;fnClick&quot;, &quot;fnClick&quot;\r\n\r\n'Function Definition\r\nFunction fnClick(objControl)\r\n objControl.Click\r\nEnd Function\r\n\r\n'=====Code in Action =====\r\nBrowser(&quot;Browser&quot;).Page(&quot;Page&quot;).WebButton(&quot;btn1&quot;).fnClick\r\nBrowser(&quot;Browser&quot;).Page(&quot;Page&quot;).Link(&quot;lnk1&quot;).fnClick\r\nBrowser(&quot;Browser&quot;).Page(&quot;Page&quot;).Image(&quot;img1&quot;).fnClick\r\n<\/pre>\n<p><em>In the above example, we have created a single function fnClick which is being used by different controls like Web Button, Link, Image etc.<\/em><br \/>\n<em><br \/>\n<\/em><\/p>\n<\/div>\n<div style=\"font-family: Verdana,sans-serif; border: 1px solid #C8B560; padding: 3mm; background: #FFF8C6; text-align: center;\">\n<p>If you enjoyed this article, you can join our blog to get free email updates directly in your inbox.<\/p>\n<form style=\"text-align: center;\" action=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify\" method=\"post\" onsubmit=\"window.open('http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=automationrepository\/feeds', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true\" target=\"popupwindow\"><input style=\"width: 160px; height: 20px;\" onfocus=\"if (this.value == 'Enter Your Email Address') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Enter Your Email Address';}\" type=\"text\" value=\"Enter Your Email Address\" \/> <input type=\"hidden\" name=\"uri\" value=\"automationrepository\/feeds\" \/> <input type=\"hidden\" name=\"loc\" value=\"en_US\" \/> <input type=\"submit\" value=\"Join Us\" \/><\/p>\n<p style=\"text-align: justify;\">\n<\/form>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Method Overriding is one of the core features of Object Oriented Programming where you can replace the original\/default implementation of a function with your own implementation. In other ways, your new function would override the code or logic of the original function. As an example, consider the addition operation which would give you the sum<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[53],"class_list":["post-920","post","type-post","status-publish","format-standard","hentry","category-qtp-concepts","tag-registeruserfunc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to achieve Method Overriding &amp; Reuse using RegisterUserFunc in QTP - XX<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anish Pillai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/\",\"name\":\"How to achieve Method Overriding & Reuse using RegisterUserFunc in QTP - XX\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/method-override-and-reuse-in-qtp.png\",\"datePublished\":\"2011-12-16T21:58:46+00:00\",\"dateModified\":\"2011-12-16T22:03:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/method-override-and-reuse-in-qtp.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/method-override-and-reuse-in-qtp.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to achieve Method Overriding &#038; Reuse using RegisterUserFunc in QTP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/\",\"name\":\"XX\",\"description\":\"\\r\\nasas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\",\"name\":\"Anish Pillai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"caption\":\"Anish Pillai\"},\"description\":\"Find more about Anish Pillai on Google+\",\"sameAs\":[\"http:\/\/www.automationrepository.com\"],\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to achieve Method Overriding & Reuse using RegisterUserFunc in QTP - XX","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/","twitter_misc":{"Written by":"Anish Pillai","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/","name":"How to achieve Method Overriding & Reuse using RegisterUserFunc in QTP - XX","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/method-override-and-reuse-in-qtp.png","datePublished":"2011-12-16T21:58:46+00:00","dateModified":"2011-12-16T22:03:45+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/method-override-and-reuse-in-qtp.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/method-override-and-reuse-in-qtp.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/12\/how-to-achieve-method-overriding-and-reuse-using-registeruserfunc-in-qtp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"How to achieve Method Overriding &#038; Reuse using RegisterUserFunc in QTP"}]},{"@type":"WebSite","@id":"https:\/\/www.automationrepository.com\/wordpress\/#website","url":"https:\/\/www.automationrepository.com\/wordpress\/","name":"XX","description":"\r\nasas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20","name":"Anish Pillai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","caption":"Anish Pillai"},"description":"Find more about Anish Pillai on Google+","sameAs":["http:\/\/www.automationrepository.com"],"url":"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/"}]}},"_links":{"self":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/comments?post=920"}],"version-history":[{"count":12,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/920\/revisions"}],"predecessor-version":[{"id":930,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/920\/revisions\/930"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}