度过了一个冬眠,在春末夏初之际,补充自己的营养,努力学习,努力工作!

qtp 问题汇总(转载)

上一篇 / 下一篇  2009-01-09 15:50:18 / 个人分类:转贴

一、Cannot find the "shoujian.projectname" object's parent "10_2" (class Frame). Verify that parent properties match an object currently displayed in your application.问题的解决。
2W!_~f3l"@d0这个问题真是郁闷,其实产生的主要原因是在录制脚本的时候,qtp没有识别出来框架Frame中的对象,回放时找不到对象出错。
!I#t To0Lo"T t0解决办法:通过object spy 识别对象 并将其添加到对象库;然后在录制点击对象的一段脚本(或者自己写),再次回放就ok了。51Testing软件测试网;BassPB1}H@

$J\'tIpMA3x,v0二、注意:datatable.Importsheet "D:\test\USER_INFO.xls",1,"Action1"中,"Action1"一定要加双引号,要不然默认导入到Global中。
9Dw'I V8d4VhZGE\0
$y]CJ {,Z0m;L4o:N:]#h0三、自动启动qtp的vbscrīpt脚本。51Testing软件测试网1Ea9l,U H(V
dim qtapp
Set qtapp=createobject("QuickTest.application")
qtapp.Launch
qtapp.visible=true51Testing软件测试网"lj"w*C|9z|S~%K
用法:将脚本卸载记事本文件中,文件格式保存为.vbs点击直接运行。就可以自动启动qtp。
:d~'HhaLw8h9P0
:gpsd\#W N051Testing软件测试网'ul } n.KT9l"\

四、修改QTP中对象的默认识别属性

WebCheckBox为例。
q7O,aABc\ F0QTP里面 ,选择Tools --> Object Identification...Environment选择Web,找到 
 WebCheckBox,看看QTP默认的识别WebCheckBox对象时使用的是哪些属性。可以修改识别WebCheckBox对象属性51Testing软件测试网6rK.@(\#|
注意: 修改只对以后录制的脚本起作用。
];p+lH)u,P0

五、QTP如何测试鼠标右键菜单

QTP附带的订票网站sample为例,edit控件username鼠标右键,点击paste(第4个菜单项)51Testing软件测试网*`7fmD!E4Q2@
51Testing软件测试网)[Mb.\D [*f+H
cur_replay_type = Setting.WebPackage("ReplayType")51Testing软件测试网$l@&|y7Q{"_x X1[
Setting.WebPackage("ReplayType") = 251Testing软件测试网@.G6P9uPx T4gV
Browser("Browser").Page("Welcome:MercuryTours").WebEdit("userName").Click 5,4, micRightBtn51Testing软件测试网W'f"Q.[7v"y8X
Setting.WebPackage("ReplayType") = cur_replay_type51Testing软件测试网EJ5Amc7qH j4k

t;a1myhq0index=4
m9a:m2gMm0Set WshShell = CreateObject("Wscrīpt.Shell")51Testing软件测试网zl0\A8|QRh)D
For i = 1 To index51Testing软件测试网J F6r.O Z8_pe M
  WshShell.sendKeys "{DOWN}"51Testing软件测试网l'`(dK iw`+] e D
Next
|zq[D `Y0WshShell.sendKeys "{ENTER}"
W9uH5\ G+@*x5p0Set WshShell = nothing
 

六、如何设置让对象库不产生重复对象

tools --options---web ---page/frame optinons
,j A/|] Tk6\ X0都选择第二项.就OK了.
 

七、QTP中用代码连接数据库

Set Conn = CreateObject("ADODB.Connection" )
+k S5zy$u"t#W0str="DRIVER=Oracle in OraHome92;SERVER=192.168.0.1;DBQ=testdb;user id=test; password=test"
Y'kj E5{}X0Conn.open str51Testing软件测试网xw.n2X8su?|r
Set Rs = CreateObject ("ADODB.Recordset" )
M.Z_(O6T lGY0sql = "select * from user_table t where table_name = 'XXX' "51Testing软件测试网.^T5x#EmVE_*_(a
Rs.open sql,conn',1,3
 

八、QTP测试页面字体颜色的办法

set ōbj =Browser().Page().WebElement().Object51Testing软件测试网)VIBk5l|p
' Get the  object
[BOQR2?0set iStyle= obj.currentstyle
:tLw\Z4j%n6A%tm0' Get the attribute
4iKv U&Cpw {0JY0sColor = iStyle.color
 

九、下拉菜单不能回放的解决方法

在录制时,比如打开记事本,点击下拉菜单 "文件"-->"退出";
t Vu4A$Q#^!_0回放时会出现 object not visible ;51Testing软件测试网SC,C [r!X#P2y
windows("记事本").click 193,11751Testing软件测试网6nT"K9Ybb#_0]
windows("记事本").winmenu("ContextMenu").Select "文件:退出"
%NX Tp$s\e@$T0
J"~+Kj8eK0QTP默认录制方式是无法录制下拉菜单的,必须修改设置后再录制51Testing软件测试网'ux%u3@9dd3{O&P
修改设置如下:51Testing软件测试网s,K^,]j
在tools -> web event recording configuration 点击custom settings... 展开Web objects,51Testing软件测试网-D~(U0c D-e Z3]
选种webelement,点击event -> add -> onmouseover 。并确定在record栏内,状态是enabled。51Testing软件测试网 g$?x-h0Qs c
然后再重新录制你的脚本。51Testing软件测试网3\a/D8uB
执行录制后的脚本,无法回放成功,这是因为脚本只录制了鼠标的onmouseover 事件,却没有录制click事
*r"bn tRG0件,所以脚本录制完后要手动添加click事件。
ZTKl@&C4Y0
 

十、QTP中如何识别带参数的链接?

QTP中如何识别带参数的链接?比如:"Browser("browser").Page("page").Link("href:=http://www.xxx.test/file/upload.php?matchable=0"
!Tt@i#th,j~051Testing软件测试网'^5l,i:C5x%X1d
特殊字符都需要用转义字符"\"来进行转义。

十一、如何让QTP运行时自动产生提示信息并自动确定?

Set WshShell = CreateObject("Wscrīpt.Shell")51Testing软件测试网.vO^J l,I;VM_
    WshShell.Popup "123456789", 2, "标题内容"
 

十二、QTP回放的过程中出现禁止运行控件提示的解决方法

修改QTP设置如下:toos-->options..-->Active Screen-->Advanced-->点选Load ActiveX controls
 

十三、从QC自动启动qtp如何自动加载插件

'此函数用于加载指定Test所有的插件,若要运行Test可自己加个qtApp.Test.Run
+z6@qf x+al#yAt0Function Load_Addins(testPath)51Testing软件测试网%n+M J IG+h8uix
      Dim qtApp 'As QuickTest.Application51Testing软件测试网\{v/jnAe:vc&}
      Dim blnNeedChangeAddins
UylcQiu0      Dim arrTestAddins
+WsQ!q f @]-}0      Set qtApp = CreateObject("QuickTest.Application")51Testing软件测试网q#{"q tPRF}
      arrTestAddins = qtApp.GetAssociatedAddinsForTest(testPath)51Testing软件测试网p|:k/X+~D
      blnNeedChangeAddins = False51Testing软件测试网 af9V%c*X6s
      For Each testAddin In arrTestAddins51Testing软件测试网a z&b#f,U9I5h
        If qtApp.Addins(testAddin).Status <> "Active" Then51Testing软件测试网&v*f&sR-G
          blnNeedChangeAddins = True
"~,r\0q9C)g1`L0          Exit For51Testing软件测试网+q [1KYH9p
        End If51Testing软件测试网g@ hK9r1l
      Next
7BL0P6s9^ aj0      If qtApp.Launched And blnNeedChangeAddins Then51Testing软件测试网g7}Q.b4M
        qtApp.Quit51Testing软件测试网7TKS@#C"u"a7xf
      End If
1{%j,a;yx/Q8d0      If blnNeedChangeAddins Then
dxC@XWBp0        Dim blnActivateOK
hH-}k.@ _#{0        blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescrīption)51Testing软件测试网S@$U s%jQiU KM
        If Not blnActivateOK Then51Testing软件测试网-z{T]1kzS
          Call ErrorLog(errorDescrīption)  '这里是调用自己的日志函数,可替换为自己的或注释掉51Testing软件测试网q:Cp Hc"|"RM&t
            Wscrīpt.Quit
4m.f3_|v*?r'm:r-S0        End If
,t-N8\;Zm(o jP]0      End If51Testing软件测试网.MP_2CA"U7x)}'wP
      If Not qtApp.Launched Then
p]"T|!{(Z)I0        qtApp.Launch
@R{4_FcU j J9R0      End If
J0U@A8ES"^0      qtApp.Visible = True51Testing软件测试网:MBJ x})z_ ~ b
      qtApp.Open testPath
n!X.uCvnm0'可在此加入qtApp.Test.Run来运行Test
3@n+GG5Bm*A!t?0      Set qtApp = Nothing
%E ^^X2E2S5e0End Function

TAG: 转贴

 

评分:0

我来说两句

Open Toolbar