Relative Paths in QC - QTP

We can't directly use relative paths when working with QC for example if we use a path "[QualityCenter] ..CommonCommon.vbs" it is considered invalid. QTP tries to find the each required resource in all the folders specified in the tools folders options. Though we cannot specify a relative path in the folders options but we can do it for th#resource itself. Which means that we can specify the path of the VBS library for example - ".^CommonCommon.vb\$,' while the QC path mentioned in the Folder options would be the absolute path.

Resolving Relative Paths

Relative paths are based on "." (Current folder) and ".."(Parent folder). So a relative path like "C: All TestTestsTestl..Common.Common.vbs" will finally resolve as "C:All TestTestsCommon Common.vbs" using the following rules:

• Each "." is replaced by a "" as "." means the current folder only.
• Each ".." causes deletion of all text before it until a "" character is encountered. In our case the " TestlVA" path portion is replaced by a single "" .

We can implement the conversion rules given above by using the following function:

'Function to resolve the relative paths to absolute
paths Public Function ResolveRelativePath(ByValsPath,ByValsCurPath)
ResolveRelativePath = sPath
'Replace [QualityCeneterj from the path
sPath = Trim(Replace(sPath, "IQualityCerrter]","",1,-1,vbTextCompare))
'In case the first character is a to .the we need to start
'with current path
If Left(sPath.l) ="" or l*eft(sPath,l) ="," Then
sPath = sCurPath&"" &sPath
End If
'\ in paths have no meaning so replace them with V sPath = Replace(sPath, "\","")
Do
'Replace all "." with "" sPath = Replace(sPath, ".","")
'Is there are relative parent folder in the path
iRelPath = InStr(sPath. "..") If iRelPath<> 0 Then
'Find the before the ".."
iRelPath2 = InStrRev(sPath, "", iRelPath-1)
If iRelPath2 = 0 Then
sPath = Left(sPath, iRelPath-1) & Mid(sPath, iRelPath + 3)
Else
sPath = Left(sPath, iRelPath.2-1) & Mid(sPath, iRelPath + 3)
End if
End If
'Loop untill all relative paths are resolved Loop while iRelPath<> 0
'Return the resolved path ResolveRelativePath = sPath
End Function

This function can be used as shown in the following code:

'Displays "C:TestsCommonCommon.vbs"
MsgBoxResolveRelativePath("C: TestsTestCasel.. CoMOnComon.vbs" ,*'")
QCRelativePath = "[QualityCenter] SubjectXTestCasesV.CoHHonCoaaon. vbs"
QCActualPath = "{QuaiityCenterl " &ResolveRelativePath(QCRelativePath,"")
'Displays "[QuaiityCenterl SubjectCommonCommon.vbs" MsgBoxQCActualPath