调整IE浏览器窗口

上一篇 / 下一篇  2007-06-05 09:21:46 / 个人分类:QTP

界面交互测试有时需要在一些测试脚本运行过程中调整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等。只要将创建对象处的参数加以调整就可以了。

TAG: QTP

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-28  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 21093
  • 日志数: 17
  • 图片数: 1
  • 建立时间: 2007-04-26
  • 更新时间: 2007-09-06

RSS订阅

Open Toolbar