.

What is relative path in QTP?

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

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

image

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.

image
References: Wiki: Path

Share and Enjoy
  • del.icio.us
  • Facebook
  • Twitter

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.

25 comments ↓

#1 Akhila on 07.03.08 at 21:41

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

#2 Ankur on 07.03.08 at 21:53

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.

#3 Shilpa on 07.09.08 at 10:46

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

#4 Anonymous on 07.10.08 at 05:46

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

#5 rahul on 07.15.08 at 00:24

Plz send me Link for trial version for QTP , i tried but failed in many links

Thanks
rahul

#6 Anonymous on 07.24.08 at 01:40

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

#7 Anonymous on 09.08.08 at 10:50

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&regards
sam

#8 Anonymous on 09.25.08 at 04:11

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

#9 karim on 10.06.08 at 05:54

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??

#10 nitin on 11.11.08 at 01:30

hi ankur
hw r u

#11 Nidhi on 02.03.09 at 02:49

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.

#12 priya on 02.05.09 at 21:25

After typing ..\Test1. Test1 Reusable Action is Exists but Action drop down box is getting disabled.Tel me the solution please.

#13 priya on 02.05.09 at 21:27

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.

#14 priya on 02.06.09 at 04:13

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.)

#15 Girish Patil on 03.10.09 at 02:11

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.

#16 Bibek on 03.15.09 at 21:24

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!

#17 vuru on 03.25.09 at 21:44

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

#18 Suma.K on 09.08.09 at 22:21

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

#19 Manish.S on 09.09.09 at 16:45

Ankur,

Does relative path also work for actions stored in QC?

Thanks,
Manish

#20 rahul_tester on 09.10.09 at 10:04

can i have the code for this.

#21 steena on 10.14.09 at 17:20

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

#22 sairam on 12.17.09 at 07:56

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.

#23 Pradeep on 12.22.09 at 17:47

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?

#24 Raja on 01.10.10 at 23:22

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,

#25 Vidhya on 03.02.10 at 03:31

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.

Leave a Comment