代码之家  ›  专栏  ›  技术社区  ›  Jonas Söderström

QTP,通过标签访问QC字段

  •  5
  • Jonas Söderström  · 技术社区  · 15 年前

    我想在QC中使用field标签而不是名称来更新自定义用户字段

    目前我们是这样做的

    Set currentRun = QCUtil.CurrentRun
    currentRun.Field("RN_USER_03") = 1
    currentRun.Post
    

    Set currentRun = QCUtil.CurrentRun
    currentRun.Field("Data Rows Passed") = 4
    currentRun.Post
    

    但是我找不到方法来做。 有什么想法吗?

    2 回复  |  直到 14 年前
        1
  •  1
  •   TheBlastOne    15 年前

    暗示所有标签都是唯一的(我怀疑……):

    假设函数名为“GetNameOfLabel”,则调用者的代码如下所示:

    Set currentRun = QCUtil.CurrentRun 
    currentRun.Field(GetNameOfLabel ("Data Rows Passed")) = 1 
    currentRun.Post 
    

    当然,这个函数并不是很简单,但是在挖掘了QC数据模型并找到了一种通过SQL从DB获取名称的有效方法之后,就足够简单了。

    或者,该函数可以在数组或字典中查找名称,然后您必须维护该字典,但每次查找都不必转到数据库。

    缺点:

    • 如果标签不是唯一的,那么调试可能真的很“有趣”

    • 如果不缓存或预加载这些查询的SQL查询结果,那么所有脚本都会变慢;
    • 复杂性,因为您必须执行正确的SQL查询,并且您以一种非常特殊的方式依赖于QC的数据模型(升级时通常是一种恐惧)

    如果在数组或字典中查找:

    • 您要么必须维护它的初始化(打赌其他管理员添加cust字段会很容易忘记这一点),要么必须从QC的表中“加载”它(这有点像上面的SQL解决方案,并且有相同的缺点)。

    我会使用从db idea初始化的数组/字典。或者,如果你能接受已经提出的不变的想法,那就是一个很好的选择。考虑到在QCs定制脚本中没有独立于会话的作用域,SQL访问的思想可能真的会扼杀性能,因为它必须为每个新的用户会话执行。这就是为什么我也有这个不变的想法。

        2
  •  1
  •   Ricardo Cruz    9 年前

    Dim gFieldLabelToNameDICT: Set gFieldLabelToNameDICT = CreateObject("Scripting.Dictionary")
    gFieldLabelToNameDICT.CompareMode = vbTextCompare
    
    Function GetNameOfLabel (strFieldLabel)
        ' If it doesn't exist yet in fieldLabelToName dict -> search it using TDC and add it to the list to improve performance
        If Not gFieldLabelToNameDICT.Exists(strFieldLabel) Then
            Dim testSetFields As List
    
            Dim testSetFields: Set testSetFields = QCUtil.QCConnection.Customization.Fields.Fields("RUN")
            For Each aField in testSetFields
                If aField.UserLabel = strFieldLabel Then
                    gFieldLabelToNameDICT.Item(strFieldLabel) = aField.ColumnName
                End If
            Next aField
        End If
    
        GetNameOfLabel = gFieldLabelToNameDICT.Item(strFieldLabel)
    End Function
    

    也许你应该增加一些错误处理,比如我们考虑到标签找不到的情况。