Showing posts with label QC-QTP Utilities. Show all posts
Showing posts with label QC-QTP Utilities. Show all posts

Monday, 6 May 2013

Automating QC


1- Uploading an attachment in QC

QCfolderName="Subject\JP\Test Set1"
localFilePath="C:\Documents and Settings\jagarwal\Desktop\To Do List.xlsx"
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.TDConnection.Connect "http://gls1qaqcr01:8080/qcbin/", "TCCA", "TCBS", "jagarwal", "Password1", False ' Connect to Quality Center
Set TDConnection = QCUtil.TDConnection
Set treeManager = TDConnection.TreeManager
Set folder1 = treeManager.nodebypath(QCfolderName)
Set strAtt = folder1.attachments
Set strAtta = strAtt.AddItem(Null)
strAtta.FileName = localFilePath
strAtta.Type = 1
strAtta.Post()
strAtta.Refresh
Set TDConnection=nothing
Set treeManager=nothing
Set folder1 =nothing


2- Removing an attachment from QC

QCfolderName="Subject\JP\Test Set1"
AttachmentName="To Do List.xlsx"
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.TDConnection.Connect "http://gls1qaqcr01:8080/qcbin/", "TCCA", "TCBS", "jagarwal", "Password1", False ' Connect to Quality Center
 
Set TDConnection = QCUtil.TDConnection
Set treeManager = TDConnection.TreeManager
Set folder1 = treeManager.nodebypath(QCfolderName)
intNdId = folder1.NodeID
Set strAtt = folder1.attachments
Set AttachFilter = strAtt.Filter
AttachFilter.Filter("CR_REFERENCE") =  "'ALL_LISTS_"& intNdId & "_" & AttachmentName & "'" 
Set attachList =  strAtt.NewList(AttachFilter.Text)
Set theAttachment=attachList.item(1)
strAtt.RemoveItem (theAttachment.ID)
'strAtta.Refresh
Set TDConnection=nothing
Set treeManager=nothing
Set folder1 =nothing
  

3- Downloading a file from QC to local file system

Public Function GetFolderAttachmentPath(TDAttachmentName, TDFolderPath)
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.TDConnection.Connect "http://gls1qaqcr01:8080/qcbin/", "TCCA", "TCBS", "jagarwal", "Password1", False ' Connect to Quality Center
 
Set objTreeManager = QCUtil.TDConnection.TreeManager
 Set objSysTreeNode = objTreeManager.NodeByPath(TDFolderPath)
 Set objAttachmentFactory = objSysTreeNode.Attachments
 Set objAttachmentFilter = objAttachmentFactory.Filter
 intNdId = objSysTreeNode.NodeID
 objAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & intNdId & "_" &   TDAttachmentName & "'"
 Set objAttachmentList = objAttachmentFilter.NewList

 If objAttachmentList.Count > 0 Then
     Set objAttachment = objAttachmentList.Item(1)
     objAttachment.Load True, ""
     strPath = objAttachment.FileName
Else     
     Reporter.ReportEvent micFail,"Failure in library function  'GetFolderAttachmentPath'",  "Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."  
End If
GetFolderAttachmentPath = strPath
set objTreeManager = Nothing
set objSysTreeNode = Nothing
set objAttachmentFactory = Nothing
set objAttachmentFilter = Nothing
End Function


4- Logging a new defect in QC


Function autoDefectLogging(strTestCaseNameSheet)

Dim qcServer
On error resume next


qcServer = "http://corswdcsapp13.corp.pg.eon.net:8080/qcbin"
qcUser = "S24856"
qcPassword = "Pa55w0rd"
qcDomain = "energy_WHOLESALE"
qcProject = "QC_EET_ENDUR_Programme"

'-------------------------------------------------------------------------
' This routine makes the connection to the gobal TDConnection object,
' and connects the user, password,domain & project specified in ' GlobalVariable.txt
'-------------------------------------------------------------------------
          
  Set tdc = CreateObject("TDApiOle80.TDConnection")
  tdc.InitConnectionEx qcServer
  tdc.Login qcUser, qcPassword
  tdc.Connect qcDomain, qcProject

 'Verify connection establishment
  

 If Err.Number <> 0 Then
          Reporter.ReportEvent micFail, "Error occured in Function- 'Connection could not be established","Error description: "& Err.Description & vblf & "Error number: " & Err.Number
 End If
                               
'-------------------------------------------------------------------------
' This routine makes bug object to auto log defect in Quality Center
' Variables used are defined in GlobalVariable.txt
'-------------------------------------------------------------------------                     

 Set BugFactory = tdc.BugFactory
 Set Bug = BugFactory.AddItem (Nothing)
 Bug.Summary = strTestCaseNameSheet
 Bug.Status = "New"
 Bug.AssignedTo = qcUser
 Bug.DetectedBy = qcUser
 Bug.Post

'Release all created objects
 Set BugFactory = Nothing
 Set Bug = Nothing

 If tdc.Connected Then
       tdc.Disconnect
 End If


 If tdc.LoggedIn Then
        tdc.Logout
 End If
          
 tdc.ReleaseConnection
 Set tdc = Nothing


'Disable error handling
On Error GoTo 0


End Function


5- Retrieving all defects from QC in an excel sheet


Public Function ConnectToQC(ByVal ServerName, ByVal Domain, ByVal Project)

 Dim QCServer, UserName, Password, QCConnection
 QCServer = "http://" & ServerName & "/qcbin"
 UserName = "alice_qc"
 Password = ""

 Set QCConnection = CreateObject("TDApiOle80.TDConnection")
 QCConnection.InitConnectionEx QCServer
 QCConnection.login UserName, Password
 QCConnection.Connect Domain, Project

 Set ConnectToQC = QCConnection
End Function



' Connect to the Quality Center Server.
Dim QCConnection
Set QCConnection = ConnectToQC("<MyQCServer>", "DEFAULT", "QualityCenter_Demo")


' Get a list of all the defects.
Dim BugFactory, BugList
Set BugFactory = QCConnection.BugFactory
Set BugList = BugFactory.NewList("")


' Open a new Excel worksheet.
Dim Excel, Sheet
Set Excel = CreateObject("Excel.Application")
Excel.WorkBooks.Add()
Set Sheet = Excel.ActiveSheet


' Set the column names.
Sheet.Cells(1, 1).Value = "Bug Id"
Sheet.Cells(1, 2).Value = "Summary"
Sheet.Cells(1, 3).Value = "Detected By"
Sheet.Cells(1, 4).Value = "Priority"
Sheet.Cells(1, 5).Value = "Status"
Sheet.Cells(1, 6).Value = "Assigned To"


' Retrieve the values of each bug.
Dim Bug, Row
Row = 2
For Each Bug In BugList
 Sheet.Cells(Row, 1).Value = Bug.Field("BG_BUG_ID")
 Sheet.Cells(Row, 2).Value = Bug.Summary
 Sheet.Cells(Row, 3).Value = Bug.DetectedBy
 Sheet.Cells(Row, 4).Value = Bug.Priority
 Sheet.Cells(Row, 5).Value = Bug.Status
 Sheet.Cells(Row, 6).Value = Bug.AssignedTo
 Row = Row + 1
Next


' Save the result.
' Open a new Excel worksheet.
Dim Excel, Sheet
Set Excel = CreateObject("Excel.Application")
Excel.WorkBooks.Add()
Set Sheet = Excel.ActiveSheet
Excel.ActiveWorkbook.SaveAs("c:\QualityCenter_Demo_DEFECTS.xls")
Excel.Quit


' Cleanup.
Set Excel = Nothing
Set QCConnection = Nothing



6- Running a Test Set from QC


' Get the test set tree manager from the test set factory
'tdc is the global TDConnection object.


Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.TDConnection.Connect "http://gls1qaqcr01:8080/qcbin/", "TCCA", "TCBS", "jagarwal", "Password1", False ' Connect to Quality Center

Set tdc=QCutil.TDConnection

Set TSetFact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager

nPath = "Root\" & Trim(tsFolderName)
Set tsFolder = tsTreeMgr.NodeByPath(nPath)


'Search for the test set passed as an argument to the example code
Set tsList = tsFolder.FindTestSets(tSetName)


If tsList.Count > 1 Then
   print "FindTestSets found more than one test set: refine search"
elseIf tsList.Count < 1 Then
   print "FindTestSets: test set not found"
End If


Set theTestSet = tsList.Item(1)
Print theTestSet.ID


'Start the scheduler on the local machine
Set Scheduler = theTestSet.StartExecution("")


'Set up for the run depending on where the test instances  are to execute.
Select Case runWhere
 Case RUN_LOCAL
            'Run all tests on the local machine
         Scheduler.RunAllLocally = True
 Case RUN_REMOTE
            'Run tests on a specified remote machine
            Scheduler.TdHostName = HostName
End Select


'Run the tests
Scheduler.run


'Get the execution status object
Set execStatus = Scheduler.ExecutionStatus


For i = 1 To execStatus.Count
   Set TestExecStatusObj = execStatus.Item(i)
    Print "Iteration " & i & " Status: " & " Test " & TestExecStatusObj.TestId &" ,Test instance " & TestExecStatusObj.TestInstance & " ,order " & TestExecStatusObj.TSTestId & " " & TestExecStatusObj.Message & ", status=" & TestExecStatusObj.Status
Next