<\/a>Pic 1-HP QC - Mapping Test Cases in Test Lab<\/p><\/div>\n
Create Folder Structure in Test Lab and Pull test Cases from Test Plan<\/h2>\n In this article, you are going to learn how to create folder structure in the Test lab and Mapping or pull test cases from Test Plan to Test Lab. \nIn order to do so, copy and paste the below code into any of the modules in your VBA code and follow the comments which are written within the code to understand.<\/p>\n
Below code will make exactly the same folder structure as Test Plan in the Test lab and It will also map corresponding test cases in the test lab from Test Plan.<\/p>\n
\r\nSub Pull_Test_Cases_in_Lab()\r\nOn Error Resume Next\r\n\r\nDim tdConnection\r\nDim qcUser, qcPassword\r\nDim qcDomain, qcProject\r\nDim qcURL\r\n\r\nDim myFolder As String\r\nDim treeMgr As Variant\r\nDim myTestFact As Variant\r\nDim myTestFilter As Variant\r\nDim myTestList As Variant\r\n\r\n'Provide all details\r\n qcUser = \"\"\r\n qcDomain = \"\"\r\n qcProject = \"\"\r\n qcURL = \"\"\r\n \r\n'Create QC connection object\r\nSet tdConnection = CreateObject(\"TDApiOle80.TDConnection\")\r\n'Initialise the Quality center connection\r\n tdConnection.InitConnectionEx qcURL\r\n 'Authenticate username and password\r\ntdConnection.Login qcUser, qcPassword\r\n'login to the domain and project\r\n tdConnection.Connect qcDomain, qcProject\r\n Set treeMgr = tdConnection.treemanager\r\n Set myTestFact = tdConnection.TestFactory\r\n Set myTestFilter = myTestFact.Filter\r\n \r\n ' Apply filter on the last known node\r\n ' Suppose you want to map all the test cases\r\n ' of your Project Folder XYZ then provide\r\n ' the complete path till XYZ\r\n ' For example: "^\Subject\XYZ\^"\r\nmyFolder = "Subject\Test Project 1"\r\n\r\n 'Get the complete test list in the main folder\r\n Set myTestList = myTestFact.newList(myTestFilter.Text)\r\n myTestFilter.Filter("TS_SUBJECT") = "^\" & myFolder & "^"\r\n 'Exit if no test cases found in the above folder\r\n If myTestList.Count = 0 Then\r\n MsgBox \"Zero Test Case Found \"\r\n Exit Sub\r\n End If\r\n ' get all the tets cases available in the\r\n ' above main folder\r\n tcCount = myTestList.Count\r\n ' traverse through each test cases\r\n ' in testList array you got\r\n For Each tc In myTestList\r\n ' Get the Subject Folder Node\r\n Set myTCNode = tc.Field(\"TS_Subject \")\r\n ' Get Complete path of test case without Test Name\r\n myPath = myTCNode.path\r\n 'Create Folder stucture and pull the\r\n ' test cases in to test set in test lab\r\n ' from test plan\r\n map_TestCase myPath, tc\r\n Next\r\n \r\n Set myTestList = Nothing\r\n Set myTestFilter = Nothing\r\n Set myTestFact = Nothing\r\nEnd Sub\r\n\r\n\r\nSub map_TestCase(myPath, myTC)\r\n\r\n Dim tcMgr As Variant\r\n Dim myRoot As Variant\r\n Dim newTSTest As Variant\r\n Dim TSFact As Variant\r\n Dim TSFilter As Variant\r\n\r\n On Error Resume Next\r\n \r\n Set tcMgr = tdConnection.TestSetTreeManager\r\n\r\n ' Split path for loop\r\n subjectArray = Split(myPath, \"\\\")\r\n ' in Test Plan folder structure starts with Subject\r\n ' while in Test Lab it is \"Root \". So we need to change\r\n ' the path\r\n NewPath = \"Root \"\r\n OldPath = \"\"\r\n\r\n For iFolder = 1 To UBound(subjectArray)\r\n 'Assign old to new path\r\n OldPath = NewPath\r\n\r\n 'get current folder\r\n CurrentSubName = subjectArray(iFolder)\r\n 'build new path\r\n NewPath = Trim(NewPath) & \"\\\" & CurrentSubName\r\n 'search Folder\r\n Set newNode = tcMgr.NodeByPath(NewPath)\r\n\r\n 'create folder if it does not exist\r\n If newNode Is Nothing Then\r\n Set tcMgr = Nothing\r\n Set tcMgr = tdConnection.TestSetTreeManager\r\n\r\n If iFolder = 1 Then\r\n Set myRoot = tcMgr.Root\r\n Else\r\n Set myRoot = tcMgr.NodeByPath(OldPath)\r\n End If ' iFolder'\r\n\r\n Set newNode = myRoot.AddNode(CurrentSubName)\r\n newNode.Post\r\n End If 'new Node\r\n\r\n ' if the current folder is the last folder of the array\r\n ' then create the testset\r\n\r\n If iFolder = UBound(subjectArray) Then\r\n\r\n Set TSFact = newNode.TestSetFactory\r\n Set TSFilter = TSFact.Filter\r\n TSFilter.Filter(\"CY_FOLDER_ID \") = newNode.Nodeid\r\n TSFilter.Filter(\"CY_CYCLE \") = CurrentSubName\r\n Set TSList = TSFact.newList(TSFilter.Text)\r\n\r\n 'If no testset found in test plan then TestSet folder will\r\n 'not be created. If you want to do so uncomment the below\r\n 'if else conditions\r\n \r\n 'If TSList.Count = 0 Then\r\n 'Set TestSet1 = TSFact.AddItem(Null)\r\n 'TestSet1.Name = CurrentSubName\r\n 'TestSet1.Status = \"Open \"\r\n 'TestSet1.Post\r\n 'Else\r\n Set TestSet1 = TSList.Item(1)\r\n 'End If\r\n\r\n Set TSTestFact = TestSet1.TSTestFactory\r\n Set TSTestList = TSTestFact.newList(\"\")\r\n 'Initilize the variable to check if any Test case found\r\n foundTCs = 0\r\n\r\n If TSTestList.Count > 0 Then\r\n\r\n For Each myTSTest In TSTestList\r\n\r\n If myTSTest.TestID = Trim(CurrentTest.ID & \"\") Then\r\n foundTCs = 1\r\n End If\r\n\r\n Next\r\n\r\n End If\r\n\r\n If foundTCs = 0 Then\r\n Set newTSTest = TSTestF.AddItem(CurrentTest.ID)\r\n newTSTest.Post\r\n End If\r\n\r\n End If\r\n\r\n Set newTSTest = Nothing\r\n Set myTSTest = Nothing\r\n Set TSFilter = Nothing\r\n Set TSTestF = Nothing\r\n Set TSTestList = Nothing\r\n Set TSFilter = Nothing\r\n Set TSFact = Nothing\r\n Set newNode = Nothing\r\n Next\r\n\r\n On Error GoTo 0\r\nEnd Sub\r\n<\/code><\/pre>\n<\/span>","protected":false},"excerpt":{"rendered":"Dear LEM Readers, In previous article, we learnt How to connect to HP QC using Excel Macro. In this article, we are going to learn How to create folder structure in HP QC Test Lab. As you must be knowing – To show the test execution in Test Lab you should follow the below steps: […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1246,1675,1677,1682],"tags":[],"class_list":["post-12182","post","type-post","status-publish","format-standard","hentry","category-macro","category-excel-macro-for-beginners","category-hp-qc","category-popular-articles"],"yoast_head":"\n
HP Quality Center - Create Folder Structure in Test Lab and Pull test Cases from Test Plan - Let's excel in Excel<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n