{"id":263,"date":"2011-09-22T02:54:25","date_gmt":"2011-09-21T21:24:25","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=263"},"modified":"2012-05-08T23:53:01","modified_gmt":"2012-05-08T18:23:01","slug":"associate-function-library-to-qtp-script","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/","title":{"rendered":"4 Different Ways to Associate Function Libraries to your QTP Scripts"},"content":{"rendered":"<div style=\"text-align: justify; font-family: Verdana;\">\n<p>Most of the times, when you are creating test scripts or are designing a new <a title=\"QTP Frameworks \u2013 An Introduction\" href=\"http:\/\/www.automationrepository.com\/2012\/03\/qtp-framework-types-an-introduction\/\">QTP Framework<\/a>, you would be trying to come up with reusable functions which you would have to store in the function library. Now, in order to use this function<!--more--> library with multiple test cases, you need to associate this function library with your scripts. <strong>This article explains the 4 methods that will help you in associating the function libraries in QTP Test Cases.<\/strong><br \/>\n<span><br \/>\n<\/span><br \/>\nBased on the type of framework you are using, you can use any of the following methods to associate function libraries to your QTP Script &#8211;<\/p>\n<ul>\n<li>1) By using <strong>&#8216;File &gt; Settings &gt; Resources &gt; Associate Function Library&#8217;<\/strong> option in QTP.<\/li>\n<li>2) By using <strong>Automation Object Model (AOM<\/strong>).<\/li>\n<li>3) By using <strong>ExecuteFile<\/strong> method.<\/li>\n<li>4) using <strong>LoadFunctionLibrary<\/strong> method.<\/li>\n<\/ul>\n<p><span><br \/>\n<\/span><br \/>\nLet&#8217;s see in detail how each of these methods can be used to map function libraries to your test scripts.<\/p>\n<h3>1. Using &#8216;File &gt; Settings &gt; Resources &gt; Associate Function Library&#8217; option from the Menu bar<\/h3>\n<p>This is the <span style=\"text-decoration: underline;\">most common method<\/span> used to associate a function library to a test case. To use this method, select File &gt; Settings option from the Menu bar. This will display the &#8216;Test Settings&#8217; window. Click on Resources from the left hand side pane. From the right hand side pane, click on the &#8216;+&#8217; button and select the function library that needs to be associated with the test case.<\/p>\n<div style=\"width: 507px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" title=\"Associate function Library to QTP\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/AssociateFunctionLibrary.png\" alt=\"Associate function Library to QTP\" width=\"497\" height=\"341\" \/><p class=\"wp-caption-text\">Associate function Library to QTP<\/p><\/div>\n<p><span><br \/>\n<\/span><\/p>\n<h3>2. Using AOM (Automation Object Model)<\/h3>\n<p>QTP AOM is a mechanism using which you can control various QTP operations from outside QTP. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test.<\/p>\n<p>Example: Using the below code, you can open QTP, then open any test case and associate a required function library to that test case. To do so, copy paste the below code in a notepad and save it with a .vbs extension.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Open QTP\r\nSet objQTP = CreateObject(&quot;QuickTest.Application&quot;)\r\nobjQTP.Launch\r\nobjQTP.Visible = True\r\n\r\n'Open a test and associate a function library to the test\r\nobjQTP.Open &quot;C:\\Automation\\SampleTest&quot;, False, False\r\nSet objLib = objQTP.Test.Settings.Resources.Libraries\r\n\r\n'If the library is not already associated with the test case, associate it..\r\nIf objLib.Find(&quot;C:\\SampleFunctionLibrary.vbs&quot;) = -1 Then ' If library is not already added\r\n  objLib.Add &quot;C:\\SampleFunctionLibrary.vbs&quot;, 1 ' Associate the library to the test case\r\nEnd\r\n<\/pre>\n<p><span><br \/>\n<\/span><\/p>\n<h3>3. Using ExecuteFile Method<\/h3>\n<p>ExecuteFile statement executes all the VBScript statements in a specified file. After the file has been executed, all the functions, subroutines and other elements from the file (function library) are available to the action as global entities. Simply put, once the file is executed, its functions can be used by the action. You can use the below mentioned logic to use ExecuteFile method to associate function libraries to your script.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Action begins\r\nExecuteFile &quot;C:\\YourFunctionLibrary.vbs&quot;\r\n\r\n'Other logic for your action would come here\r\n'.....\r\n<\/pre>\n<p><span><br \/>\n<\/span><\/p>\n<h3>4. Using LoadFunctionLibrary Method<\/h3>\n<p>LoadFunctionLibrary, a new method introduced in QTP 11 allows you to load a function library when a step runs. You can load multiple function libraries from a single line by using a comma delimiter.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Some code from the action\r\n'.....\r\n\r\nLoadFunctionLibrary &quot;C:\\YourFunctionLibrary_1.vbs&quot; 'Associate a single function library\r\nLoadFunctionLibrary &quot;C:\\FuncLib_1.vbs&quot;, &quot;C:\\FuncLib_2.vbs&quot; 'Associate more than 1 function libraries\r\n\r\n'Other logic for your action would come here\r\n'.....\r\n<\/pre>\n<p><span><br \/>\n<\/span><br \/>\nThis was all about the different ways using which you can associate function libraries to QTP Scripts. What are your views on this article? Can you think of any other points which I have missed and can be added here? Please let us know your views using the comments section. Happy Reading.. :&#8211;)<br \/>\n<span><br \/>\n<\/span><\/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: 24px;\" 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=\"Subscribe\" \/><\/p>\n<p style=\"text-align: justify;\">\n<\/form>\n<\/div>\n<p style=\"border: 1px solid #C38EC7; padding: 3mm; background: #EBDDE2;\"><strong>To check out more tutorials, visit our <a title=\"QTP Tutorials\" href=\"http:\/\/www.automationrepository.com\/tutorials-for-qtp-beginners\/\" target=\"_blank\">QTP Tutorials<\/a> page. You can also check the <a title=\"All Articles\" href=\"http:\/\/www.automationrepository.com\/archive\/\" target=\"_blank\">Archives<\/a> page to view the list of all our articles.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the times, when you are creating test scripts or are designing a new QTP Framework, you would be trying to come up with reusable functions which you would have to store in the function library. Now, in order to use this function<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[29,33,30,32,31,17],"class_list":["post-263","post","type-post","status-publish","format-standard","hentry","category-qtp-basic-stuff","tag-aom","tag-associate-function-library","tag-executefile","tag-function-library","tag-loadfunctionlibrary","tag-qtp-11"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>4 Different Ways to Associate Function Libraries to your QTP Scripts - XX<\/title>\n<meta name=\"description\" content=\"Read about all the ways using which you can associate your function library to a QTP Script. These methods are, using AOM, ExecuteFile method, LoadFunctionLibrary method\" \/>\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\/09\/associate-function-library-to-qtp-script\/\" \/>\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\/09\/associate-function-library-to-qtp-script\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/\",\"name\":\"4 Different Ways to Associate Function Libraries to your QTP Scripts - XX\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/AssociateFunctionLibrary.png\",\"datePublished\":\"2011-09-21T21:24:25+00:00\",\"dateModified\":\"2012-05-08T18:23:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"description\":\"Read about all the ways using which you can associate your function library to a QTP Script. These methods are, using AOM, ExecuteFile method, LoadFunctionLibrary method\",\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/AssociateFunctionLibrary.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/AssociateFunctionLibrary.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"4 Different Ways to Associate Function Libraries to your QTP Scripts\"}]},{\"@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":"4 Different Ways to Associate Function Libraries to your QTP Scripts - XX","description":"Read about all the ways using which you can associate your function library to a QTP Script. These methods are, using AOM, ExecuteFile method, LoadFunctionLibrary method","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\/09\/associate-function-library-to-qtp-script\/","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\/09\/associate-function-library-to-qtp-script\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/","name":"4 Different Ways to Associate Function Libraries to your QTP Scripts - XX","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/AssociateFunctionLibrary.png","datePublished":"2011-09-21T21:24:25+00:00","dateModified":"2012-05-08T18:23:01+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"description":"Read about all the ways using which you can associate your function library to a QTP Script. These methods are, using AOM, ExecuteFile method, LoadFunctionLibrary method","breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/AssociateFunctionLibrary.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/AssociateFunctionLibrary.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/09\/associate-function-library-to-qtp-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"4 Different Ways to Associate Function Libraries to your QTP Scripts"}]},{"@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\/263","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=263"}],"version-history":[{"count":24,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":282,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/263\/revisions\/282"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}