使用HP-UFT,是否可以判断对象存储库中的对象是否正在其他测试中使用?

使用HP-UFT,是否可以判断对象存储库中的对象是否正在其他测试中使用?,hp-uft,Hp Uft,我目前正在使用UFT——我有一个GUI测试,在我的一个测试中有一个web元素对象,我想删除/更新,但我担心它会被我们测试套件中的另一个测试引用。我将进入一个别人构建的测试套件 是否有任何方法可以判断对象存储库中的对象是否正在其他测试中使用?无需进入每个单独的测试和操作就可以找到答案?我的方法是简单的递归文件搜索 开放式EditPlus 搜索->在文件中查找 查找内容= 文件类型=*.mts |*.vbs |*.qfl 文件夹= 选中“包括子文件夹”复选框 单击查找 您可以使用“搜索>查看>查找”

我目前正在使用UFT——我有一个GUI测试,在我的一个测试中有一个web元素对象,我想删除/更新,但我担心它会被我们测试套件中的另一个测试引用。我将进入一个别人构建的测试套件


是否有任何方法可以判断对象存储库中的对象是否正在其他测试中使用?无需进入每个单独的测试和操作就可以找到答案?

我的方法是简单的递归文件搜索

开放式EditPlus 搜索->在文件中查找 查找内容= 文件类型=*.mts |*.vbs |*.qfl 文件夹= 选中“包括子文件夹”复选框 单击查找
您可以使用“搜索>查看>查找”或UFT中的ctrl+F并选择查看整个解决方案,然后从每个操作打开Script.mts文件并搜索对象名称。如果找到对象,请在文件中写入对象所在的脚本名称和行号

使用以下代码:

'strScriptsPath is the path where your test script folders are placed.

Set strScripts = objFSO.GetFolder(strScriptsPath).SubFolders
For Each Script In strScripts
    strAction = strScriptsPath & "\" & Script.Name & "\Action1\Script.mts"
    If objFSO.FileExists(strAction) Then
        'Open Script in NotePad
        Set strFile = objFSO.OpenTextFile(strAction, 1)
        Do While Not (strFile.AtEndOfStream)
            strLine = strFile.ReadLine
            If InStr(1, strLine, strObjectName) > 0 Then
                iVerificationCount = objSheet.UsedRange.Rows.Count
                iCurrentRow = iVerificationCount + 1
                objSheet.Cells(iCurrentRow, 1) = Script.Name
                objSheet.Cells(iCurrentRow, 2) = strLine
                If strFile.AtEndOfStream Then
                    objSheet.Cells(iCurrentRow, 3) = strFile.Line
                Else
                    objSheet.Cells(iCurrentRow, 3) = strFile.Line - 1
                End If
            End If
        Loop
        strFile.Close
        Set strFile = Nothing
    End If
Next
Set strScripts = Nothing
为了能够使用此代码,请声明objFSO对象并编写一段代码来创建excel并获取objSheet

也可以使用以下代码替换对象名称:

'strScriptsPath is the path where your test script folders are placed.

Set strScripts = objFSO.GetFolder(strScriptsPath).SubFolders
For Each Script In strScripts
    strAction = strScriptsPath & "\" & Script.Name & "\Action1\Script.mts"
    If objFSO.FileExists(strAction) Then
        'Open Script in NotePad
        Set strFile = objFSO.OpenTextFile(strAction, 1)
        Do While Not (strFile.AtEndOfStream)
            strLine = strFile.ReadLine
            If InStr(1, strLine, strObjectName) > 0 Then
                iVerificationCount = objSheet.UsedRange.Rows.Count
                iCurrentRow = iVerificationCount + 1
                objSheet.Cells(iCurrentRow, 1) = Script.Name
                objSheet.Cells(iCurrentRow, 2) = strLine
                If strFile.AtEndOfStream Then
                    objSheet.Cells(iCurrentRow, 3) = strFile.Line
                Else
                    objSheet.Cells(iCurrentRow, 3) = strFile.Line - 1
                End If
            End If
        Loop
        strFile.Close
        Set strFile = Nothing
    End If
Next
Set strScripts = Nothing
如上所述,为每个循环使用

strScript = strScriptsPath & "\" & strScriptName & "\Action1\Script.mts"
strFind = "Old Object Name"
strReplace = "New Object Name"
Set strFile = objFSO.OpenTextFile(strScript, 1)
strData = strFile.ReadAll
strNewData = Replace(strData, strFind, strReplace)
strFile.Close
Set strFile = Nothing
Set strFile = objFSO.OpenTextFile(strScript, 2)
strFile.Write strNewData
strFile.Close
Set strFile = Nothing
**您只需将整个代码写入.vbs文件并运行该文件