领测软件测试网
软件测试工具QTP自动化测试Google地图
如何用QTP对Google地图进行自动化测试呢?因为Google地图是内嵌到浏览器里的ActiveX控件,那么我们的思路就是用vbscript调用Goolge地图的API,从而实现对内嵌Google地图的操作与验证!本文原文请见:http://www.advancedqtp.com/knowledge-base/articles/environment-techniques-id15/web-id34/automating-google-earth/。
【前置条件】
QTP加载WEB和ActiveX插件
IE7,并访问http://code.google.com/apis/earth/页面下载Google地图Plugin
熟悉Google地图的API(参见http://code.google.com/apis/earth/页面),以便脚本编程
【实例脚本】
该脚本实现了改变地图视图类型、显示Google地图控件、浏览纽约时区的一些操作。
MILY: Courier New; BACKGROUND-COLOR: #dddddd" align=center>
Const URL = "http://earth-api-samples.googlecode.com/svn/trunk/demos/kmlplayground/index.html" Const SW_MAXIMIZED = 3 ' 关闭当前浏览器后开启新的浏览器进入Google地图页面 SystemUtil.CloseProcessByName "iexplore.exe" SystemUtil.Run "iexplore.exe", URL, "", "open", SW_MAXIMIZED Browser("CreationTime:=0").Page("index:=0").Sync Set objActiveX = Browser("CreationTime:=0").Page("index:=0").ActiveX("progid:=GEPluginCoClass.GEPluginCoClass.1.0", "location:=0").Object
' 获取地图控件属性值 ALTITUDE_ABSOLUTE = objActiveX.ALTITUDE_ABSOLUTE VISIBILITY_SHOW = objActiveX.VISIBILITY_SHOW ALTITUDE_RELATIVE_TO_GROUND = objActiveX.ALTITUDE_RELATIVE_TO_GROUND MAP_TYPE_EARTH = objActiveX.MAP_TYPE_EARTH MAP_TYPE_SKY = objActiveX.MAP_TYPE_SKY SPEED_TELEPORT = objActiveX.SPEED_TELEPORT wait 2
' 改变SKY视图 Set geOptions = objActiveX.getOptions() Call geOptions.setMapType( MAP_TYPE_SKY ) wait 5 ' 改变EARTH视图 Call geOptions.setMapType( MAP_TYPE_EARTH )
' 以最大速度缩放视图 geOptions.setFlyToSpeed( SPEED_TELEPORT ) Set kmlLookAt = objActiveX.getView().copyAsLookAt( ALTITUDE_ABSOLUTE ) kmlLookAt.setRange(50000000) objActiveX.getView().setAbstractView(kmlLookAt) wait 2
' 显示可视化控件 geOptions.setGridVisibility( true ) geOptions.setStatusBarVisibility(true) geOptions.setScaleLegendVisibility( true ) geOptions.setMouseNavigationEnabled( true ) geOptions.setOverviewMapVisibility( true ) ' 返回定位控件 Set geNavigationControl = objActiveX.getNavigationControl() geNavigationControl.setVisibility( VISIBILITY_SHOW ) Set geView = objActiveX.getView() Set kmlLookAt = geView.copyAsLookAt( ALTITUDE_RELATIVE_TO_GROUND ) ' 设定显示速度、标题等 geOptions.setFlyToSpeed(0.5) kmlLookAt.setTilt(0) kmlLookAt.setHeading(0)
' 设定到纽约时区 kmlLookAt.setLatitude( 40.7594 ) kmlLookAt.setLongitude( -73.985 )
objActiveX.getView().setAbstractView(kmlLookAt)
'循环滚动地图 For i = 1 to 17 kmlLookAt.setRange(kmlLookAt.getRange() * 0.5) objActiveX.getView().setAbstractView(kmlLookAt) Wait 1 Next
Set objActiveX = Nothing |
文章来源于领测软件测试网 https://www.ltesting.net/
TAG:
google
Google
qtp
QTP
软件测试
自动化
地图