How to Add Multiple Libraries with UFT Dynamically

In my previous post here- , I have discussed, how to add library files dynamically. But that was valid for only one library file.
Refer the below code under Library Settings

dim qtlibs
'to remove all
Add a library:
If qtLibs.find("path of the lib"\abc.vbs")=-1 then
qtlibs.Add "path of the lib"\abc.vbs",1
End If
qtApp.Test.Save ' in this case you have to open the test in edit mode,readonly false
But there two ways to do that:
1. Execute File <path of the vbs/qfl file>
You have to write these lines for all library files one by one.
2. LoadFunctionLibrary <path of qfl/vbs> We can give many library files path with names separated by comma(,). I could have opted one of these two methods, but one issue compelled me to think otherwise. The issue was, there could be multiple libraries as and when project grows up. So every time,if a person going to add a new function library, Somebody needs to update the above lines in code just to load the files.That triggered the cost of maintenance during function library addition. Below is a way I have coded to handle addition of all libraries with our script dynamically using AOM way : The precondition is to have a folder called Libraries where we need to place all libraries.
Dim qtApp

Set qtApp=CreateObject("QuickTest.Application")

Set objFso=CreateObject("Scripting.FileSystemObject")
objLibPath=path of our Library folder ' Like C:\Test\Library\
Set objFolder=objFso.GetFolder(objLibPath)
Set colFiles=objFolder.Files
qtApp.Launch  ' launch QTP/UFT 

Set objLib=qtApp.Test.Settings.Resources.Libraries
For Each objFile in colFiles
If Not instr(fileName,".lck") Then ' sometimes I have seen .lck files are 
'created and not destroyed even if the QTP is closed
   if objLib.Find(objLibPath&fileName)=-1 Then
      objLib.Add objLibPath&fileName
   End If
objFile.Delete 'Delete the .lck file
End If
How to Add Multiple Libraries with UFT Dynamically How to Add Multiple Libraries with UFT Dynamically Reviewed by Animesh on May 27, 2017 Rating: 5

1 comment:

Powered by Blogger.