1.
I created a test in QTP with the name "twra". (E.g. for better understanding “test with reusable action"). It has just one line of code:
Msgbox "I am a reusable action"
In the Keyword View, right click on Action1 and choose Action Properties. In the Action Properties dialog box that opens, check the ‘Reusable action’ checkbox in the General tab and click OK.
2.
I created another test in QTP with the name "call twra". At present it also has just one line of code:
Msgbox "I am going to call a reusable action in a test - twra"3.
Now make sure that "call twra" test is open and go to Insert ->Call to Existing Action. Select Action window opens.
Here you have to click on “…” button or type the complete path (in ‘From test:’ dropdown) to select the test that contains the reusable action.
Now without doing anything on Select Action window, just close (Cancel) it.
4.
Now go to Tools -> Options and go to Folders tab. Click on + to add a Path. The paths that you specify here can be a full path or a relative path. The relative path is relative to the location of the test currently being edited.
In our case we will add C:\Program Files\Mercury Interactive\QuickTest Professional\Tests, because all the tests are stored in Tests folder.
After entering the path click OK.
5.
Now again go to Insert ->Call to Existing Action. Select Action window opens.
Now in the “From test:” dropdown just type the name of the test from where you want to call a reusable action (twra in our case) and it will list all of its reusable actions.
[If you enter any path (e.g. path for Function Library or path for Object Repository etc.) as relative path, then during the run session, QuickTest searches for the file in the folders listed in the Folders pane of the Options dialog box, in the order in which the folders are listed.]
Note: Use of relative path is possible anywhere in QuickTest Professional.
Above you saw just one way of doing things.
[Just understand the below text very carefully:]
We can also do the above steps like this: (Suppose “call twra” test is open)
Above in the 3rd step when Select Action window opens, since both “twra” and “Call twra” are stored under Tests, we can simply write ..\twra in the “From test:” dropdown (No need of step 4 and 5 above) in order to access its reusable actions.
This is because both the tests are located in C:\Program Files\Mercury Interactive\QuickTest Professional\Tests and we are currently in C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\call twra. Path of current test (<current test>) is always there in search list (Tools -> Options -> Folders tab),
and our current path is C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\call twra, so to find twra which is under C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\ we go one step back with ..\ and type twra. So in all we type ..\twra and it will find it.
One more way to understand:
(Still suppose we are in “call twra”)
If on your system you go to C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\ and cut the folder twra from here and paste it under C:\Program Files\Mercury Interactive\QuickTest Professional\ then in the above situation you have to go two folders back and type ..\..\ and then type twra (so in all we have to type ..\..\twra) in ‘From test:’ dropdown in Select Action window, since we are in test C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\call twra.
PathFinder.Locate
You can use a PathFinder.Locate statement in your test to retrieve the complete path that QuickTest will use for a specified relative path based on the folders specified in the Folders tab.
PathFinder is an object which lets you to find file paths.
Locate is a method of PathFinder object which returns the full file path that QuickTest uses for the specified relative path based on the folders specified in the Folders tab search list (Tools -> Options -> Folders tab).
Additionally you can add the below line in the "call twra" test to know which relative path it picked from the search list (Tools -> Options -> Folders tab).
Msgbox (PathFinder.Locate ("twra"))
See how much you have learned about QTP Relative & Absolute Path by answering these Multiple Choice Questions .
Script on How to add any path in the Search List '(Tools -> Options -> Folders tab) through a script.
Subscribe to RSS Feed to stay in touch with the upcoming exciting stuff.
Also See:
QTP SystemUtil Vs InvokeApplication
QTP Optional Step
QTP Random Variables
QTP Crypt Object