Posts: 29
Threads: 13
Joined: Oct 2012
Reputation:
0
12-04-2012, 11:14 PM
Hi,
Anyone please help me in using relative path. I need to traverse to the super parent folder of test script file and append some other path to the same. Eg: Test script file @ "C:\Tests\Automation\TestScripts\Login\", i need to get "C:\Tests\Automation\Data\Environment.xml".
I am aware that using "..\" we can navigate to the parent folder, but when i put msgbox "..\..\" & Environment("TestDir"), its giving "..\..\C:\Tests\Automation\TestScripts\Login\" instead of "C:\Tests\Automation\". anyone please help.
Thanks
Sams
Posts: 26
Threads: 1
Joined: Dec 2012
Reputation:
0
12-06-2012, 04:21 PM
Use Pathfinder.locate utility in QTP.
In your case, Pathfinder.locate(".") will give you the path of the script which is "C:\Tests\Automation\TestScripts\Login"
if you use Pathfinder.locate("..\..\"), the path would be "C:\Tests\Automation".
To append the path of the environment variable,
RelPath = Pathfinder.locate("..\..\")
Envvarpath = Relpath & "\Data\Environment.xml"
Hope this helps.
Let me know if you need more help.
Thanks,
Elango
Posts: 516
Threads: 17
Joined: Jul 2009
Reputation:
3
12-11-2012, 12:13 AM
Relative path is always with respect to the folders so don't forget to give the folder name before the file name.
Thanks,
SUpputuri
Posts: 29
Threads: 13
Joined: Oct 2012
Reputation:
0
12-12-2012, 06:19 PM
Hi Elango,
PathFinder.Locate works fine if the code is directly inside QTP test case. If i had to put the code in one of the functions of library, PathFinder will consider the caller test case (which has called the function) as reference and each test case will be having different paths, so how can we generalize the code here.. Please help. Hope u got my point.
Tanks
Sams
Posts: 26
Threads: 1
Joined: Dec 2012
Reputation:
0
12-13-2012, 05:50 PM
I am not sure what you are trying to do... Can you give me an example.
Thanks,
Elango
Posts: 29
Threads: 13
Joined: Oct 2012
Reputation:
0
12-13-2012, 09:07 PM
Hi Elango,
Please go thru the following pseudo code. Please correct me if i am going wrong anywhere.
Test script1 @ D:\Tests\Automation\<AUT>\Test Scripts\<High Level Test suite>\
Test script2 @ D:\Tests\Automation\<AUT>\Test Scripts\<High Level Test suite>\<Low Level Test Suite>
Both of them use the function library @ D:\Tests\Automation\<AUT>\Function Libraries\AUTFunctions.qfl
Function GetAUTRootFolder()
GetAUTRootFolder= PathFinder.Locate("..\..\..\")
End Function
Above will give the path D:\Tests\Automation\<AUT> when Test script1 is run, but i think it will yield to D:\Tests\Automation\<AUT>\Test Scripts\ in case of Test script2 execution which is incorrect.
Please correct me if my understanding is wrong.
Thanks
Sams