Micro Focus QTP (UFT) Forums
Extract data from test and use it in another test - 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: Extract data from test and use it in another test (/Thread-Extract-data-from-test-and-use-it-in-another-test)



Extract data from test and use it in another test - yuetling926 - 10-06-2009

Hi All,

Can I use the "output value" to output text form one test and use it in another test?

Thanks
Jody


RE: Extract data from test and use it in another test - Saket - 10-06-2009

No, you cant do this directly, you will have to put this into output parameter of one test and take it into the input parameter of another test.
or you can set the value in data table and use it.


RE: Extract data from test and use it in another test - yuetling926 - 10-06-2009

However, I am using a function to generate a string in test1 and want to use that string in test 2.
It is assumed that I don't need to remember the generated string and can ne used in test 2.

Input parameter can also achieve it?

Thanks
Jody


RE: Extract data from test and use it in another test - Saket - 10-06-2009

Yes, the returned string from your function in test1 should go in the Output parameter for test1
and use the O/P parameter of test1 as input parameter for test2.


RE: Extract data from test and use it in another test - yuetling926 - 10-06-2009

Can it really transfer to another Test file?
it seems that output values from test1 and only be used later within only test1.
it is because it stored the output value in a globalsheet.

However, when I open Test2,,the value in global files become blank. Then, how can I make it as a input parameter of test 2?

Thanks
Jody


RE: Extract data from test and use it in another test - Saket - 10-06-2009

oh sorry, my mistake. I assumed you are calling tests in an script.
this is not possible if these are two seperate scripts unless you call the scripts through a vbscript.


RE: Extract data from test and use it in another test - basanth27 - 10-06-2009

Write the output from test1 to a excel or filesystemobject. For Test2 read value from the excel data. Does this help ?


RE: Extract data from test and use it in another test - Saket - 10-06-2009

if you are using QTP AOM then you can easily do this
see if the code below gives you an idea

Code:
Set qtApp = CreateObject("QuickTest.Application")
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtApp.Launch
qtApp.Visible = True

qtResultsOpt.ResultsLocation = "D:\results"

qtApp.Open "C:\QTP\Script\Script1"

' parameters collection defined
Set pDefColl = qtApp.Test.ParameterDefinitions

Set oParams = pDefColl.GetParameters()

'added parameters Run the script
qtApp.Test.Run qtResultsOpt, True, oParams

'Extract the output Parameter
Set oParam = oParams.Item("OutputVal")

qtApp.Test.Close

qtApp.Open "C:\QTP\Script\Script2"


Set pDefColl = qtApp.Test.ParameterDefinitions

Set iParams = pDefColl.GetParameters()

Set iParam = iParams.Item("InputVal")

'add input parameter taken from earlier test
qtApp.Test.Run qtResultsOpt, True, iParam

missed to assign ouput parameter to the input parameter for second run in the code
try this -
Code:
Set qtApp = CreateObject("QuickTest.Application")
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtApp.Launch
qtApp.Visible = True

qtResultsOpt.ResultsLocation = "D:\results"

qtApp.Open "C:\QTP\Script\Script1"

' parameters collection defined
Set pDefColl = qtApp.Test.ParameterDefinitions

Set oParams = pDefColl.GetParameters()

'added parameters Run the script
qtApp.Test.Run qtResultsOpt, True, oParams

'Extract the output Parameter
Set oParam = oParams.Item("OutputVal")

qtApp.Test.Close

qtApp.Open "C:\QTP\Script\Script2"


Set pDefColl = qtApp.Test.ParameterDefinitions

Set iParams = pDefColl.GetParameters()

Set iParam = iParams.Item("InputVal")

iParam.Value = oParam.Value

'add input parameter taken from earlier test
qtApp.Test.Run qtResultsOpt, True, iParam



RE: Extract data from test and use it in another test - Tharun007 - 06-30-2011

Hey Saket,
Can you give me an example (simple one) for the output parameter of one test and take it into the input parameter of another test.?? Sad


RE: Extract data from test and use it in another test - Archens - 04-26-2012

Quick-and-dirty alternate method using Windows environment variables:

Code:
Sub SetSysEnv(strSysEnvVar,strValue)
    Set WshShell = CreateObject("WScript.Shell")
    Set WshSysEnv = WshShell.Environment("SYSTEM")
    WshSysEnv(strSysEnvVar) = strValue
    Set WshShell = Nothing
    Set WshSysEnv = Nothing
End Sub

Function GetSysEnv(strSysEnvVar)
    Set WshShell = CreateObject("WScript.Shell")
    Set WshSysEnv = WshShell.Environment("SYSTEM")
    GetSysEnv = WshSysEnv(strSysEnvVar)
    Set WshShell = Nothing
    Set WshSysEnv = Nothing
End Function

Archens