Calling a function from within another function not working in UFT

  • Questions
  • Calling a function from within another function not working in UFT
Question ID: 107801
1
0

I want to use one function library function in another function library file.

For example (leaving out actual code for brevity, I know there would be values passed, etc):

**Function LibraryA:**

Function addition()
‘do some adding
End Function

**Function LibraryB:**

Function sub()
Call addition()
End Function

Marked as spam
Posted by (Questions: 324, Answers: 9)
Asked on July 29, 2017 3:36 pm
4 views
Answers
1
Private answer

You have to be sure to be referencing both function library files in the test. There are 4 main ways to do this.

1. Go to 'File > Settings > Resources > Associate Function Library' and associate both library files
2. Use AOM Code
3. Use ExecuteFile method somewhere in the script
4. Use LoadFunctionLibrary method somewhere in the script

(examples borrowed from (http://www.automationrepository.com/2011/09/associate-function-library-to-qtp-script/)

**AOM Code:**
'Open QTP
Set objQTP = CreateObject(''QuickTest.Application'')
objQTP.Launch
objQTP.Visible = True

'Open a test and associate a function library to the test
objQTP.Open ''C:AutomationSampleTest'', False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries

'If the library is not already associated with the test case, associate it..
If objLib.Find(''C:SampleFunctionLibrary.vbs'') = -1 Then ' If library is not already added
objLib.Add ''C:SampleFunctionLibrary.vbs'', 1 ' Associate the library to the test case
End

**ExecuteFile method:**

ExecuteFile ''C:YourFunctionLibrary.vbs''

**LoadFunctionLibrary method:**

LoadFunctionLibrary ''C:YourFunctionLibrary_1.vbs'' 'Associate a single function library
LoadFunctionLibrary ''C:FuncLib_1.vbs'', ''C:FuncLib_2.vbs'' 'Associate more than 1

Marked as spam
Posted by (Questions: 16, Answers: 734)
Answered on July 29, 2017 3:42 pm
Oh I wasn't referencing one of the libraries. Thanks, this is helpful!!
( at July 29, 2017 3:43 pm)