念头、语言和行动的速度

发布新日志

  • qtp 问题汇总(转载)

    hbxtly 发布于 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.问题的解决。
    这个问题真是郁闷,其实产生的主要原因是在录制脚本的时候,qtp没有识别出来框架Frame中的对象,回放时找不到对象出错。
    解决办法:通过object spy 识别对象 并将其添加到对象库;然后在录制点击对象的一段脚本(或者自己写),再次回放就ok了。

    二、注意:datatable.Importsheet "D:\test\USER_INFO.xls",1,"Action1" 中,"Action1"一定要加双引号,要不然默认导入到Global中。

    三、自动启动qtp的vbscrīpt脚本。
    dim qtapp
    Set qtapp=createobject("QuickTest.application")
    qtapp.Launch
    qtapp.visible=true
    用法:将脚本卸载记事本文件中,文件格式保存为.vbs 点击直接运行。就可以自动启动qtp。


    四、修改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
Open Toolbar