English 中文(简体)
QTP, access to QC field by label
原标题:

I want to update a custom user field in QC using the Label of field instead of the name

At the moment we are doing it this way

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

But I would like to do it this way

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

But I can t find the method to do it with. Any Ideas?

最佳回答

Implying all labels are unique (which I doubt..):

You could create a function which accepts a label, searches in QC s tables that define customized fields for the correct field definition, and returns the field name. Then use the function s result value as the indexed property s index.

Suppose that function would be called "GetNameOfLabel", then the Caller s code would look like:

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

Of course, the function would not really be trivial, but easy enough after some digging in the QC data model and finding an efficient way to fetch the name from the DB via SQL.

Or, the function could look up the name in an array, or a dictionary, then you would have to maintain that dictionary, but you would not have to go to the database for each lookup.

Disadventages:

  • Scripts with the wrong label might be harder to be debug
  • If labels are not unique, it might be real "fun" to debug

If looking up on the DB:

  • All scripts slow down if you don t cache, or pre-load, SQL query results for those lookups;
  • complexity, as you have to do the right SQL query, and you depend on QC s data model in a quite peculiar way (usually a horror when you re upgrading)

If looking up in an array, or dictionary:

  • You either must maintain its initialization (bet other admin guys adding a cust field will forget that easily), or must "load" it from QC s table (which is a bit like the SQL solution above, and has the same downsides).

I d go with the array/dictionary-initialized-from-db-idea. Or, if you can live with the constant idea already presented, that one is a good bet. Considering that there is no session-independent scope in QCs customizing scripts, the SQL access idea might really kill performance because it would have to be executed for every new user session. Which is why I, too, +1 d the constant idea.

问题回答

Look at this:

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

Maybe you shall want to add some more error handling, such us considering the case that the label is not found.





相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签