{"id":12184,"date":"2013-09-22T16:15:20","date_gmt":"2013-09-22T16:15:20","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=3195"},"modified":"2022-08-07T06:04:06","modified_gmt":"2022-08-07T06:04:06","slug":"download-test-cases-from-qc","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2013\/09\/download-test-cases-from-qc\/","title":{"rendered":"HP Quality Center – Excel Macro to Import Test Cases from QC"},"content":{"rendered":"
In this article, I am going to share the VBA code to download the test cases from QC in Excel Sheet. Here in this example, I will fetch very few important fields from QC but if you want more fields to be fetched then it can be easily done. I have categorized this VBA code into two main categories:<\/p>\n
Copy and paste the below code into your excel VBA module. Make the necessary changes like your QC ID, Password, URL, path, etc. and enjoy running the code \ud83d\ude42<\/p>\n
\r\nFunction EmportTestCases()\r\n On Error Resume Next\r\n Dim QCConnection\r\n Dim sUserName, sPassword\r\n Dim sDomain, sProject\r\n Dim TstFactory, TestList\r\n Dim TestCase\r\n'Create QC Connection Object to connect to QC\r\n Set QCConnection = CreateObject(\"TDApiOle80.TDConnection\")\r\n sUserName = \"your user id\"\r\n sPassword = \"your password\"\r\n QCConnection.InitConnectionEx \"your QC URL\/qcbin\"\r\n'Authenticate your user ID and Password\r\n QCConnection.Login sUserName, sPassword\r\n'Quit if QC Authentication fails\r\n If (QCConnection.LoggedIn <> True) Then\r\n MsgBox \"QC User Authentication Failed\"\r\n End\r\n End If\r\n sDomain = \"your domain name\"\r\n sProject = \"your project name\"\r\n'Login to your Domain and Project\r\n QCConnection.Connect sDomain, sProject\r\n'Quit if login fails to specified Domain and Project\r\n If (QCConnection.AuthenticationToken = \"\") Then\r\n MsgBox \"QC Project Failed to Connect to \" & sProject\r\n QCConnection.Disconnect\r\n End\r\n End If\r\n'Now successful connection is made to QC\r\n'Get the test factory\r\n Set TstFactory = QCConnection.TestFactory\r\n' Your QC Project Path for which you want to download\r\n' the test cases.\r\n fpath = \"your project folder\" \r\n Set myfilter = TstFactory.Filter()\r\n myfilter.Filter(\"TS_SUBJECT\") =\"^\" & fpath & \"^\"\r\n'Get a list of all test cases for your specified path\r\n Set TestList = myfilter.NewList()\r\n'Format the header before downloading the test cases\r\n With ActiveSheet\r\n .Range(\"B5\").Select\r\n With .Range(\"B4:F4\")\r\n .Font.Name = \"Arial\"\r\n .Font.FontStyle = \"Bold\"\r\n .Font.Size = 10\r\n .Font.Bold = True\r\n .HorizontalAlignment = xlCenter\r\n .VerticalAlignment = xlCenter\r\n .Interior.ColorIndex = 15\r\n End With\r\n .Cells(4, 2) = \"Subject (Folder Name)\"\r\n .Cells(4, 3) = \"Test Name (Manual Test Plan Name)\"\r\n .Cells(4, 4) = \"Description\"\r\n .Cells(4, 5) = \"Status\"\r\n Dim Row\r\n Row = 5 '- set the data row from 5\r\n'loop through all the test cases.\r\n For Each TestCase In TestList\r\n .Cells(Row, 2).Value = TestCase.Field(\"TS_SUBJECT\").Path\r\n .Cells(Row, 3).Value = TestCase.Field(\"TS_NAME\")\r\n'QC stores description in html format. So before storing it\r\n'in to excel, StripHTML() will remove all HTML tags and put\r\n'texts only. Also new line tag
is replaced with new line\r\n'character chr(10) in excel so that all the new line texts appears properly\r\n .Cells(Row, 4).Value = StripHTML(Replace(TestCase.Field(\"TS_DESCRIPTION\"), _\r\n \"<br>\", Chr(10)))\r\n .Cells(Row, 5).Value = TestCase.Field(\"TS_EXEC_STATUS\")\r\n Row = Row + 1\r\n Next ' Next test case\r\n End With\r\n 'Release the object\r\n Set DesignStepFactory = Nothing\r\n Set DesignStep = Nothing\r\n Set DesignStepList = Nothing\r\n Set TstFactory = Nothing\r\n Set TestList = Nothing\r\n Set TestCase = Nothing\r\n QCConnection.Disconnect\r\n MsgBox (\"All Test cases are downloaded without Test Steps\")\r\nEnd Function\r\n\r\nFunction StripHTML(sInput As String) As String\r\n Dim RegEx As Object\r\n Set RegEx = CreateObject(\"vbscript.regexp\")\r\n Dim sInput As String\r\n Dim sOut As String\r\n sInput = cell.Text\r\n With RegEx\r\n .Global = True\r\n .IgnoreCase = True\r\n .MultiLine = True\r\n .Pattern = \"<[^>]+>\" 'Regular Expression for HTML Tags.\r\n End With\r\n sOut = RegEx.Replace(sInput, \"\")\r\n StripHTML = sOut\r\n Set RegEx = Nothing\r\nEnd Function\r\n<\/code><\/pre>\n