1. 第一种方法: 用GetROProperty("default value")
首先获取对象到本地。
其次,在对象下写以下代码:
mytest =Browser("主页名称").Page("主页名称").Frame("ext-gen218").WebEdit("id").GetRoProperty("default value")
MsgBox (mytest) ' 测试是否获取成功
’以下是把获取到的ID写到C盘下的1.txt文件中。
Const ForReading=1,ForWriting=2,ForAppending=8
Set fso = CreateObject("Scripting.FileSystemObject")
set openfile=fso.OpenTextFile("c:/1.txt",ForAppending,true)
openfile.WriteLine mytest
openfile.Close
Set fso=nothing '清空资源
’为其在result里能看到ID是否成功获取,写以下一条代码
Reporter.ReportEvent micPass,"pass","The ID can be output successfully"
第二种方法: 用传递参数的方式。应用Output
1) 在Active Screen 把ID对象加入到本地对象库中:right click>insert output value.
生成的语句:Browser("主页名称").Page("主页名称").Frame("ext-gen179").WebEdit("id").Output CheckPoint("id")
2)在所在action上定义输出参数: 在其所对应的action上(在testflow 窗口),right click>Action Properties>Parameters>在output paramenters 板块,定义两个输出参数: Name=aout; type=string.
注意:如果这个action 是子action,那么其父action也要定义一个output参数:
那怎么把子action传给父action呢? 其方法是在子action>right click>action call Properties>在output paramenters 板块,定义三个输出参数: Name=aout; type=string; Store In=bout.. 此时父action再定义这个bout参数就行了。
3)接下来这步关键。把这个参数设置成全局应用。File>Settings>output paramenters 板块, 定义两个输出参数: Name=aout; type=string.
4) 应用output参数。
executefile "C:\test.vbs"
ReadReocordToFile(Testargs("tSDout"))
5) test.vbs如下:
Function ReadReocordToFile(name)
Dim readstr
Dim fso, Testfile, testFolder, openfile, fso2
set fso = CreateObject("Scripting.FileSystemObject")
'创建fso对象
IF not fso.FolderExists("C:\test") Then
Set testFolder =fso.createFolder("C:\test")
End IF
Set Testfile = fso.openTextFile("C:\test\test.txt", 8, True, 0)
Testfile.WriteLine(name)
Testfile.Close
set fso2 = CreateObject("Scripting.FileSystemObject")
Set openfile=fso2.OpenTextFile("C:\test\test.txt",1,True,0)
Do Until openfile.AtEndOfStream
str=openfile.ReadLine(name)
Msgbox a(str)
Loop
openfile.Close
Set fso=Nothing
End Function
本文详细介绍了在QTP自动化测试中,如何通过两种方法获取文本框的值。第一种方法使用GetROProperty("default value"),结合FileSystemObject将值写入文本文件并验证。第二种方法利用Output参数,通过Active Screen插入输出值,定义并应用全局输出参数,最终在VBScript中读取并显示文本框的值。
2315

被折叠的 条评论
为什么被折叠?



