Tuesday, June 22, 2010

QTP: Get an attachment from a Test in QC

Function getAttachmentFromQC(attachmentName)
Dim returnValue

Dim attachmentList
Set attachmentList = QCUtil.CurrentTest.Attachments.NewList ("")

For Each Attachment in attachmentList
Attachment.Load True, ""
If InStr(Attachment.FileName, attachmentName) Then
getAttachment = Attachment.FileName
End If
Next

End Function


Usage
This code imports the first sheet from a attached excel sheet
DataTable.ImportSheet getAttachmentFromQC("test_data.xls") ,1 ,1

Edit "Generate Script" Template for Quality Center QT Add-In

In this post I will update the Script that generates a script from manual test steps in QC. It is assumed that you have the "QuickTest Add-in For Quality Center" installed.

Locate Script
YOUR_HP_DIRECTORY\QuickTest Add-in For Quality Center\bin\Templates\Template10\Action1
Or similar

Make Backup
Copy "Scripts.mts" to a file called "Script.mts.backup"

Edit File
Open "Script.mts" in Edit Software, e.g. Notepad
Script looks like this
' This test was created using HP Quality Center[No Page Break]


Update file
Changing file to this
' This test was created using HP Quality Center[Page Break]
Option Explicit[Page Break]
[Page Break]

Close and Save file

Try it out
Start QC
Create a new test and add some steps
Click the "Genereate Script" button, select "QUICKTEST_TEST" and confirm
Select "Test Script" tab
Change to "Expert View"
Check the results

To edit Step template
Goto
YOUR_HP_DIRECTORY\QuickTest Add-in For Quality Center\bin\Templates

Edit ManualTemplate.txt

Monday, June 21, 2010

Add user defined field to test case to Quality Center

Add Custom Field
You need admin right to do this
Tools > Customize
Project Entities > Test > User Fields
Select first ZZTC_Customize_AlfaNum_xx field

Make it visible
Tools > Customize
Groups
Select the group
View
Select Tab Test Cases
Select "Test Cases Data-Hiding Filter"
Select Tab Visible Fields
Mark your new field
Click OK
Close and Save

Now it should be visible

QTP QC integration: QCUtil

There is magic variable thats called QCUtil that gives you instant access to values in QC, if the QTP script was started from QC.

Example of Usage
Set currentTSTest = QCUtil.CurrentTestSetTest
currentTSTest.Field("TC_USER_11") = 4
currentTSTest.Post

Check if connected to Quality Center
If QCUtil.IsConnected Then
...
End If

All methods in QCUtil
CurrentRun - Returns the Quality Center OTA Run object, which represents the current run.
CurrentTest -
CurrentTestSet -
CurrentTestSetTest -
IsConnected -
QCConnection -

QTP: Using a parameter in the DataTable as a global incrementer

I needed to find a way to have a global incrementer to count all iterations that passed or failed during a QTP run.
This is one way of doing it using DataTable

Adding a new Sheet in The DataTable
DataTable.AddSheet("Temp")

Adding a Parameter to the Sheet ( Default value 0 )
DataTable.GetSheet("Temp").AddParameter "Counter","0"

Increment Value
DataTable.GetSheet("Temp").GetParameter("Counter").ValueByRow(1) = DataTable.GetSheet("Temp").GetParameter("Counter").ValueByRow(1) + 1

Updating a Custom TestSet Parameter
Set currentTSTest = QCUtil.CurrentTestSetTest
currentTSTest.Field("TC_USER_11") = DataTable.GetSheet("Temp").GetParameter("Counter").ValueByRow(1)
currentTSTest.Post