QTP - 27 Working with HP’s QC 与QC交互
2012-02-08 18:12
399 查看
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” |
27.2 QCUtil Object
QCUtil Object provides the following properties:CurrentRun Property | 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). |
'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 Object27.4 TDConnectionObject
If QC connected:
Set TDConnection = QCUtil.QCConnection print TDConnection.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 |
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 |
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; |
Set oAttachments = FromPlace.Attachments 'Get a collection of all attachments present Set allAttachment = oAttachments.NewList("") For Each oAttachment In allAttachment ‘process each attachments Next |
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 |
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 |
'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 |
'Path for the folder where the Test Set exists testSetFolder = QCUtil.CurrentTestSet.TestSetFolder.Path |
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 |
'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 |
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 |
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 |
相关文章推荐
- QTP - 26 Working with MS IE browser 与IE 交互
- QTP -20 Working with web Tables 与webTable交互
- QTP-22 Working with Databases 与DB交互
- QTP - 23 (Working with MS Excel) QTP与Excel交互
- QTP -25 Working with MS Word 与word交互
- QTP - 17 Working with APIs 与windows API交互
- QTP - 24 Working with MS Outlook 与outlook交互
- QTP-21 Working with XML 与XML交互
- 与android database 交互(chapter 14-Working with the SQLite Database)
- 迅雷下载 HP QTP LR QC AML MyEclipse8.5 Tomcat7地址
- QTP -30 Working with .NET Classes
- Manual:Core:Working with JSON (EXT 与json的交互)
- QTP-Working with Outlook-ClickYes Pro
- [转]Working with the Web ADF timeout showLapseAlert 9.3 与 9.2
- Functions for Working with Objects matlab
- Working with Dates in PL/SQL(PL/SQL中使用日期)
- Working with Numbers in PL/SQL(在PL/SQL中使用数字)
- iOS SDK: Working with URL Schemes
- QC出现HP AML-client停止工作解决方法