Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Relative path
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
THank you so much Elango.. It helped me a lot Smile

--Sams
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
Relative path is always with respect to the folders so don't forget to give the folder name before the file name.
Thanks,
SUpputuri
Reply
#5
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#6
Solved: 11 Years, 3 Months, 4 Weeks ago
I am not sure what you are trying to do... Can you give me an example.

Thanks,
Elango
Reply
#7
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#8
Solved: 11 Years, 3 Months, 4 Weeks ago
Use the code below,

Code:
Dim GetAUTRootFolder, RelPath

GetAUTRootFolder = Pathfinder.locate("..\..\..\")
'Assuming the path returned by pathfinder utility is ""D:\Tests\Automation\AUT\Test Scripts\High level suite\Low level suite\"

If Instr(GetAUTRootFolder,"Test Scripts\") Then
    RelPath = Split(GetAUTRootFolder,"Test Scripts\")
    GetAUTRootFolder = RelPath(0)
End If

Msgbox GetAUTRootFolder

In either case you have mentioned above, it will give you "D:\Tests\Automation\AUT\" as path.

Hope it helps.

Let me know in case of any questions.

Thanks,
Elango
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to get relative path by using testdir environment variable Sathyaprasad 1 1,950 11-30-2017, 02:21 AM
Last Post: supputuri
  Path of Flight reservation Window is not recorded in HP UFT 12.52 version mailtokopalverma@gmail.com 1 2,702 04-01-2016, 05:34 PM
Last Post: vinod123
  X path Identification vasavi.vasavi 1 2,997 07-29-2015, 10:44 AM
Last Post: kbhargava505
  environment variable path for qc automation2012 0 2,873 01-18-2015, 08:18 AM
Last Post: automation2012
  Change Object Repository File Path for ExternalActions MasterChief 1 4,694 11-13-2014, 06:05 PM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 1 Guest(s)