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

本文详细介绍了如何使用HP QuickTest Professional(QTP)与Quality Center(QC)进行自动化测试,包括设置路径、使用QCUtil对象、OTA架构、连接与记录、附件管理、文件下载与上传、测试位置获取等关键步骤。

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).

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

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

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

Returns the Quality Center OTA QCConnection objectd

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

 

该数据集通过合成方式模拟了多种发动机在运行过程中的传感器监测数据,旨在构建一个用于机械系统故障检测的基准资源,特别适用于汽车领域的诊断分析。数据按固定时间间隔采集,涵盖了发动机性能指标、异常状态以及工作模式等多维度信息。 时间戳:数据类型为日期时间,记录了每个数据点的采集时刻。序列起始于2024年12月24日10:00,并以5分钟为间隔持续生成,体现了对发动机运行状态的连续监测。 温度(摄氏度):以浮点数形式记录发动机的温度读数。其数值范围通常处于60至120摄氏度之间,反映了发动机在常规工况下的典型温度区间。 转速(转/分钟):以浮点数表示发动机曲轴的旋转速度。该参数在1000至4000转/分钟的范围内随机生成,符合多数发动机在正常运转时的转速特征。 燃油效率(公里/升):浮点型变量,用于衡量发动机的燃料利用效能,即每升燃料所能支持的行驶里程。其取值范围设定在15至30公里/升之间。 振动_X、振动_Y、振动_Z:这三个浮点数列分别记录了发动机在三维空间坐标系中各轴向的振动强度。测量值标准化至0到1的标度,较高的数值通常暗示存在异常振动,可能潜在的机械故障相关。 扭矩(牛·米):以浮点数表征发动机输出的旋转力矩,数值区间为50至200牛·米,体现了发动机的负载能力。 功率输出(千瓦):浮点型变量,描述发动机单位时间内做功的速率,取值范围为20至100千瓦。 故障状态:整型分类变量,用于标识发动机的异常程度,共分为四个等级:0代表正常状态,1表示轻微故障,2对应中等故障,3指示严重故障。该列作为分类任务的目标变量,支持基于传感器数据预测故障等级。 运行模式:字符串类型变量,描述发动机当前的工作状态,主要包括:怠速(发动机运转但无负载)、巡航(发动机在常规负载下平稳运行)、重载(发动机承受高负荷或高压工况)。 数据集整体包含1000条记录,每条记录对应特定时刻的发动机性能快照。其中故障状态涵盖从正常到严重故障的四级分类,有助于训练模型实现故障预测诊断。所有数据均为合成生成,旨在模拟真实的发动机性能变化典型故障场景,所包含的温度、转速、燃油效率、振动、扭矩及功率输出等关键传感指标,均为影响发动机故障判定的重要因素。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值