Micro Focus QTP (UFT) Forums
Can I use return value of Action1 in other Action2 - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Can I use return value of Action1 in other Action2 (/Thread-Can-I-use-return-value-of-Action1-in-other-Action2)



Can I use return value of Action1 in other Action2 - yugal - 12-29-2008

Hi All,
I want to use the return value of one action in to other action, please help me.

Scenario:
Action 1:- I am going to upload the details of a property/(real estate) in a, here the property id entered by the user is unique key,

Action 2:- In the Admin section of the site I want to Enable that property in the site for sale,

So I want to use the "Action 1" as re-usable action and want to return the "PropertyId" entered by User in "Action 1", So that I can use that perticular "property id" to search in the admin.

Many Thanks in advance.
Waiting for replies (URGENT!!!)

Please find the code snippet in the reply of this thread...


RE: Can I use return value of Action1 in other Action2 - yugal - 12-30-2008

Hi Ankur,
I have to do this...
' Action1 (Upload Property)
Code:
SystemUtil.Run "iexplore", "http://MyTestingSite.net"
Browser("MyTestingSite").Page("MyTestingSite").Image("MyTestingSite").Click
Browser("MyTestingSite").Page("MyTestingSite_2").Link("ESTATE AGENTS HOME").Click
Browser("MyTestingSite").Page("MyTestingSite_3").WebEdit("UcAgentLogin1$txtAgentName").Set "UserName"
Browser("MyTestingSite").Page("MyTestingSite_3").WebEdit("UcAgentLogin1$txtPassword").Set "Password"
Browser("MyTestingSite").Page("MyTestingSite_3").Image("Login").Click 34,11
Browser("MyTestingSite").Page("MyTestingSite_4").Link("add a new property").Click

Randomize()
propertyID="Property_"&int(100*rnd())

Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtPropert").Set propertyID
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtAddress").Set "test"
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtAddress_2").Set "test"
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtTownToB").Set "test"
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtCountyT").Set "test"
Browser("MyTestingSite").Page("MyTestingSite_5").WebList("UcNewPropertyToBuy1$drpRegionT").Select "London"
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtPostCod").Set "BR 123"
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtPropert_2").Set "Property Summary"
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$txtDisplay").Set "Display Address"
Browser("MyTestingSite").Page("MyTestingSite_5").WebFile("UcNewPropertyToBuy1$Upload6").Set "file://path/image.jpg"
Browser("MyTestingSite").Page("MyTestingSite_5").WebEdit("UcNewPropertyToBuy1$MainImageT").Set "Image title"
Browser("MyTestingSite").Page("MyTestingSite_5").WebCheckBox("UcNewPropertyToBuy1$ckbSubmit").Set "ON"
Browser("MyTestingSite").Page("MyTestingSite_5").Image("UcNewPropertyToBuy1$btnSaveToB").Click 68,12
Browser("MyTestingSite").Page("MyTestingSite_6").Check CheckPoint("MyTestingSite")
Browser("MyTestingSite").Page("MyTestingSite_6").Link("Return home").Click
'---------------------------------------------------------------
Here I want to use the Property id as the return value for this Action1 so that I can use it in the Action2 to find out the property, and do some task with that property.
---------------------------------------------------------------

'Action2 (Publish Property)
Code:
RunAction "Copy of UploadProperty", oneIteration

SystemUtil.Run "iexplore","http://MyTestingSite.net/admin"
Browser("MyTestingSite").Page("MyTestingSite").WebEdit("txtusername").Set "UserName"
Browser("MyTestingSite").Page("MyTestingSite").WebEdit("txtpassword").Set "Password"
Browser("MyTestingSite").Page("MyTestingSiteS").WebButton("Login").Click
Browser("MyTestingSite").Page("MyTestingSite_2").Image("properties").Click
wait (2)

Dim row,i,strProperty,lnkImg

'+++++"I want here the return value of action1 i.e. the ProprtyToBePublish"++++++
ProprtyToBePublish = ??????????????? 'return value from action1
'++++"I want here the return value of action1 i.e. the ProprtyToBePublish"++++

msgbox ProprtyToBePublish
row = Browser("MyTestingSite").Page("MyTestingSite_2").Frame("Frame").WebTable("1").GetRowWithCellText(ProprtyToBePublish)
msgbox row
set lnkImg=Browser("MyTestingSite").Page("MyTestingSite_2").Frame("Frame").WebTable("1").ChildItem(row,5,"WebElement",0)
lnkImg.Click
Browser("MyTestingSite").Page("MyTestingSite").Frame("Frame_2").WebCheckBox("chkIsPublished").Set "ON"
Browser("MyTestingSite").Page("MyTestingSite").Frame("Frame_2").Link("Save Property").Click
--------------------
Also need to know If I can optimize some qtp script here.


RE: Can I use return value of Action1 in other Action2 - nageshpv - 01-02-2009

Hi, try using it as function and get the return value from it and then use it.
Else use a global variable and assign value to it in Action 1 and then access the value from Action 2


RE: Can I use return value of Action1 in other Action2 - yugal - 01-02-2009

Hi nageshpv,

How can use the script from "action1" as a Function,
Can u please explain with an example, I have written the code above for "action1".


RE: Can I use return value of Action1 in other Action2 - nageshpv - 01-02-2009

Yugal, try with the Global variable, that will be very simple.


RE: Can I use return value of Action1 in other Action2 - sreekanth chilam - 01-02-2009

Hi All,

Inorder to use return value of Action1 in other actions like Action2,Action3....Action n in current script.

We can use the following features in QTP:
1) User defined Environment Variables (Create User defined Env. Var for return Value.....which inturn can be accessed by all other actions in Current script.)
2) Action Parameters (Output Parameters)
3) Output Values ( Output the required return value(Property Id) into RunTime Global Data Sheet present in Test Results window....which inturn can be accessed by all other actions in the current script)

Just try the above from your end & check it out.....I hope you can easily accomplish the required task.......