【问题标题】:UFT script using a data table runs only the first row repeatedly; doesnt consider the rest of the rows使用数据表的 UFT 脚本仅重复运行第一行;不考虑其余的行
【发布时间】:2019-08-05 13:12:02
【问题描述】:

我正在编写一个 UFT 脚本,该脚本从全局数据表中读取值并将值输入到文本框,然后执行验证。但是脚本只读取第一个值,而不是列中的其余值(并且运行相同的值 6 次)。我知道我遗漏了一些基本的东西,但不能指望它;你能帮忙吗?

length (data table)
-100
200
100.01
0
100
25

代码如下:

<opens the number dialog>

data_length = DataTable.GetRowCount 'returns 6 

for i=1 To data_length

swfWindow("main_client").SwfWindow("tallyDialog").WinEdit("Current Value: -000.00).Set DataTable.Value("length") 'expecting it to read and input first value.

swfWindow("main_client").SwfWindow("tallyDialog").ActiveX("Enter") 'click enter

avg_length = swfWindow("main_client").SwfWindow("tallyDialog").Check (Checkpoint("Value must be from 0 to 100))

If avg_length then

reporter.reportEvent micPass, "test passed"

Else

reporter.reportEvent micFail, "test failed"

End if

Next

我希望它对长度表中的所有 6 个值执行此迭代,但它对第一个值 (-100) 执行此迭代 6 次我缺少什么?

在 UFT 设置中将“在所有行上运行”更改为“仅运行一次迭代”也不起作用。

【问题讨论】:

    标签: datatable qtp hp-uft


    【解决方案1】:

    这里有几个问题需要考虑。这里有一些代码可以满足你的需要,然后是解释。

    首先,将您的测试设置为只运行一次迭代,因为您在这一次迭代中循环遍历数据表。如果要避免代码中的循环,则可以将其设置为“运行所有行”,它将遍历数据表。

    <opens the number dialog>
    
    data_length = DataTable.GetRowCount 'returns 6 
    
    for i=1 To data_length
        DataTable.SetCurrentRow(i)
        swfWindow("main_client").SwfWindow("tallyDialog").WinEdit("Current Value: -000.00).Set DataTable.Value("length") 'expecting it to read and input first value.
        swfWindow("main_client").SwfWindow("tallyDialog").ActiveX("Enter") 'click enter
        avg_length = swfWindow("main_client").SwfWindow("tallyDialog").Check (Checkpoint("Value must be from 0 to 100))
        If avg_length then
            reporter.reportEvent micPass, "test passed"
        Else
            reporter.reportEvent micFail, "test failed"
        End if
    Next
    

    注意循环开始处的DataTable.SetCurrentRow 命令,它将数据表行设置为循环索引i。这确保了每次循环时,数据表都会为循环的迭代选择正确的数据项。

    试一试,如果您仍然遇到问题,请在评论中发表您的问题,我会尽力提供进一步的帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多