qtp problem+solution

上一篇 / 下一篇  2011-02-15 16:36:57 / 个人分类:QTP


 一、Cannot find the "shoujian.projectname" object's parent "10_2" (class Frame). Verify that parent properties match an object currently displayed in your application.问题的解决。
 这个问题真是郁闷,其实产生的主要原因是:在录制脚本的时候,qtp没有识别出来框架Frame中的对象,回放时找不到对象出错。
 解决办法:通过object spy 识别对象 并将其添加到对象库;然后在录制点击对象的一段脚本(或者自己写),再次回放就ok了。
 
 二、注意:datatable.Importsheet "D:\test\USER_INFO.xls",1,"Action1" 中,"Action1"一定要加双引号,要不然默认导入到Global中。
 
 三、自动启动qtp的vbscript脚本。
 dim qtapp
 Set qtapp=createobject("QuickTest.application")
 qtapp.Launch
 qtapp.visible=true
 用法:将脚本卸载记事本文件中,文件格式保存为.vbs 点击直接运行。就可以自动启动qtp。
 
 四、 描述性编程中出现“The “[WinEdit]”object's description ,matches more than one of the objects currently displayed in your appliction.Add addtional properties to the objects ddescription in order to uniquely identify the object.”中问题的解决。
 
   这个问题看起来其实很简单就是在QTP描述过程中,发现匹配该对象的属性多于1个,因此无法正确匹配,所以QTP报错。错误如图下:
 
 
 问题解决方法:
 添加更多的对象属性,以便正确匹配,在对象查看器点击该对象(我的是password对象),点击
 ,查看对象的属性,添加更多的属性,如:window id 等。同时将脚本修改为:
 Dialog("Login").WinEdit("attached text:=Password:","window id:=3001").Set "cheers_lee"
 注意红色字体部分,我是同个两个属性匹配WinEdit的,一个是attached text另一个是window id。再次运行脚本,测试通过OK!强调的是attached text和window id 是对象的属性,通过对象查看器可以看到。
 五、修改QTP中对象的默认识别属性
 以WebCheckBox为例。
 在 QTP里面 ,选择Tools --> Object Identification...Environment选择Web,找到  WebCheckBox,看看 QTP默认的识别WebCheckBox 对象时使用的是哪些属性。可以修改识别WebCheckBox对象的属性。
 注意: 修改只对以后录制的脚本起作用。
 六、QTP如何测试鼠标右键菜单
 以QTP附带的订票网站sample为例,edit控件username鼠标右键,点击paste(第4个菜单项)
 
 cur_replay_type = Setting.WebPackage("ReplayType")
 Setting.WebPackage("ReplayType") = 2
 Browser("Browser").Page("Welcome: Mercury Tours").WebEdit("userName").Click 5,4, micRightBtn
 Setting.WebPackage("ReplayType") = cur_replay_type
 
 index=4
 Set WshShell = CreateObject("Wscrīpt.Shell")
 For i = 1 To index
     WshShell.sendKeys "{DOWN}"
 Next
 WshShell.sendKeys "{ENTER}"
 Set WshShell = nothing
 
 七、如何设置让对象库不产生重复对象
 tools --options---web ---page/frame. optinons
 都选择第二项.就OK了.
 
 八、QTP中用代码连接数据库
 Set Conn = CreateObject("ADODB.Connection" )
 str="DRIVER=Oracle in OraHome92;SERVER=192.168.0.1;DBQ=testdb;user id=test; password=test"
 Conn.open str
 Set Rs = CreateObject ("ADODB.Recordset" )
 sql = "select * from user_table t where table_name = 'XXX' "
 Rs.open sql,conn',1,3
 
 九、QTP测试页面字体颜色的办法
 set ōbj = Browser().Page().WebElement().Object
 ' Get the  object
 set iStyle= obj.currentstyle
 ' Get the attribute
 sColor = iStyle.color
 
 十、下拉菜单不能回放的解决方法
 在录制时,比如打开记事本,点击下拉菜单 "文件"-->"退出";
 回放时会出现 object not visible ;
 windows("记事本").click 193,117
 windows("记事本").winmenu("ContextMenu").Select "文件:退出"
 
 QTP默认录制方式是无法录制下拉菜单的,必须修改设置后再录制
 修改设置如下:
 在tools -> web event recording configuration 点击custom settings... 展开Web objects,
 选种webelement,点击event -> add -> onmouseover 。并确定在record栏内,状态是enabled。
 然后再重新录制你的脚本。
 执行录制后的脚本,无法回放成功,这是因为脚本只录制了鼠标的onmouseover 事件,却没有录制click事
 件,所以脚本录制完后要手动添加click事件。
 
 十一、QTP中如何识别带参数的链接?
 QTP中如何识别带参数的链接?比如:"Browser("browser").Page("page").Link("href:=http://www.xxx.test/file/upload.php?matchable=0"
 
 特殊字符都需要用转义字符"\"来进行转义。
 十二、如何让QTP运行时自动产生提示信息并自动确定?
 Set WshShell = CreateObject("Wscrīpt.Shell")
        WshShell.Popup "123456789", 2, "标题内容"
 
 十三、QTP回放的过程中出现禁止运行控件提示的解决方法
 修改QTP设置如下:toos-->options..-->Active Screen-->Advanced-->点选Load ActiveX controls
 
 十四、从QC自动启动qtp如何自动加载插件
 '此函数用于加载指定Test所有的插件,若要运行Test可自己加个qtApp.Test.Run
 Function Load_Addins(testPath)
         Dim qtApp 'As QuickTest.Application
         Dim blnNeedChangeAddins
         Dim arrTestAddins
         Set qtApp = CreateObject("QuickTest.Application")
         arrTestAddins = qtApp.GetAssociatedAddinsForTest(testPath)
         blnNeedChangeAddins = False
         For Each testAddin In arrTestAddins
             If qtApp.Addins(testAddin).Status <> "Active" Then
                 blnNeedChangeAddins = True
                 Exit For
             End If
         Next
         If qtApp.Launched And blnNeedChangeAddins Then
              qtApp.Quit
         End If
         If blnNeedChangeAddins Then
             Dim blnActivateOK
             blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescrīption)
             If Not blnActivateOK Then
                 Call ErrorLog(errorDescrīption)  '这里是调用自己的日志函数,可替换为自己的或注释掉
                   Wscrīpt.Quit
             End If
         End If
         If Not qtApp.Launched Then
             qtApp.Launch
         End If
         qtApp.Visible = True
         qtApp.Open testPath
 '可在此加入qtApp.Test.Run来运行Test
         Set qtApp = Nothing
 End Function

TAG:

 

评分:0

我来说两句

Open Toolbar