1

My problem is that the current code only uploads one Test case and I have no way of adding more than one since the number of test steps are dynamic (see attached image), hence I wouldn't know in which row each test case would end in order to add that into the code in order to automate the whole process if I had say 10 Test cases to upload for instance.

I would appreciate your help to come up with a way to create a loop which could integrate everything and let the user upload as many test cases as necessary.

Cheers.

I've managed to upload one test case with all the steps and expected results.

Sub upload_test_cases()

Dim wd, CConnection, sProject, sTestPlanPath, TestFolderPath, strNodeByPath

'qcURL = InputBox("Please enter ALM URL", "", "http://url:8080/qcbin")
qcURL = "http://url:8080/qcbin/"
If qcURL = "" Then
  MsgBox ("ALM URL cannot be blank")
  Exit Sub
End If

'sDomain = InputBox("Please enter your Domain" & vbNewLine & "Eg:CORE_SYSTEMS", "", "CORE_SYSTEMS")
sDomain = ""
If sDomain = "" Then
  MsgBox ("DomainName cannot be blank")
  Exit Sub
End If

'sProject = InputBox("Please enter your ProjectName" & vbNewLine & "Eg:RADC;GCM(As per ALM Project)", "", "GCM")
sProject = ""
If sProject = "" Then
  MsgBox ("ProjectName cannot be blank")
  Exit Sub
End If

sUser = InputBox("Please enter your Username" & vbNewLine & "Eg:MSID", "", "")
'sUser = ""
If sUser = "" Then
  MsgBox ("UserName cannot be blank")
  Exit Sub
End If

sPass = InputBox("Please enter your Password", "", "")
'sPass = ""

'sFolderpath = InputBox("Please enter your ALM Folderpath" & vbNewLine & "<Subject\FolderStructure>", "")
'sFolderpath = "Subject\Folder_Name"

'If sFolderpath = "" Then
 ' MsgBox ("FolderPath cannot be blank")
  'Exit Sub
'End If

Set QCConnection = CreateObject("TDApiOle80.TDConnection")

QCConnection.InitConnectionEx qcURL
QCConnection.ConnectProjectEx sDomain, sProject, sUser, sPass


Set tsf = QCConnection.TestFactory
Set trmgr = QCConnection.TreeManager
Set subjectfldr = trmgr.NodebyPath("Subject")
Worksheets("Sheet1").Select
' read the main and sub folder names
Set folder = Worksheets("Sheet1").Cells(2, 1)
Set subfolder = Worksheets("Sheet1").Cells(2, 2)

On Error Resume Next
' create main folder
Set trfolder = subjectfldr.AddNode(Worksheets("Sheet1").Cells(2, 1))
trfolder.Post

Set subjectfldr = trmgr.NodebyPath("Subject\" & folder)
'create subfolder if specified
If Not subfolder = "" Then
Set trfolder = subjectfldr.AddNode(subfolder)
trfolder.Post
End If

'reset error handling
On Error GoTo 0

If subfolder = "" Then
Set trfolder = trmgr.NodebyPath("Subject\" & folder)
Else
Set trfolder = trmgr.NodebyPath("Subject\" & folder & "\" & subfolder)
End If


' now create a test case
Set sampleTest = trfolder.TestFactory.AddItem(Null)
' set mandatory values
sampleTest.Field("TS_NAME") = Worksheets("Sheet1").Cells(2, 3) ' Test Case Name
sampleTest.Field("TS_DESCRIPTION") = Worksheets("Sheet1").Cells(2, 4) ' Project
sampleTest.Field("TS_RESPONSIBLE") = Worksheets("Sheet1").Cells(2, 8) ' Designer[![enter image description here][1]][1]


sampleTest.Post
' create test steps
Set dsf = sampleTest.DesignStepFactory
Set stepList = dsf.Newlist("[empty]")

Dim RowCount As Integer

' loop through all the steps
LastRow = Range("F2", Range("F2").End(xlDown)).Rows.Count
For i = 2 To (LastRow + 1)
Set dstep = dsf.AddItem(Null)
dstep.StepName = Worksheets("Sheet1").Cells(i, 5) ' Step Name
dstep.StepDescription = Worksheets("Sheet1").Cells(i, 6) ' Step Description
dstep.StepExpectedResult = Worksheets("Sheet1").Cells(i, 7) ' Step Expected Results
'stepList.Add (dstep)
'sampleTest.Post
dstep.Post
Next i


Set DesignStepFactory = Nothing
Set TestFactory = Nothing
Set TreeManager = Nothing
    
'Disconnect from QC
QCConnection.Disconnect

'Logout the QC Session
QCConnection.Logout
QCConnection.ReleaseConnection

End Sub

User should be able to upload as many test cases as necessary as per data added in Sheet1 of the excel spreadsheet.

I know there is an Excel Add-in to perform this action but running a Macro and setting everything yourself is much easier and convenient, that's why I'm trying to come up with this specific macro.

enter image description here

Community
  • 1
  • 1
pyrish
  • 65
  • 1
  • 10
  • Hi, I am not sure whether I understand your question fully. May you edit your question please and add a step-by-step recipe what exactly you tried? My usual way is to desing meta-Excelfile which tracks the test case steps per test case and generating a file (without any VBA inside) for the standard HP ALM Excel plugin. – B--rian Aug 19 '19 at 12:15

0 Answers0