How to use automation object to load the library files in QTP. I tried to use this stmt" set App = createobject("Quicktest.Application")App.Test.Settings.Resources.Libraries.Add ("F:QTPrepository.vbs"),1 ".could u pls help how to add it by script itself? what is executefile concept? is it workaround to my question?

Questions by kittucivil   answers by kittucivil

Showing Answers 1 - 40 of 40 Answers

Konka Ravi Krishna

  • Mar 27th, 2006
 

This code will add the library files:

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable

Dim qtLibraries 'As QuickTest.TestLibraries ' Declare a test's libraries collection variable

Dim lngPosition

' Open QuickTest

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object

qtApp.Launch ' Launch QuickTest

qtApp.Visible = True ' Set QuickTest to be visible

' Open a test and get its libraries collection

qtApp.Open "C:\Test1", False, False ' Open a test

Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries collection object

' Add Utilities.vbs if it's not in the collection

If qtLibraries.Find("C:\sai1.vbs") = -1 Then ' If the library cannot be found in the collection

qtLibraries.Add "C:\sai1.vbs", 1 ' Add the library to the collection

End If

Venkat

  • Apr 5th, 2006
 

Hi,

when ever you want to add library files(.VBS) files to the script, use th following function.

Executfile(" Path of file ")

the above fucntion load the VBS file to your script and you can use the fucntions in VBS file using

Call Functionname(arg list)

Venkat

  Was this answer useful?  Yes

Ram

  • Dec 21st, 2006
 

Hi

I have question

Can we add the library file while running the test

regards

Ram

  Was this answer useful?  Yes

lokesh

  • Jan 3rd, 2007
 

Hi Ravi Krishna,

   Your answer is very good.But I've a doubt in it.U declared a variable as IngPosition but never used.Can u explain in detail what is that IngPosition

Thank u

Lokesh

  Was this answer useful?  Yes

Jitesh Sojitra

  • Jan 31st, 2007
 

I am also getting same error like
There was an error while running
"This operation cannot be performed during a run session."
Pls help me if you could run it successfully.

  Was this answer useful?  Yes

Sirisha

  • Feb 23rd, 2007
 

Easy Way to Load the Library Files is in  Resource Settings Tab of Test Setting File box .When you load these , it will take all the necessary functions from the library file while running the Script

 Go to File ->Test Settings which Opens Test Settings Dialog box, Click on Resource Tab then add the library files in the associated Librares by using the Browse Button.

  Was this answer useful?  Yes

manish

  • Mar 13th, 2007
 

Hi ,
This is Gre8 Script thank
I have changed it as per my requirement to add file to same Script

Dim qtApp
Dim qtLibraries

Set qtApp = CreateObject("QuickTest.Application")
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries collection object

If qtLibraries.Find("C:sai1.vbs") = -1 Then ' If the library cannot be found in the collection
ExecuteFile  "C:sai1.vbs"
End If

Call test1()

Function In File Sai1.vbs
Function test1()
MsgBox "Hi Manish"
End Function



  Was this answer useful?  Yes

shruti

  • Apr 5th, 2007
 

Hi,

I have recorded one script. Now i want to use the function Executefile.
Inorder to use this function is it necessary to load librabry files. If yes then can you please tell me how to make this library file.

  Was this answer useful?  Yes

debleena23

  • Apr 17th, 2007
 

Hi
The simplest way out is ......

Store the Library file along with the entire path in a variable.
EG: sPath = "D:/Files/Functions.vbs"

Then just write ......

Executfile (sPath)

OR
Just write ...........
Executfile ("D:/Files/Functions.vbs")

Below this call which ever function you want to call from the library file
Call FunctName(argument list)

  Was this answer useful?  Yes

SUSHMA

  • Jul 5th, 2007
 

We can load the library files  into the QTP script by using LoadFromFile method.

  Was this answer useful?  Yes

Soumya

  • Jul 11th, 2007
 

No You need not to add to the libraries . Direct path can be given.

  Was this answer useful?  Yes

I can tell you where the exact problem is, when you try to add the library files in main script itself it will through error, b'cos in the runtime only we are adding library files and using those library files, so they are not compiled and we are direlctly using those library files without compling them that is the reason why we get error

??????? For that we need to use a startup script that will add all these library files, or we can use the Execurefile method to directly use them in script

Raghuram Gupta
raghu_13_sa @ yahoo . com
9866379523

  Was this answer useful?  Yes

rajesh

  • Sep 5th, 2007
 

In the initialize file (.vbs) use App.Folders.Add(Libr_Path)

In the main script in QTP use lib_path = Pathfinder.Locate("Library.vbs")

This can be useful for you to load library file to current test.

Note: initialize file should be created in "scripts" folder.

  Was this answer useful?  Yes

chanduU

  • Mar 20th, 2008
 

When you load the library files in QTP and run it it will show you one error msg..
so done something else ...tyr this
set qtp=createobject("QuickTest.Application")
qtp.launch
qtp.visible=true
qtp.open "C:AutomationMain_Script"

set qttst=qtp.test
set qtplbs=qtp.Test.Settings.Resources.Libraries 
  qtplbs.removeall
  
  qtplbs.add"C:Automationlibraryfunctions.vbs"
  'qtplbs.setasdefault
               
  qttst.run
               'qtTest.Settings.Run.OnError = "NextStep"

                 'qtTest.Settings.Run.StartIteration = 1
set qtp=nothing
set qtplbs=nothing
set qttst=nothing

just save it as a vbs file and just click on the VBS file..
it will open QTP..load the VBS files and run ur script..

thanks
chandu

  Was this answer useful?  Yes

Here is a Step by step process to load the library at runtime to a test and call its functions:

1. Create a test in QTP and in expert view call the function which is there in .vbs file
2. create a .vbs file with the same function name which is mentioned in QTP test

keep in mind that qtp should be closed and we are using a vbs file to run a QTP test using its object model

3. Now create a vbs file which would load a vbs file to the test at runtime, run the qtp test and that test inturn would call the function which is there in library file.

Here is the code to load library file at runtime to a test and run the test. I am using Chandu's code here.

---------------------------------------  sample code --------------------------------
set qtp=createobject("QuickTest.Application")
qtp.launch
qtp.open("C:QTPScriptsqtptest")
wscript.sleep(10000)
set qttst=qtp.test
set qtplbs=qtp.Test.Settings.Resources.Libraries
qtplbs.removeall
qtplbs.add ("C:new.vbs")
qttst.run
set qtp=nothing
set qtplbs=nothing
set qttst=nothing
------------------------------------------------------------------------------------------------

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions