|
界面交互测试有时需要在一些测试脚本运行过程中调整IE浏览器窗口的尺寸和位置。QTP仅仅提供了浏览器窗口的最大化方法,即Browser("Web Testing\").FullScreen,但是并没有提供其他的改变窗口尺寸和位置的方法。
依靠QTP本身提供的有限方法是不够的,可以利用VBscrīpt语言和QTP的描述性编程实现对IE浏览器窗口的尺寸和位置的控制。代码如下:
'Open an IE browser with the method CreateObject()
Dim objIE, hwndIE
Set ōbjIE = CreateObject("internetexplorer.application")
objIE.Visible = true
objIE.Navigate URL 'The parameter URL is the destination address for the IE browser
'Wait a while till the page is fully loaded
Wait(10)
'Move and resize the browser
hwndIE = objIE.HWND
'Operate the IE browser as a window object with descrīptive programming
'The window object can be uniquely identified by the parameter hwndIE, which is the window's handle of the browser
Window ("hwnd:=" & hwndIE).Activate
Window ("hwnd:=" & hwndIE).Move intPosX, intPosY 'intPosX and intPosY represent the new location for the IE browser
Window ("hwnd:=" & hwndIE).Resize intSizeX, intSizeY 'intSizeX and intSizeY represent the new size for
'Release the object after the adjustment
Set ōbjIE = nothing
除了IE浏览器之外,这样的代码同样适用于其他被测的应用程序,如Word、Excel等。只要将创建对象处的参数加以调整就可以了 |
|