Micro Focus QTP (UFT) Forums

Full Version: Error in Calling function Libraries
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Using QTP 9.2 Windows 7
Im learning how to create and use functions libraries in QTP.
I have created log in and log out functions for my application

Code:
Function login()
Browser("Login Form").Page("Login Form").WebList("Login1$Company").Select "095 - TEXPO – 095"
Browser("Login Form").Page("Login Form").WebEdit("Login1$Password").SetSecure "4f45d60061419cac90ecb62f"
Browser("Login Form").Page("Login Form").WebEdit("Login1$UserName").Set "madeeha"
Browser("Login Form").Page("Login Form").Image("Login1$LoginButton").Click 22,13
End Function

Code:
Function logout()
Browser("Softronic - HCMS").Page("Softronic - HCMS_2").Sync
Browser("Softronic - HCMS").Close
Browser("Login Form").Page("Softronic Applications").Link("Logout").Click
Browser("Login Form").Page("Login Form").Sync
Browser("Login Form").Close
End Function
When im calling the function in any other test it generates an error that Login object not found in the object repository.
I know these objects are not present in the OR, how can I used these Functions in my test?
Need guidance for it.
Thanks.
you can get solutions on any of the below

1. Code these function as reusable actions and call actions
2. use Descriptive programming
3. add the objects in to Shared Repository and store externally say "C:\Repository.tsr". and add the below codes at the start of the functions

Code:
Dim qtApp
Set qtApp = CreateObject("QuickTest.Application")
curact=Environment.Value("ActionName")
qtApp.Test.Actions(curact).ObjectRepositories.Add "C:\Repository.tsr"
Adding the above code generating an error in Function library:
Error in library file. Your function library may not be valid.
i think code sensitive to QTP 9.X version. conclude you are using later.
instead of old codes, add the object repository code at the start of the function like

Code:
RepositoriesCollection.Add "C:\sh.tsr"

before that ensure all objects used in functions are added and stored in the shared object repository. (like C:\sh.tsr)

and you can try other ways also.
I guess you have not associated the function library with the test
I have associate function library with test