QTP学习笔记
1. What is the command in QTP to invoke IEBrow?
Thereare three ways to invoke IE browser and launch a website from QTP.
1.First we use the method called as "InvokeApplication"
Syntax:InvokeApplication "Path"
Example:invokeapplication "C:Program FilesInternet Exploreriexplore.exe"
(Thiswill launch IE browser)
Example:invokeapplication "C:Program FilesInternetExplorerIExplore.exe","www.google.com"
(Thiswill launch IE browser and also a particular web site like google.com)
Example:invokeapplication "C:Program FilesMercury InteractiveQuickTestProfessionalbinQTPro.exe"
(Thiswill invoke QTP)
2. Wewill use the "SystemUtil" object associated with a "Run"method
Syntax:SystemUtil.Run "Application/URL"
Example:SystemUtil.Run "iexplore.exe"
Example:Systemutil.Run "C:Program FilesInternetExplorerIExplore.exe","www.google.com"
Example:SystemUtil.Run http://www.google.com
(Herewhen you run this line of code systemutil.run executes a method called run bywhich the IE browser
isopened and also the url mentioned is launched. This is useful when you want QTPto directly launch the
websiteyou want in a single step)
3.When you want to invoke IE and then launch a url through script you can use theobject function linrary.
Syntax:Set IE1=CreateObject("InternetExplorer.Application")
IE1.visible=True
IE1.Navigate("sitename") /* with this you can navigate to the URL*/
Example:Set IE = CreateObject("InternetExplorer.Application")
IE.Visible= True
IE.Navigatehttp://www.google.com
2. Get current Action name
Environment.Value("ActionName")
Example:
Reporter.ReportEventmicFail,Environment.Value("ActionName") ,"实际输出:"&actualScale&",预计输出:"&expectedScale
3. 提取数字的正则表达式
SetregEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "[^0-9]"
regEx.Global=True
MsgBox regEx.Replace(“abc123456-78-9好吧”)
4. 移动光标的语句
DimdeviceReplayObject
SetdeviceReplayObject = CreateObject("Mercury.DeviceReplay")
CalldeviceReplayObject.MouseMove(0, 0)
5. 让组件可见
比如,一个组件需要滑动滚动条到页面的低端才能让其可见,可使用:
Browser(GISBrowser).Page(GISPage).WebElement(pMenu).MakeObjVisible
*MakeObjVisible方法能将不可见的组件滑动到可视范围、
*Scrolls an ActiveX object into view if it is not visible in thewindow.
6. 判断控件是否可见
等待判断控件是否可见,然后好进行下一步操作
If Browser(GISBrowser).Page(GISPage).WebElement(satelliteImage).WaitProperty("visible", "True", 20000)Then
Browser(GISBrowser).Page(GISPage).WebElement(pMenu).Click
wait(3)
Browser(GISBrowser).Page(GISPage).Link(cMenu).Click
End If
7. 等待浏览器变成完成状态
等待浏览器变成完成状态,页面有AJAX请求也是好使的
'等待浏览器的状态变成”完成“状态
Do While Browser(GISBrowser).Page(GISPage).Object.readyState<>"complete"
wait(1)
Loop