Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

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

How to add Attachments in QC during test script execution in QTP

Using below code, we can add attachment to QC during test script execution:

''This function will add the required attachment in QC, for Location defined by argument strLocationinQC

Function func_AddAttachmentToQC(FilePath,strLocationinQC)



On Error Resume next

If (ucase(strLocationinQC) = "TEST") Then

Set objCurrentTest = QCUtil.CurrentTest.Attachments

Set objAttach = objCurrentTest.AddItem(Null)

ElseIf(ucase(strLocationinQC) = "TESTSET") Then

Set objCurrentTest = QCUtil.CurrentTestSet.Attachments

Set objAttach = objCurrentTest.AddItem(Null)

ElseIf(ucase(strLocationinQC) = "TESTRUN") Then

Set objCurrentTest = QCUtil.CurrentRun.Attachments

Set objAttach = objCurrentTest.AddItem(Null)

End If

objAttach.FileName = strFilePath

objAttach.Type = 1

objAttach.Post

objAttach.Refresh

End Function

How to integrate QTP 11 with Quality Center/ALM

HP ALM 11 or Quality Center is used as a test management tool in which we can store tests, function Libraries, test data, object repository, recovery scenario and much more. Below are some of the features in QTP required to connect to Quality Center and various options in QTP regarding QTP-QC Integration

Integration between QC and QTP

QTP can connect to a project stored in ALM through VBScript Code or through QTP IDE as explained below:

Through Code

Below code creates a connection to QC. This will validate if a connection to QC already exists and in case not connected than connects to the required project in QC

Public Functionfunc_ConnectQCQTP(QCurl,Domain,ProjectName,UserName,Password)

Set qtApp = CreateObject("QuickTest.Application") 

If  qtApp.launched <> True then 

    qtApp.Launch 

End If

qtApp.Visible = "true"

If Not qtApp.TDConnection.IsConnected Then

   qtApp.TDConnection.Connect QCurl,Domain,ProjectName,UserName,Password,False

End If

Set qtApp = nothing

End Function


Through QTP Interface


Go to File>ALM/QC Connection as shown below and create the connection.

Connecting to QC from QTP



Connecting to QC from QTP

User is allowed options to reconnect to the QC Server, and authenticate on start up and login to project automatically once QTP is launched.

Version Control in QC


In case of test stored in QC,version controlling the test script is very useful,so that test can be open by one user at a time and previous versions of test are available and can revert to previous version in case of issues. In case of version control, a test will open in read only mode and changes in script can be done only post checking out the script, and once changes are incorporated, changes should be checked in.



QCUtil - utility object in QTP for QC- QTP intregration


In this tutorial, We will discuss about QCUtil - utility object in QTP for QC- QTP intregration. Will discuss various properties of QCUtil Object in this post. Hope this information is useful for QC-QTP integration.

QCUtil Object 

QCUtil Object is used to access QC OTA.
Below are the properties of QCUtil object that can be used for extracting information from QC.

Properties of QCUtil Object


1. QCUtil.CurrentRun:  This give reference to the current test run in QC.We can then get  information of currentrun  like name as shown below:


set objRun = QCUtil.CurrentRun
msgbox objRun.Name

2. QCUtil.CurrentTest: This give reference to the current test in QC. We can extract information like name of the test, adding attachment to current test using this property


set objTest = QCUtil.CurrentRun
msgbox objTest.Name

3. QCUtil.CurrentTestSet: This give reference to the current test set in QC. We can  extract information similar as above for testset using this property.


set CurrentTSTest = QCUtil.CurrentTestSet

4. QCUtil.CurrentTestSetTest: This gives reference to current test execution instance in the testset.


set CurrentTSTestSet = QCUtil.CurrentTestSetTest

5. IsConnected Property: returns true/false based on QTP currently connected to QC project.


blnQCsts = QCUtil.IsConnected

6. QCConnection Property: This gives an instance of current run session and can access the structure of QC using this property


Set QCConnection = QCUtil.QCConnection


Examples of working with QCUtil Object


1.Adding a defect in QC using QCUtil Object:


            ‘Create instance of QCConnection
            Set QCConnection = QCUtil.QCConnection
‘Create an instance of BugFactory
Set DefFactory = QCConnection.BugFactory
'Add a new defect
Set Bug = DefFactory.AddItem(Nothing)
‘Provide mandatory details for the defect
Bug.Status = “New”
Bug.Summary = “Module Detected new defect summary”
Bug.DetectedBy = “njoshi”
Bug.AssignedTo = “dev001”
Bug.Post
Set DefFactory = nothing
Set QCConnection = nothing.

2. Adding Attachment to QC 


Dim ObjCurrentTest,ObjAttch
‘ We can add attachment to currentTest, current run, testset, and testsettest by using repective ‘properties 
Set ObjTest = QCUtil.CurrentTest.Attachments
Set ObjAttachFile = ObjTest.AddItem(Null)
ObjAttachFile.FileName = FileName ‘ Provide path of the file that needs to be attached to QC 
ObjAttachFile.Type = 1
ObjAttachFile.Post
ObjAttachFile.Refresh

3. Validating If QC is connected properly: 


if QCUtil.IsConnected then
msgbox “QC is connected”
Else
Msgbox “QC is not connected”
EndIf
   

4. Connecting to QC through QTP


Set qtApp = CreateObject ("QuickTest.Application")
If  qtApp.launched <> True then
     qtApp.Launch
End If
qtApp.Visible = "true"
If Not qtApp.TDConnection.IsConnected Then
      qtApp.TDConnection.Connect QCurl, DomainName, ProjectName, UserName, Password, False
End If