Forum Discussion
Some time ago I did a similair to what Hugo said parsing of TC project file to get a list of all manual tests that exist in the project. Hope you'll be able to modify the code (many thanks to SmartBear's Support for the help with it) to get the list of Keyword tests...
'-------------------------------------------------------------------------------
Function GetManualTestsCollection
Const cProcName = "GetManualTestsCollection"
Dim cProcNameMsgPrefix
cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
Const cExt = ".tcMT"
Dim Doc
Dim ManualTestCollection
Dim Nodes
Dim Node
Dim strManTCName
Dim i
Set ManualTestCollection = CreateObject("Scripting.Dictionary")
Set GetManualTestsCollection = ManualTestCollection
If ("" = BuiltIn.GetCOMServerPath("Msxml2.DOMDocument.4.0")) Then InstallMSXML
' Create COM object
Set Doc = Sys.OleObject("Msxml2.DOMDocument.4.0")
Doc.async = False
' Load data from the current project file
Call Doc.load(Project.FileName)
' Report an error, if, for instance, the markup or file structure is invalid
If (Doc.parseError.errorCode <> 0) Then
s = "Reason:" & vbTab & Doc.parseError.reason & vbCrLf & _
"Line:" & vbTab & CStr(Doc.parseError.line) & vbCrLf & _
"Pos:" & vbTab & CStr(Doc.parseError.linePos) & vbCrLf & _
"Source:" & vbTab & Doc.parseError.srcText
' Post an error to the log and exit
Call Log.Error(cProcNameMsgPrefix & "Error when parsing the project file.", _
Project.FileName & vbCrLf & s)
Set Doc = Nothing
Exit Function
End If
' Use an XPath expression to obtain the list of Manual tests nodes
' Set Nodes = Doc.selectNodes("//Node[contains(@name,"".tcmt"")]")
' Return 'name' nodes that ends on cExt value (case insensitive compare)
' Case insensitive search for the 'name' nodes that end on the cExt ('.tcMT') extension
' Based on:
' http://stackoverflow.com/questions/614797/xpath-find-a-node-that-has-a-given-attribute-whose-value-contains-a-string
' http://www.dotnetspider.com/resources/470-Doing-case-InSensitve-comparisons-using-XPa-X.aspx
' http://bytes.com/topic/xml/answers/726552-xpath-query-ends
Set Nodes = Doc.selectNodes("//Node[substring(translate(@name, ""abcdefghijklmnopqrstuvwxyz"", ""ABCDEFGHIJKLMNOPQRSTUVWXYZ""), string-length(@name) - string-length(""" & cExt & """) + 1, string-length(@name)) = translate(""" & cExt & """, ""abcdefghijklmnopqrstuvwxyz"",""ABCDEFGHIJKLMNOPQRSTUVWXYZ"")]")
' Process the nodes
For Each Node In Nodes
For i = 0 To Node.attributes.length-1
' If ("value" = Node.attributes(i).name) Then
If ("name" = Node.attributes(i).name) Then
strManTCName = Node.attributes(i).text 'e.g. ManualTests\ManualTest1\ManualTest1.tcMT
' get file name (without path and ext.)
strManTCName = Utilities.ChangeFileExt(aqFileSystem.GetFileName(strManTCName), "")
If ("" <> strManTCName) Then ManualTestCollection.Add strManTCName, Eval(strManTCName)
End If
Next
Next
Set Doc = Nothing
End Function
'-------------------------------------------------------------------------------