QTP tips

上一篇 / 下一篇  2009-05-05 01:18:42

1.我下载了一个新的试用版本,但是不能使用
  你的机器上是否安装了老的版本的QTP?如果安装了老的版本也会有问题的。你可以把QTP安装在没有安装QTP的机器上。
2.如何在QTP中使用API?
'声明FindWindow方法
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString

'获得记事本窗体的Handle
hwnd = Extern.FindWindow("Notepad", vbNullString)
if hwnd = 0 then
    MsgBox "Notepad window not found"
end if
'改变记事本窗体的标题
res = Extern.SetWindowText(hwnd, "PCL")

3.动态打开IE

创建StartUrl 环境变量
StartURL = Environment("StartUrl")
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = true
IE.Navigate StartURL

4.如果我随机调用不同的函数如何实现
x = some random number
select case x
 case 1call function1
case 2
 call function2
case
   else'error handlingend
end select

5.通过命令行启动应用程序
Set ōShell= CreateObject ("Wscrīpt.shell")
oShell.run "cmd /K CD C:\Winnt\system32 & calc.exe"
Wait(1)
Set ōShell = Nothing

6.如何添加验证点
步骤1. Add object to the object repository
步骤2. use the GETROproperty()
步骤3. retrive the value of one property of an object
步骤4. compare manually

7.如何禁止运行结束之后显示测试结果?
禁止脚本运行结束之后显示测试结果
1. Go to Tools -> Options.
2. Select the Run tab.
3. Clear the "View results when run session ends" checkbox.
4. Click <OK>.
激活运行结束之后显示测试结果
1. Go to Tools -> Options.
2. Select the Run tab.
3. Select the "View results when run session ends" checkbox.
4. Click <OK>.

8.QuickTestPro中是否可以编写调试vb代码?
   不可以在QTP的Expert view中写入VB代码,但是你可以写vbs代码。vbs代码的语法和vb很类似,很多的vb函数可以在vbs中调用,但这不代表qtp中可以写vb的代码。
 

9.怎样通过GetWindowThreadProcessId从window的句柄得到线程的ID。
代码
MyVarPtr = 0
extern.Declare micLong,"GetWindowThreadProcessId","user32.dll","GetWindowThreadProcessId", micLong , micLong+micByRef
MyVarPtr = 0
pid = extern.GetWindowThreadProcessId (hWnd, MyVarPtr)

10.如何进行文件对比?
Set fso = CreateObject("scrīpting.FileSystemObject")
Set file1 = fso.OpenTextFile("C:\file1.txt", 1)
Set file2 = fso.OpenTextFile("C:\file2.txt", 1)

if file1.readall=file2.readall then
msgbox "Files are equal"
else
msgbox "Files are not equal"
end if

11.如何对比两个xml文件?
Set doc = XMLUtil.CreateXML()
doc.LoadFile "c:\example.xml"
Set doc1 = xmlutil.CreateXML()
doc1.Load doc.ToString
Set doc2 = doc.Clone()
res = doc1.Compare(doc2,resultDoc,micXMLValues+micXMLCDataSections)
if res = 1 then
 msgbox "Documents match :-)"
else
 msgbox "Documents do not match :-("
end if

12.如何使用Excel对象处理数据?
Dim xl
打开excel文件
Function OpenExcelFile(strFilePath)
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open strFilePath
End Function
获得指定单元格数据
Function GetCellData(strSheet,rwIndex,colIndex)
GetCellData = xl.WorkSheets(strSheet).Cells(rwIndex,colIndex)
End Function
填充单元格数据
Function PutCellData(strSheet,rwIndex,colIndex,varData)
xl.WorkSheets(strSheet).Cells(rwIndex,colIndex) = varData
End Function
保存并推出
Function SaveAndQuit()
xl.Activeworkbook.save
xl.Quit
Set xl = nothing
End Function

13.QuickTestPro版本多少
QTP Major releases
5.6 (branded Astra QuickTest I believe)
6.0
6.5
8.0
8.2
9.0

14.如何更新classpath?
Set Sh = CreateObject("Wscrīpt.Shell")

key =  "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\CLASSPATH"

Sh.RegWrite key ,  Sh.RegRead(key) & ";C:\Oracle\Ora92\jdbc\lib\classes12.zip"


15.回放的过程中提示"Unable to launch the browser. The specified browser is not installed"
Certain installation combinations of IE 5.x or upgrades to IE 6.x and QuickTest Professional may result in the inability of QTP to launch IE and result in the error message, "Unable to launch the browser. The specified browser is not installed." A workaround is to make a copy of the "IEXPLORE.EXE" loader stub found in "<drive>:\Program Files\Internet Explorer\..." and place it in the "<drive>:\WINNT" subdirectory. In addition, the following registry key and string values must be added (if absent) to maintain backward compatibility:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE]
"Path"="D:\\Program Files\\Internet Explorer\\"
@="D:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"


TAG:

 

评分:0

我来说两句

Open Toolbar