QTP/UFT - 循环访问多个数据表

QTP/UFT - Access multiple datasheets in loop

我对 QTP/UFT 比较陌生。我正在编写测试,需要在同一测试中使用来自全局和本地数据的数据 Sheet。

我的 for 循环是这样的:

Datatable.GetSheet("Global")
RowCount = Datatable.GetRowCount
For Cntr = 1 to RowCount
    Datatable.SetCurrentRow(Cntr)
    msgbox Datatable("Form", dtGlobalSheet) 'Form is my column Name from Global Data Sheet'

    Datatable.GetSheet("Action1")
    RowCount2 = Datatable.GetRowCount
    For Cntr2 = 1 to RowCount2
        Datatable.SetCurrentRow(Cntr2)
        msgbox Datatable("Number", dtGlobalSheet) 'Number is my column Name from Action1 Data Sheet'
    Next
Next

两张工作表中我的列值都乱七八糟。

您需要将数据表分配给变量,以便更好地使用它。

  • 您正在呼叫 Datatable.GetSheet("Global") 但未将其分配给任何地方。
  • 当您使用 Datatable.GetRowCount 时,您实际上并没有告诉 UFT 从哪个数据表获取行数,这可能是您的问题之一。
  • 在您的代码末尾,您使用的是 msgbox Datatable("Number", dtGlobalSheet),但您可能应该使用 msgbox Datatable("Number", dtLocalSheet)(假设您在代码中的某处分配了这些变量)。

检查这个可能的解决方案(未测试):

Dim dtGlobal : Set dtGlobal = Datatable.GetSheet("Global")
Dim dtLocal : Set dtLocal = Datatable.GetSheet("Action1")
RowCount = dtGlobal.GetRowCount
For Cntr = 1 to RowCount
    'Working with global datatable
    dtGlobal.SetCurrentRow(Cntr)
    msgbox dtGlobal.GetParameter("Form") 'Form is my column Name from Global Data Sheet'

    'Working with local datatable
    RowCount2 = dtLocal.GetRowCount
    For Cntr2 = 1 to RowCount2
        dtLocal.SetCurrentRow(Cntr2)
        msgbox dtLocal.GetParameter("Number") 'Number is my column Name from Action1 Data Sheet'
    Next
Next

PS.: 在准确定义了哪些数据来自哪个数据表之后,您可能需要检查您的循环以确保您的逻辑正确,因为我没有检查该部分。如果这对你有用,请告诉我。

编码愉快。