You are on page 1of 3

Relative and Absolute Paths in QTP

Every Test Automaton Project follows a specific framework to develop scripts. Every framework has a folder structure to maintain scripts and resources. A script can have lot of resources associated with it. We may execute our scripts in different machines. We may copy our scripts to the server for backup. In such cases we need to ensure that script doesnt fail because of path change. So how can we make portability of the scripts?

The answer is Relative Path. We can give two types of paths when associating a resource. Absolute Path: A complete path to a specific file starting from a fixed location. An absolute path always points to the specified file, regardless of the current directory. Ex: To associate D:\Demo Framework\Libraries\Global\WebControls.vbs file to script1 we can use the same path to specify Absolute Path. Relative Path: A Relative Path is relative to where that file is located. Ex: To associate D:\Demo Framework\Libraries\Global\WebControls.vbs file to script1 we can use ..\..\Libraries\Global\WebControls.vbs path to specify Relative Path. The above example explained by considering below sample framework folder structure.

How to specify Relative Path? A simple logic needs to be followed in specifying Relative Path. If you want to go forward use folder name, to go back use ..\. In the above folder structure to associate D:\Demo Framework\Libraries\Global\WebControls.vbs to Script1 which is there inD:\Demo Framework\Scripts we have used ..\..\Libraries\Global\WebControls.vbs. To understand this in simple steps Open the script1 folder D:\Demo Framework\Scripts\Script1. Now, from here how do you go to D:\Demo Framework\Libraries\Global\WebControls.vbs. Step1: Click on Back (Now youre there at D:\Demo Framework\Scripts\) Step2: Click on Back (Now youre there at D:\Demo Framework\) Step3: From here go to Libraries folder (Now youre there at D:\Demo Framework\Libraries) Step4: Go to Global folder (Now youre there at D:\Demo Framework\Libraries\Global)

As I said for going back we have to use ..\, two times we have used back, so ..\..\ should be used. To go forward we have to use folder name. Now the relative path becomes ..\..\Libraries\Global\WebControls.vbs We can use Relative Paths for Associated Object Repositories Associated Library Files External Actions Associated Recovery Scenarios Associated Recovery Scenario Function Libraries Search Folders

Set objFSO=CreateObject("Scripting.FileSystemObject") Set txtFile = objFSO.OpenTextFile("../../new.txt")----this is working fine

Get Absolute Path from Relative Path


If you use Relative Path for all the resources, the path displays something like "..\..\QtpSudhakar\Libs\Sample.vbs". Sometimes we may require to have full path to send it to results file or to know exact location of the file for debugging. In this scenario to know the full path of a resource which is associated with relative path, we have to use below script. The script will automatically return the absolute path of a resource which is specified with Relative Path.
we can convert relative path to absolute path. But we cannot set that absolute path value in resources.

Dim QTP Dim cLibs Dim LibIndex

' Get Control over QTP Set QTP=CreateObject("Quicktest.Application")

'Get All Associated Resources set cLibs=QTP.Test.Settings.Resources.Libraries

For LibIndex=1 to cLibs.Count

' Using PathFinder object locate and display the Absolute path msgbox PathFinder.Locate( cLibs.Item(LibIndex))

Next

You might also like