Relative path - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP) +--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners) +--- Thread: Relative path (/Thread-Relative-path) |
Relative path - sams001 - 12-04-2012 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 RE: Relative path - elango87 - 12-06-2012 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 RE: Relative path - sams001 - 12-06-2012 THank you so much Elango.. It helped me a lot --Sams RE: Relative path - supputuri - 12-11-2012 Relative path is always with respect to the folders so don't forget to give the folder name before the file name. RE: Relative path - sams001 - 12-12-2012 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 RE: Relative path - elango87 - 12-13-2012 I am not sure what you are trying to do... Can you give me an example. Thanks, Elango RE: Relative path - sams001 - 12-13-2012 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 RE: Relative path - elango87 - 12-14-2012 Use the code below, Code: Dim GetAUTRootFolder, RelPath 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 |