Page 1 of 2
HP Quality Center Logging
Posted: Thu Jun 24, 2010 10:07 pm
by sdaly
For anyone interested, I have created a small module which allows you to record your test results in QC. This is useful if you are using QC as you can have all your test logs stored in a central place and obviously can make use of the QC metrics.
Instructions are below and I have attached the module. It is written in VB.NET, but you could always modify it if you are using a different language. If you find this useful let me know!
Thanks
Scott
Description
***********
Checks for a test in QC with same name under specified folder. If the test does not exist
then a placeholder is created. An instance of the test is then checked in the specified testset
within TestLab. If an instance does not exist, one is created. A run is then added with the latest
result and a Ranorex Test Log is uploaded and attached to the run.
Usage
*****
1)Add OTA reference to your project
2)Add the QCbridge module to your project.
3)Add the below to the main program
QCbridge.url = "http://??.??.??.??/qcbin"
QCbridge.user = "??"
QCbridge.pass = "??"
QCbridge.domain = "??"
QCbridge.project = "??"
4)Add the line of code below at the start of each test.[TRUE or FALSE to log to console)
QCbridge.startTest(System.Reflection.MethodBase.GetCurrentMethod().Name,False)
5)Add the line of code below at the end of each test.
QCbridge.stopTest("QCTESTPLANFOLDERNAME","QCTESTSETNAME","Passed")
6)Add the line of code below to the exception catch in the main program.
QCbridge.stopTest("QCTESTPLANFOLDERNAME","QCTESTSETNAME","Failed")
NOTE: The folder and testset must exist in QC.
Re: HP Quality Center Logging
Posted: Tue Aug 03, 2010 2:21 pm
by sdaly
I have made a few changed to this now....
If you want to use it, use the code below...
Imports TDAPIOLELib 'for QC
Imports Ranorex 'for Ranorex reporting
Imports System.IO
Imports System.Windows.Forms
Public Module QCbridge
'variables for QC connection details
Public url,user,pass,domain,project As String
'QC connection object
Dim tdc As TDAPIOLELib.TDConnection
'holds name of current test
Dim currentTestName, Tfolder,Tsetname As String
Dim boolTestStarted as Boolean
Public Sub startTest(TestPlanFolder as string,TestSetName as String,testName as string,logToConsole as Boolean)
currentTestName = testName
Tfolder = TestPlanFolder
Tsetname = TestSetName
'set the report up
Report.Setup(ReportLevel.Info, TestName & ".rxlog", logToConsole)
Report.Info("Test",TestName & " test starting")
'add system summary to report
Report.SystemSummary
boolTestStarted = True
End Sub
Public Sub stopTest(Result As String)
If boolTestStarted = True Then
If Result = "Passed" Then Report.Info("Test",currentTestName & " test finished")
'end the Ranorex report
report.End
'create connection to QC
connectQC(url,user,pass,domain,project)
'add the test result to QC
add(Result)
'disconect from QC
disconnectQC
boolTestStarted = False
End If
End Sub
Private Sub connectQC(url As String, user As String, pass As String, domain As String, project As String)
Try
'create new QC connection object
tdc = New TDAPIOLELib.TDConnectionClass
'initialise connection
tdc.InitConnectionEx(url)
'login to QC
tdc.Login(user, pass)
'login to project
tdc.Connect(domain, project)
Catch ex As system.Exception
'if an exception occurs while logging in, there is no point continuing, therefore abort the thread
Report.Info("QCBridge",ex.Message.ToString)
End Try
End Sub
Private Sub disconnectQC
Try
'disconnect from QC project
tdc.DisconnectProject
'disconnect from QC
tdc.Disconnect
tdc = Nothing
Catch ex As System.Exception
Report.Info("QCBridge",ex.Message.ToString)
End Try
End Sub
Private Sub add(Result as string)
Dim TestF As TestFactory
Dim NewTest As Test
Dim root As SubjectNode
Dim folder As SubjectNode
Dim TestSetF As TestSetFactory
Dim TstSet As TestSet
Dim testInstanceF As TSTestFactory
Dim tstInstance As TSTest
Dim RunF As RunFactory
Dim theRun As Run
Dim lst As TDAPIOLELib.List
Dim TreeMgr As TreeManager
Dim folderName As string = "Automation"
Dim labTreeMgr As TestSetTreeManager
Dim aFilter As TDFilter
Dim attachF As AttachmentFactory
Dim reportToAttach As Attachment
Dim ExStrg As IExtendedStorage
Try
TreeMgr = tdc.TreeManager
TestF = tdc.TestFactory
labTreeMgr = tdc.TestSetTreeManager
'get test plan root
root = TreeMgr.TreeRoot("Subject")
'find specified folder
folder = root.FindChildNode(Tfolder)
'set the filter to filter on the test factory
aFilter = TestF.filter
'filter on name of test
aFilter.Filter("TS_NAME") = Trim(currentTestName)
'filter on specified folder
aFilter.Filter("TS_SUBJECT") = folder.Path
'get list of matching tests
lst = TestF.NewList(aFilter.Text)
'check for no match
If lst.Count < 1 Then
'if no match, add test to the plan under specified folder
NewTest = TestF.AddItem(currentTestName)
NewTest.Field("TS_SUBJECT") = folder.NodeID
NewTest.Post
Else
'if tests were found, get first one found
NewTest = lst.Item(1)
End If
'set test set factory
TestSetF = tdc.TestSetFactory
'filter on testsetfactory
aFilter = TestSetF.Filter
'filter on specified testset name
aFilter.Filter("CY_CYCLE") = Tsetname
'get list of matching test sets
lst = TestSetF.NewList(aFilter.Text)
'get first match - if none are found, exception will be thrown
TstSet = lst.Item(1)
'set testinstancefactory
testInstanceF = TstSet.TSTestFactory
aFilter = testInstanceF.Filter
'filter test instances on test ID
aFilter.Filter("TC_TEST_ID") = NewTest.ID
'get maching instances inthe test set
lst = testInstanceF.NewList(aFilter.Text)
'check if an instance of the test was found
If lst.Count < 1 Then
'if no instance was found then add an instance
tstInstance = testInstanceF.AddItem(system.DBNull.Value)
tstInstance.Field("TC_TEST_ID") = NewTest.ID
Else
'if an instance was found, get it
tstInstance = lst.Item(1)
End If
'set initial status
tstInstance.Status = "No Run"
tstInstance.Post
'create run factory
RunF = tstInstance.RunFactory
'add new run for test
theRun = RunF.AddItem("Automated")
'set the result passed in
theRun.Status = Result
theRun.Post
theRun.Refresh
'upload if log exists
If file.Exists(currentTestName & ".rxlog") Then
'get attachment factory for the test run
attachF = theRun.Attachments
'add new attachment
reportToAttach = attachF.AddItem(currentTestName & ".rxlog")
'add description
reportToAttach.Description = "Ranorex Automated Test Report for " & currentTestName & ". Stylesheet required."
reportToAttach.Post
'get attachments storage
ExStrg = reportToAttach.AttachmentStorage
'set path where log exists
ExStrg.ClientPath = application.StartupPath
'upload the attachment, wait until upload finished
ExStrg.Save(currentTestName & ".rxlog",True)
End If
Catch ex As System.Exception
'on error, release QC connection
disconnectQC
report.Info("QCBridge", ex.Message.ToString)
End Try
End Sub
End Module
Re: HP Quality Center Logging
Posted: Mon Aug 16, 2010 6:29 am
by QAWebTester
Hi Scott,
Do you have similar approach for MS TFS or Test Manager.
If so, can you post one.
Thank you.
Re: HP Quality Center Logging
Posted: Wed Aug 25, 2010 3:32 pm
by sdaly
Hi QAWebTester
I've never used MS TFS but I suppose the approach would be similar.....
Re: HP Quality Center Logging
Posted: Wed Nov 10, 2010 9:06 pm
by sundarpn
In our Ranorex test scripts, we have the QC TestCase ID available. (this is the ID that corresponds to the manual test case).
Any thoughts on how to log results using this Test Case ID? I figured TestCase ID will be a better identifier. (and the automated script need not aware of the test plan tree structure)
Also, should a test set exist or will a test set be created automatically?
Thx
Re: HP Quality Center Logging
Posted: Thu Nov 11, 2010 9:27 am
by sdaly
Hi
See this line -
aFilter.Filter("TC_TEST_ID") = NewTest.ID
Just remove all the TestPlan code and replace NewTest.ID with the ID of the test to log.
The bit of code I posted is old now and does not create a set automatically....we have updated though and it does now create the set.
This will help you -
tdFilter1.Filter("CY_CYCLE") = "Auto_" & strTsetname & "_" & strTag2
'get list of matching test sets
listTDAPI = testSetFactory1.NewList(tdFilter1.Text)
If listTDAPI.Count < 1 Then
console.WriteLine("QCbridge creating new test set")
testSet1 = testSetFactory1.AddItem("Auto_" & strTsetname & "_" & strTag)
Else
testSet1 = listTDAPI.Item(1)
End If
Thanks
Scott
Re: HP Quality Center Logging
Posted: Thu Jul 21, 2011 9:12 am
by manpreet.x.singh
hey sdaly,
The HP QC LOGGING CODE you have give is very good. But My question is where you will keep you ranorex automated test cases to trigger. I mean to say is it stored on some local drive.
Please explain me this part briefly as I might to implement RANOREX in coming months
.
Thanks & Regards
Manpreet Singh
email : -
[email protected]
Re: HP Quality Center Logging
Posted: Fri Jul 22, 2011 5:36 pm
by sdaly
Hi Manpreet
You can store them wherever you like but a shared drive is probably a good option. We have our automation project set up with Cruise Control which builds the project and spits it out to a share every time someone commits to SubVersion.
If you are wanting to trigger the test from QC then you probably don't need this code, just create a VAPI-XP test and trigger using VBS like I explained in my other post.
If you are using Ranorex Studio, Nunit, your custom test manager etc to trigger the tests then you can use this code to create a test instance in test lab, record the result and upload the log.
Hope that helps
Thanks
Scott
Re: HP Quality Center Logging
Posted: Thu Oct 20, 2011 10:25 am
by rsriram
Hi Scott,
Thank you for the code and all the help you have provided in your posts.
I am evaluating Ranorex for my client, and the important requiremnt is QC integration. I am using the your code and steps in my test, however when it reaches the line tdc.InitConnectionEx(url), nothing happens. The execution is still in the "Executing" state and no activity. It doesnt even stop unless I stop the execution manually. I am pretty new to API and .Net coding, so any pointers or advice would be of great help.
Thanks
Sriram.
Re: HP Quality Center Logging
Posted: Thu Oct 20, 2011 10:39 am
by sdaly
Hi Sriram
Have you set the public url, username and password fields?
Also, do you have the relevant QC dependencies on your machine? To ensure you do, log in to QC as normal, the first time you log in, the OTA dll will be downloaded. Then in your project, make sure you have a reference to COM > OTA
Thanks
Scott
Re: HP Quality Center Logging
Posted: Thu Oct 20, 2011 11:23 am
by rsriram
Thank you, Scott. I have already added the OTA reference, I guess that'd done.
I have a public function in the test -
Public Sub InitQC()
QCbridge.url = "<myurl>"
QCbridge.user = "<myusername>"
QCbridge.pass = "<mypassword>"
QCbridge.domain = "<mydomain>"
QCbridge.project = "<myproj>"
End Sub
And I call it in the first action line in my recording (please see attachment). Is this the right way to do it?
Thanks,
Sriram.
Re: HP Quality Center Logging
Posted: Thu Oct 20, 2011 11:38 am
by sdaly
Ah so you are using this within Ranorex studio... I wrote this well before all the Ranorex code module stuff so not sure how it would work. I use Ranorex with SharpDevelop + Nunit so not sure about all the code module stuff etc... but it looks like you want to put together a QCLog Ranorex module....maybe one of the team will be able to give you a hand
Re: HP Quality Center Logging
Posted: Thu Oct 20, 2011 12:01 pm
by rsriram
Oh yes... sorry I forgot to mention that!
Thanks for the help, anyway.
Best,
Sriram.
Re: HP Quality Center Logging
Posted: Thu Oct 27, 2011 1:08 pm
by rsriram
Hi Scott,
I'm able to connect to QC now. Not sure how it happened, but it did.
I have one more question - Everytime the code tries to set the filter (aFilter = TestF.filter), it displays an Unexpected Exception with the message 'Field < Subject > requires a value from the corresponding list.'
I tried to fix it, it still would'nt work. Any idea why this is happening?
Thanks,
Sriram.
Re: HP Quality Center Logging
Posted: Thu Oct 27, 2011 1:21 pm
by sdaly
Hi Siram
Weird!...Maybe there was a setting changed in the dashboard
I'm not too sure tbh, what values are in the 'corresponding list?
It may well be that you are using a newer version of QC and the API may have some differences, I would consult the latest QC OTA API reference and check out some of the filtering examples....
Thanks
Scott