Have you ever wondered about how to effortlessly transfer your QTP scripts from your computer to one of colleagues or may be from a drive of your computer to another ? Well, relative path is the answer. As promised in my previous post on optimizing QTP scripts, we “ll discuss what is a relative path and the benefits of using them in your QTP scripts.
There can be two types of path in your file System, absolute and relative.
A full path or absolute path is a path that points to the same location on one file system regardless of the working directory.
Example of a full path:
C:\Program Files\Mercury Interactive\QuickTest Professional\Tests
while
A relative path is a path relative to the current working directory, so the full absolute path may not need to be given.
Example of a relative path: Say your current working directory is QuickTest Professional as shown above so the relative path for the folder Mercury Interactive which is one level up would be ..\..\Mercury Interactive similarly folder which is on same level can be referenced by ..\Some Folder
Now that the definition is clear, I think you can guess the benefits of using relative paths in QTP.
Suppose you have a test where you need to call a reusable action which was created in a different test. The normal steps we follow would be: Insert > Call to existing Action

and then we select the reusable action from the drop down list.

The major drawback with this approach is that if you need to shift your files to some other computer where the similar path is not maintained you will have to do a lot of rework and map the reusable actions all again.
To get over this problem, we can use relative path. In the Select Action box as shown below instead of selecting the test just type in ..\Test1. If there is a test named “Test1″ in the current directory, action drop down box would automatically populate the list of reusable actions under it.

References: Wiki: Path
Have you downloaded the FREE Optimizing QTP eBook yet? Get It Now!
If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.




36 comments ↓
Nice article Ankur.
But one point is not clear for me.
from your post “instead of selecting the test just type in ..\Test1. If there is a test named “Test1″ in the current directory”
1) here what does “current directory” refers to?
2) Do you mean instead of browing for the whole path “C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\Test1″ we can just give “..Test1″ in Select action box?
3) I am not getting how can we give relative path for reusable test located at “C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\Test1″
Sorry if understood in other way…please explain I want to use this feature in my tests.
Thanks,
Akhila
1) In example it is “Quick Test Professional” as mentioned
2) Yes, if you are in the current directory
3) Just try on your machine as I have written and you will understand.
Hi Ankur,
I am new to QTP and I am trying to script a client-server Java application.
I am not able to use .Sync function in the script and I have wait function. Can you please let me know what could be used instead of wait?
-Thanks
Shilpa
Ankur,
I am new to QTP. I am trying to run scripts in batch mode using Test Batch Runner. When I run the .mtb file after the first script runs the application closes. Is there a way to fix this?
Thanks,
Ted
Plz send me Link for trial version for QTP , i tried but failed in many links
Thanks
rahul
Hi Ankur,
I have created a reusbale action from scratch. I have taken that reusable action modify it and created another reusable action with different action name as well as test name.I put both the reusable actions on the same directory.
From another test (with in the same directory) I want to call those actions(By call to existing actions) through relative paths. First Action(Which I created from scratch)is added and also local sheets is added. But in case of second action(which i have created from that first action)it is not added and also data sheet is not added. It is showing that First action is again added.
This problem only happens when I want to call those actions together. If I call only second action then this problem not happening.
Can you please tell me why this thing happening? Is Second action use some ids or links of first action? What changes i have to made in second action so that in can called with the first action also.
Thanks,
Suman
Thank you Mr Ankur
i am learning manythings.i want to know the realtime scenarious for differnt faltforms.and how will you handle the posted questions in your project
thanks®ards
sam
After running QTP current directory is set to C:\Program Files\HP\QuickTest Professional\bin. How can I locate test script directory? I mean folder where for ex. Default.xls is stored.
Thanks for answer. Standa
my query is suppose i have some function defined is some other qtp script and i want to use/include these functions in the current then how to we do? i donot want to use functions so that i donot need to write the functions again in my script so how do i import it in the current scrip and use it as an how i want??
hi ankur
hw r u
Hi
I am new to QTP.
I am Usig QTP with window based application. but i am getting many problems. QTP does not recognize the objects like text fields, imgaes, edit boxes….etc for window based application.
I have choosen the add-ins as a vB.
Please solve my problem.
After typing ..\Test1. Test1 Reusable Action is Exists but Action drop down box is getting disabled.Tel me the solution please.
Test1 Reusable Action Exists means its there in my directory but still action drop down box is not automatically getting populated with list of reusable actions under it.Its getting disabled.
How to count total number of rows which is not present in one page.(For ex. in one page only 10 rows can display and by clicking on next only other 10 rows is displaying but suppose that table contains 500row and i want to get that total 500 row count.)
Hi Ankur,
I am using relative path in my project for the shared object repositories. but i am facing a problem, when ever i reopen my project in which i have used relative path for OR i get messages in resource missing panel saying the particular OR file is missing. But all the messages are gone when i just open the Associate Repository dialog and close it. There is no problem in the script execution. I don’t know why the Messages are coming when the OR files are present in the project folder.
Thanks in advance….
Girish.
Hi everyone!
Is it possible to parametrize image field.Here i m using file upload control to upload image,so i want to upload 10 different images..so how can we acheive that with QTP parametrization technique?
Thanks in advance,
Cheers!
Hi Ankur,
I am beginer to QTP and trying to look a job in QTP.
Sir, Is it possible for u to teach me online and what would be the fee and how many days it take.
Thanks, vuru
Hi Ankur,
I am very thanks full to you, I learnt many things in WMI 4m u.
And u clarified many of my doubts but still i hav some major doubts regarding Whole web application test by using QTP. Is there any simple logic for that??
Thnks&Regards,
Suma.K
Ankur,
Does relative path also work for actions stored in QC?
Thanks,
Manish
can i have the code for this.
Hi Ankur,
Can you please give me link for QTP trial version.
I tried the link that you have provided for demo version for QTP beginners but it’s not working.
please let me know it ASAP.
Thanks & Regards,
Steena Almeida
Hi,
I used relative path for Reusable Action and Datatable. When I open the script from QC, the relative path for Datatable is not working fine. The Datatable is blank, not reflected in Test script. Please clarify it.
Hi Ankur,
I came to know that we can overcome the problem with absolute path using environment variable, which returns the path where QTP is installed.
Pls let me know how to use an environment variable in this scenario?
Hi,
I know the concept of Relative Path but not 100%. From my perspective we can go for environment variable..
we do have a built-in environment variable called “TestDir”.
This holds the path of your Test which is currently loaded in your QTP. using this we can get the path or append what ever path you want,
Hi,
I am new to QTP.I would like to upload photos in QTP.
I recorded the script with photo upload.But the QTP has not recorded the photo upload events.I have added the following Add ins
ActiveX
VisualBasic
Web
Please help me in this regard.
Hi ankur
can we use same pattern of relative path to access files
for example I need to access Testdata.xlsx file
for which can i create
set objworkboos = objexcel.workbooks.open(“..\..\tesdata.xlsx”)
kalluri
how do i traverse backwork in directory using QTP. I have used Environment(“TestDir”) to get the dirctory but if i use “..\\..\\” , it should work , but seems not. Can some one give me correct code
thanks
Set fso = createobject(“Scripting.FileSystemObject”)
print fso.GetParentFolderName(Environment.Value(“TestDir”)) ‘ this will give you the name of the parent folder
Use the above lines of code and see if it solves your problem
Hi Ankur,
Iam trying to run the QTP Scripts created on another machine on my machine. The scripts and the shared object repository created on one machine was copied as is as a folder on to the network drive. I copied the same on to my machine and created the the same folder structure that was on the other machine.I tried to run the scripts and I have manually loaded the Shared repository. The script failed to recognise the objects on the application.What is that I need to do to make the scripts work.Please advice.
Hi,
Can anyone tell me limitations of QTP
This relative path thing doesn’t work if I am connected to QC. All my files and resources are located in Quality Center, I can’t then specifiy an Action that is relative because it won’t work for finding the action in Quality Center.
When searching for actions in the Action Window there is either:
or
[Quality Center]…
Do you have a solution for using relative paths when QTP is connected ie sync’d with QC ??
Hi Ankur,
can u provide me some database related scripts..
Thanks
Sridev
Hi
Can the relative paths can be used when my qtp scripts are stored in QC?
Hi,
I want to get the object properties Index, creationTme by using script?
sir,
I am who to count the no of actions ,send the script in by using object repository.
Hello Ankur,
Well nice articles ,But can you explain more eloborately for relative and absolute path .
Thank you
Leave a Comment