调整IE浏览器窗口(转自http://www.51testing.com/?4696)

上一篇 / 下一篇  2007-06-18 17:15:49 / 个人分类:转贴

界面交互测试有时需要在一些测试脚本运行过程中调整IE浏览器窗口的尺寸和位置。QTP仅仅提供了浏览器窗口的最大化方法,即Browser("WebTesting\").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等。只要将创建对象处的参数加以调整就可以了。


TAG: 转贴

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-03  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 3689
  • 日志数: 7
  • 建立时间: 2007-06-13
  • 更新时间: 2009-04-01

RSS订阅

Open Toolbar