QTP - 27 Working with HP’s QC 与QC交互

news/2024/11/28 19:47:02/

27 Working with HP’s QC

Note: First make sure QTP connect to QC.

27.1 QC Path:

QC path’s root folder is “Subject”. So all QC path startwith “[QualityCenter]Subject”. Set QC path into QTP’s Toolsà Options…àFolder(Tab)

QTP use QC paths:

DataTable.Import “[QualityCenter]Subject\Input\TestCase1.xls”

DataTable.ImportSheet “[QualityCenter]Subject\Input\TestCase1.xls”, “Global”, “Global”

 

ExecuteFile “[QualityCenter]Subject\ScriptConfiguration.vbs”

 

Note: QTP cannot use relative path, but you can write a function.

 

27.2 QCUtil Object

QCUtil Object provides the following properties:

Returns the Quality Center OTA Run object (QC: Test Plan).

  • CurrentTestSet Property

Returns the collection of tests (QC: Test Lab).

  • CurrentTestSetTest Property

Returns the Quality Center OTA TSTest object (QC: Test Lab).

  • IsConnected Property

Boolean value indicates whether QTP is currently connected to a QC.

  • QCConnection Property

Returns the Quality Center OTA QCConnection objectd

  • CurrentTest Property

Returns the Quality Center OTA Test object (QC: Test Plan).

 

Example to use QCUtil object:

'Are we connecting to QC?

IsQCConnected = Not (QCUtil.QCConnection Is Nothing)

'Is the test stored in QC

IsTestPresentInQC = Not (QCUtil.CurrentTest Is Nothing)

'Is the test running from QC

IsTestRunningFromQC = Not (QCUtil.CurrentRun Is Nothing)

 

27.3 QC Open Test Architecture (OTA)

即QCCOM, 略。最顶层是TDConnectionObject.TDConnection Object TDConnectionObject TDConnection Object TDConnection Object TDConnection Object

27.4 TDConnectionObject

If QC connected:

 

Set TDConnection = QCUtil.QCConnection

print TDConnection.Connected

 

If QC not connected:

Set qtApp = CreateObject("QuickTest.Application")

qtApp.Launch

qtApp.Visible = True

qtApp.TDConnection.Connect "http://qcserver ", _
              "MY_DOMAIN", "My_Project", "James", "not4you", False

If qtApp.TDConnection.IsConnected Then

               print "Connect to qc is successful" & qtApp.TDConnection.User & “log in”

End if

 

27.4 TheCommand and Recordset  Object

The Command and Recordset object allow us to get data from QC DB.

Note:注意DB返回数据的格式,如果是HTML格式,就得再写一个fucntion转换成plainText格式。

'Get the TD OTA object reference

Set TDConnection = QCUTil.QCConnection

 

'Get the ID of the current test in the Data base

TestID = QCutil.CurrentTest.Field ("TS_TEST_ID")

 

'Get all the design steps present in the Test and

'read the Step Description and Expected Text

Set TDCommand = TDConnection.Command

TDCommand.CommandText =  _

  "Select DS_DESCRIPTION, DS_EXPECTED From DESSTEPS where DS_TEST_ID = " & TestID

 

'Execute the query

Set TDRes = TDCommand.Execute

 

'Loop throuh all the results in the recordset

While Not TDRes.EOR

  Msgbox TDRes.FieldValue("DS_DESCRIPTION")

  Msgbox TDRes.FieldValue("DS_EXPECTED")

 

  TDRes.Next

Wend

 

27.5  The AttachmentFactory Collection

AttachmentFactory collection can access attachments present in thefollowing object:

Requirement Tab;

Test Plan Tab: Folder, Test, Design steps;

Test Lab Tab: Folder, Test, TestSet, TestRun, TestStep

Defect;

 

Here is the example to get attachment:

  Set oAttachments = FromPlace.Attachments

'Get a collection of all attachments present

  Set allAttachment = oAttachments.NewList("")

For Each oAttachment In allAttachment

‘process each attachments

Next

 

Download attachment as the “process each attachments” (above)

Set FSO = CreateObject("Scripting.FileSystemObject")

oAttachment.Load True,""

'Copy the file from temporary downloaded location to the TOPlace folder

    FSO.CopyFile oAttachment.FileName, _

                 TOPlace & oAttachment.Name(1),True

 

27.6  Simple way to download files from QC:PathFinder & Locate method

Note: 1PathFinder based on the folders specified in the Folder Tab (ToolsàOptionàFolders)

             2 The method only used on foldersor tests present in the test plan tab

             3 If QTP local temporary fileshave same name file, will not download. So clear                              temporary files beforedownload.

sFilePath = PathFinder.Local(“QCcommon.vbs”)

‘Or full path

sFilePath = PathFinder.Local(“[QualityCenter] Subject\AllTest\QCcommon.vbs”)

 

27.7  Uploading attachment to QC

  'Get attachments (AttachmentFactory)

   Set oAttachments = QCUtil.CurrentTest.Attachments

  'Now just upload the new one

  Set oNewAttachment = oAttachments.AddItem(Null)

  oNewAttachment.FileName = NewFileName

  oNewAttachment.Type = 1 'TDATT_FILE

  oNewAttachment.Post

 

27.8  Getting the Current Test location

'Function to get the current test path is running from

Public Function GetCurrentTestPath()

  GetCurrentTestPath = ""

 

  'The test in not in QC

  If QCUtil.CurrentTest is Nothing Then Exit Function

 

  'Get the test name

  testName = CurrentTest.Name

 

  'Get the ID of the parent folder

  parentFolderID = CurrentTest.Field("TS_SUBJECT").NodeID

 

  'Get the complete path of parent folder

  parentFolderPath = QCUtil.QCConnection.TreeManager.NodePath(parentFolderID)

 

  GetCurrentTestPath = parentFolderPath & "\" & testName

End Function

 

27.9 Gettingthe Current Test Set Location:

    'Path for the folder where the Test Set exists

    testSetFolder = QCUtil.CurrentTestSet.TestSetFolder.Path

 

27.10Enumerating all the tests in test lab tab

 The Test Lab folderstructure is managed by TestSetTreeManager object. TestSet object are managedby TestSetFactory object, Each TestSet object contains test managed byTSTestFactory object.

--TestSetFactory –TestSet –ConditionFactory –Condition

                                                --TSTestFactory--TSTest--RunFactory

--TestSetTreeManager--TestSetFolder—TestSetFactory

Here is the sample code:

'This function can be used to enumerate all the test present inside a testSet.

Set allTests = oTestSet.TSTestFactory.NewList("")

  For each oTest in allTests

    Print "Test - " & oTest.name

  Next

 

Function EnumerateAllTestSets(ByVal FolderPath)

  'Check if the folder object has been passed or a string path

  If isObject(FolderPath) Then

    Set oTestSetFolder = FolderPath

  ElseIf FolderPath = "" or LCase(FolderPath) = "root" then

    'Root folder needs special handling

    Set oTestSetFolder = QCUtil.QCConnection.TestSetTreeManager.Root

  Else

    'Get the object from the path

    Set oTestSetFolder = QCUtil.QCConnection.TestSetTreeManager.NodeByPath(FolderPath)

  End If

 

  'A root folder cannot have any test set. So we need not check

  'for any testsets in case of the Root Folder.

  If oTestSetFolder.name <> "Root" Then

    Print oTestSetFolder.Path

 

    'Loop through all the test sets present in the folder

    Set allTestSets = oTestSetFolder.TestSetFactory.NewList("")

    For each oTestSet in allTEstSets

      Print "Test Set - " & oTestSetFolder.Path & "\" & oTestSet.Name

 

      'Call another function to enumerate all the test inside the current test set

      EnuemrateTestInTestSet oTestSet

    Next

  End If

 

27.11Enumerating all the tests in test plan tab

QC OTA model’s TreeManager object manage the folderstructure of test plan tab. Each folder contains folders/tests. Tests aremanaged by a TestFactory object.

--TestFactory--Test--DesignStepFactory--DesignStep

--TreeManager--SysTreeNode

Here is the sample code:

Public Function EnumerateAllTestsinTestPlan(ByVal folderPathOrObject)

  If IsObject(folderPathOrObject) Then

    'We already have a reference to the folder object

    Set oTestPlanFolder = folderPathOrObject

  ElseIf folderPathOrObject = "" or lcase(folderPathOrObject) = "subject" Then

    'Get the root subject folder

    Set oTestPlanFolder = QCutil.QCConnection.TreeManager.NodeByPath("Subject")

  Else

   'Get the folder using the string path

    Set oTestPlanFolder = QCUTil.QCConnection.TreeManager.NodeByPath(folderPathOrObject)

  End If

‘And then use NewList on that object to get the collection of tests present in the folder

Set oTestFactory = oTestPlanFolder.TestFactory.NewList("")

  For each oTest in oTestFactory

        MsgBox oTestPlanFolder.Path & "\" & oTest.Name

  Next

 

  'Recursively call this function for each sub folder

  Set allSubFolders = oTestPlanFolder.NewList()

  For each oFolder in allSubFolders

    EnumerateAllTestsinTestPlan oFolder

  Next

End Function

 


http://www.ppmy.cn/news/179998.html

相关文章

ubuntu 硬盘分区格式及大小方案

上周配了一台新机&#xff0c;cpu:e8400 双核 3.0G 主板 P5Q turbo 内存 4G 硬盘500G . 之前的笔记本由于内存比较小&#xff0c;所以分别装了ubuntu和win2k3。 ubuntu 正常情况下有256M内存就足够了&#xff0c;这种情况下我决定不在用物理硬盘来装 win2k3 了&#xff0c;只装…

P51 8

P51 第八题 输入整数a和b,如果能被b整除&#xff0c;就输出算式和商&#xff0c;否则输出算式&#xff0c;整数商和余数。 #include<stdio.h> #include<stdlib.h> int main() {int a,b,c;printf("请输入a,b\n");scanf("%d",&a);scanf(&q…

P4P

P4P在西方世界已经生机一片&#xff0c;但它还没有来到中国的时候&#xff0c;就遭受到了质疑。P4P有一个初级目标和高级纲领。初级目标就是加速网民下载、节约电信运营商流量。高级纲领则是建立软件厂商和电信运营商的对话机制&#xff0c;以实现网民、软件商、运营商的多赢。…

5-1

输出 150 到 200之间有且仅有一位数字为9的所有整数。要求定义和调用函数is(n, digit)判断正整数n是否有且仅有一位数字为digit,若满足条件则返回1,否则返回0。 运行示例: 159 169 179 189 190 191 192 193 194 195 196 197 198 #include <stdio.h> int main(void) {…

vue3 技能提升

技能1&#xff1a;善用Composition API抽离通用逻辑 是的技能2&#xff1a;慢慢补充 是的技能3: 占位

华硕主板 ERROR CODE 8e000000 错误的解决方法

新配的华硕主板ASUS P5Q SE开机有个问题&#xff0c;在开机LOGO之前会黑屏&#xff0c;上边写着ERROR CODE&#xff1a;8e000000&#xff0c;网上查了下&#xff0c;好像还是华硕主板的专有问题。下边说一下解决方案其实很简单&#xff0c;只要在开机时按DEL键进入BIOS设置&…

P5.Pickle

1. Example Python challenge 5 载入文件中的信息&#xff0c;把信息存到列表中&#xff08;倒序存&#xff0c;因为pop()是倒序输出的&#xff09;&#xff0c;把结果打印出来。序列中的元素信息是(字符,字符出现的次数)。 2. Code

p45-001

数据结构与算法 p45-001 试设计一个非递归算法在O&#xff08;n&#xff09;时间内将一个含有n个元素的单链表逆置&#xff0c;要求其辅助空间为常量。 #include<iostream.h> typedef int T; template<class T> struct Node { T data; Node *next; }; …