Micro Focus QTP (UFT) Forums
Creating a variable list to use throughout my scripts - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Creating a variable list to use throughout my scripts (/Thread-Creating-a-variable-list-to-use-throughout-my-scripts)

Pages: 1 2


Creating a variable list to use throughout my scripts - mv8167 - 02-10-2012

I have been trying a few different way to create and use a list of variables throught my tests and scripts. I must be doing something wrong as the variables disapear as the Library is left.

Currently, from my Test script, I call a function as below:

Code:
Public Function ImageAccessVariableList ()

Set objQTPApp  = CreateObject("QuickTest.Application")
Set objQTPLibraries = objQTPApp.Test.Settings.Resources.Libraries
If objQTPLibraries.Find("O:\QTP Tests\Objec Repository\ImageAccessVariableList.txt") <> -1 Then
    objQTPLibraries.Remove "O:\QTP Tests\Objec Repository\ImageAccessVariableList.txt"
    Reporter.ReportEvent micFail, "Image Access Variable List"& DataTable.GlobalSheet.GetCurrentRow, "The 'ImageAccessVariableList.txt' file was Not found.")
    ExitTestIteration
End If

End Function
What should i change?


RE: Creating a variable list to use throughout my scripts - mv8167 - 02-10-2012

I tried the following, also with no luck.
(can i even set my variables from a Function call?

Code:
Public Function ImageAccessVariableList ()

'for "O:\QTP Tests\Objec Repository\ImageAccessVariableList.vbs"

Set objQTPApp  = CreateObject("QuickTest.Application")
objQTPApp.Launch
objQTPApp.Visible = True
Set objQTPLibraries = objQTPApp.Test.Settings.Resources.Libraries
'objQTPLibraries.RemoveAll

VariableList = "O:\QTP Tests\Objec Repository\ImageAccessVariableList.txt"

If objQTPLibraries.Find(VariableList) <> -1 Then
    objQTPLibraries.RemoveAll
    Reporter.ReportEvent micFail, "Variable List", "The ImageAccessVariableList.txt file was Not found."
    ExitTestIteration
End If

objQTPLibraries.Add (VariableList)
'objQTPLibraries.Add "D:\test2.vbs"

Reporter.ReportEvent micPass, "Variable List", "The ImageAccessVariableList.txt file was found."

Set objQTPApp = Nothing

End Function



RE: Creating a variable list to use throughout my scripts - Rodrigo Carvalho - 02-11-2012

Not sure if i undestand the issue you're facing.. but, if you want to access variables stored externally to the test you can use a librarie (qfl) and declare the variables you need to use as public and associate the lib to the test, example:

'CONSTANTS FILE

'Creation Date: 07/02/2012
'Description: It Contains the path where the data source is located
Public Const DATA_SOURCE_PATH = "C:\Automation\DataSource\DataSource.xls"
Public Const IMPORT_DATA_SOURCE = True

'<<<<<<<<<<<< DATA MIGRATION >>>>>>>>>>>>>>>>
Code:
Public Const DATA_MIGRATION_FILE_PATH = "C:\Automatizacion\PIB\DataMigration\"
Public Const TAB_BALANCE = "hubpib.Inquire is missing"
    Public Const TAB_BALANCE_ACCOUNT_SUMMARY = "hubpib.Inquire is missing"
    Public Const TAB_BALANCE_MY_TRANSFERS_OTHER_BANKS = "My transfers to other banks"
    Public Const TAB_BALANCE_SPEI_OPERATION = "SPEI Operations"



RE: Creating a variable list to use throughout my scripts - rajpes - 02-11-2012

Code:
'*HAPPY B'DAY LORENA*
VariableList = "O:\QTP Tests\Objec Repository\ImageAccessVariableList.txt"
Set objQTPApp = CreateObject("QuickTest.Application")
objQTPApp.Launch
objQTPApp.Visible = True
Set objQTPLibraries = objQTPApp.Test.Settings.Resources.Libraries
If objQTPLibraries.Find(VariableList) <> -1 Then
objQTPLibraries.RemoveAll
End if
objQTPLibraries.Add (VariableList)
Reporter.ReportEvent micPass, "Variable List", "The ImageAccessVariableList.txt is freshly attached"
Set objQTPApp = Nothing



RE: Creating a variable list to use throughout my scripts - mv8167 - 02-13-2012

Thx guys for your help. I will try both ideas.

Where do I place the code? in a function library?

Rajpes, thx for the B-Day wish. How did you know.? ;-)


RE: Creating a variable list to use throughout my scripts - rajpes - 02-13-2012

somehow i came to know Smile

You are creating instance of qtp app, so you cant put that in a function library.


RE: Creating a variable list to use throughout my scripts - mv8167 - 02-13-2012

I added the code to a function library, but when i return to the Test script, the values in my txt file disapear.

objQTPLibraries.Add (VariableList) -- This code gives me a Run Error of "This operation cannot be preformed durring a run session."


RE: Creating a variable list to use throughout my scripts - mv8167 - 02-14-2012

I went to Setup -> Resources sand added my vbs file

and, ,Itried:

Code:
Public Function ImageAccessVariableList ()
ExecuteFile  "O:\QTP Tests\QTPInputData\ImageAccessVariableList.vbs"
End function

But none of my variables get loaded into my QTP variable list.

thoughts?


RE: Creating a variable list to use throughout my scripts - mv8167 - 02-28-2012

Rajpes,

Sorry, i just learned your meaning of "instance" of QTP.

How do I then run this instance of QTP? I was thinking of just adding my variable list to my test via File -> Settings -> Resources -> [+]

but from what I understand, I must start QTP using the code provided before the test runs?

If so, then it is not possible to load a variable list at the start of a test after QTP has been running?

thx for your advise.


RE: Creating a variable list to use throughout my scripts - inborntester - 02-28-2012

this should work. what do you meant by QTP variable list? can you share ImageAccessVariableList.vbs file.