2016-11-21 74 views
0

我对QTP/UFT比较新。我正在编写测试,需要在同一测试中使用Global和本地数据表中的数据。QTP/UFT - 访问循环中的多个数据表

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 

我的列值都可以从两个片搞砸了。

回答

1

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

  • 您打电话给Datatable.GetSheet("Global"),但不能将它分配到任何地方。
  • 当你使用Datatable.GetRowCount你实际上并没有告诉UFT从哪个数据表中获得rowcount,这可能是你的问题之一。
  • 在代码的末尾,您使用的是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:准确定义什么数据即将从数据表,你可能要检查你的循环,以确保在您的逻辑是正确的,因为我没有检查那部分。让我知道这是否适合你。

快乐编码。

+1

感谢Victor的快速回复..这只适用于一个更改..我使用UFT 12.54,它不支持dtGlobal.Value(“Form”)。所以我用dtGlobal.GetParameter(“Form”)代替它 – phpfreak

+0

我很高兴它解决了。不幸的是我没有UFT了,所以我从[tutorialspoint](https://www.tutorialspoint.com/qtp/qtp_data_table_methods.htm)检查了方法,因为我不记得它,并且无法事先测试它。我建议您将此网站加入书签以备将来参考;) –

+0

当然,我确实。谢谢! – phpfreak