QTP成长园地

发布新日志

  • 指定行的数据进行比较

    2007-09-26 14:28:11

    在录制查询功能或者是添加,修改记录时,需要在列表页面比对显示数据是否与预期值一致。因此写一个比对函数。共享一下:

    '-----------------------------------------------------------------
    'function:compare array with data of row in Table
    'call method:
    'Input parameter: obj_SelPage: SelectPage  which is QTP WebList object
    '                 obj_Table:   Table  which is  QTP WebTable object
    '                 pageNo: Index of row in  pagelist which be compared with array
    '                         The first index in the list is numbered 0
    '                 rowNo:  Index of row in  table which be compared with array
    '                         The first index in the table is numbered 1
    '                 data_array: Type array
    '                 num: compare cells  which column is from 1 to num . 

    'For example in QTP:
    '            ExecuteFile  "..\..\Lib\Common.vbs"
    '            Dim  data_array(3)       
    '      data_array(0)=datatable("userID","Action1")
    '            data_array(1)=datatable("Department","Action1")
    '            data_array(2)=datatable("Descrīption","Action1")
    '            data_array(3)=datatable("Account_Expires","Action1")  
    '            call compare_list(obj_SelPage,obj_Table,1,5,data_array)       
    '-----------------------------------------------------------------
    Public Sub  compare_list(obj_SelPage, obj_Table,pageNo,rowNo,data_array,num)

     Dim result
      result=false
     obj_SelPage.Select "#"&pageNo  'go to that  page  in which   row  is compared
     colnum=obj_Table.GetROProperty("cols") 'get  the number of columns in table
     If num>colnum Then
      'MsgBox " input parameter [num] can't greater than colnum"
      Reporter.ReportEvent micFail,  "check_list_result", "input parameter [num] can't greater than colnum"
     
     Else
       For c=1 to num
         If  trim(data_array(c-1))<>trim(obj_Table.GetCellData(rowNo, c)) then
           Reporter.ReportEvent micFail,  "check_list_result", "Expect  result:" & data_array(c-1) & ", Display  Result:" & obj_Table.GetCellData(rowNo, c)
           result=false
         Else
               Reporter.ReportEvent micPass,  "check_list_result", "Expect  result:" & data_array(c-1) & ", Display  Result:" & obj_Table.GetCellData(rowNo, c)
            result=true
         End If
       Next
     End If                     
    End  Sub

     

  • 在qtp中通过string 查找并定位列表页数和行数的VBS函数

    2007-09-26 14:06:55

    今天写了一个qtp中的VBS函数,功能:通过传入字符串来 查找并定位在table列表中的页数和行数的。

    '-----------------------------------------------------------------
    'function:Find pageNo, rowNo of a string in Table
    'call method:define variable pageNo,rowNo in QTP before call this function
    'Input parameter: obj_SelPage: SelectPage  which is QTP WebList object
    '                 obj_Table:   Table  which is  QTP WebTable object
    '                 pageNo:  Return index of page which string is located in list
    '                          The first index in the list is numbered 0
    '                 rowNo:   Return index of row which string is located 
    '                          The first index in the table is numbered 1
    '                 strValue: A string which you will find in Table
    '                 col:     the column of table where string will match with
    '                          The first col in the table is numbered 1
    'Return value: 
    '                  false : not find string in table
    '                  true :  find string in table
    'For example in QTP:
    '            ExecuteFile  "..\..\Lib\Common.vbs"
    '            Dim  ipage,irow
    '            value=FindStrInTab(obj_Select1,obj_Table1,ipage,irow,"jane",1)
    '            If value=true then
    '              msgbox  ipage
    '              msgbox  irow
    '           
    '            End If         
    '-----------------------------------------------------------------
    Public Function FindStrInTab(obj_SelPage, obj_Table, byref pageNo,byref rowNo,strValue, col)
     FindStrInTab=false
     num= obj_SelPage.GetROProperty("items count")
     For i =0 to num-1
        If  obj_SelPage.Exist Then
          obj_SelPage.Select "#"&i
        End If
        If obj_Table.Exist Then
          tabNum=obj_Table.GetROProperty("rows")
        End If

        For j=2 to  tabNum
          If  trim(obj_Table.GetCellData(j, col))= trim(strValue) then
           pageNo=i
           rowNo=j
           FindStrInTab=true
          Exit For            
        End if
      Next
      If  FindStrInTab=true Then
           Exit For 
      End If
     Next
    End Function

  • 导入导出ORACLE数据

    2007-09-26 13:54:23

    在QTP录制过程中,可能需要备份数据来初始化应用。提供以下exp ,imp语句:
    用法:进入DOS命令界面(开始-〉运行-〉cmd),输入 exp imp 语句

    导入导出数据
    导出:exp username/pw @数据库服务名 file=数据库存放路径 [tables=需要导出的表名]

    比如:exp test/test@test  file=G:\test.dmp tables=admin,user

    导入:imp username/pw@数据库服务名 file=数据库存放路径 full=y | fromuser=从备份文件导出指定用户  touser=将数据导入数据库中指定用户

    比如:imp test/test@test  file=G:\test.dmp fromuser=test1 touser=test2

          imp test/test@test  file=G:\test.dmp full=Y

  • 如何将ORACLE中取出的DATE型格式化字符‘MM/DD/YYYY’

    2007-09-26 13:42:01

    如何将ORACLE中取出的DATE型格式化字符‘MM/DD/YYYY’

    调用to_char(date,'MM/DD/YYYY')

    例子:select to_char(EFF,'MM/DD/YYYY') from  CD 

  • QTP中对提示文字设检查点的问题

    2007-09-20 16:58:14

     今天打算录制输入非法数据,检测提示文字是否正确的功能。原本想很简单,只要选中文字设置textcheckpoint 就OK了。 但是在运行时,系统总是报找不到text对象, 原因是系统识别对象是通过text的前后文字来定位的, 然而我录制的页面中text前面是个input框,也就是说text前面的值是在变的,所以在run case 的时候,  text前面的值改变了也就识别不到了。

    解决办法:取文字的上级对象, 我取到的是个TD对象,然后将TD对象设置标准检查点,设置参数。并且在对象库中将该TD对象的innertext属性删除。就OK啦

  • select框中数据与数据库数据进行比较

    2007-09-19 17:15:54

    'Connect Oracle
    ExecuteFile  "..\..\Lib\DBOperation.vbs"
    Dim  Res,Cmd,sql,dbnum,selectnum 

    'select中的数据个数
    selectnum=Browser("Welcome to test").Page("Welcome to test").WebList("select").GetROProperty("items count")

    DBConnect()
    sql ="select  count(*) from admin_groups"
    ExecuteSql(sql)' Execute SQL
    dbnum= Res(0)'数据库中的数据个数

    If  dbnum<>groupnum   Then
        Reporter.ReportEvent micFail,"比对数据库 "," 比对结果与数据库中不一致"
    else
       sql1="select GROUPID  from admin_groups"
       ExecuteSql(sql1)
       i=1
       Do while not Res.eof
         If     trim(Browser("Welcome to test").Page("Welcome to test").WebList("select").GetItem(i))<>trim(Res(0))Then
         Reporter.ReportEvent micFail,"比对数据库"," 比对结果与数据库中不一致 "
         Exit Do
         End If
       Res.movenext
       i=i+1
       Loop

       If   i=dbnum+1   Then
        Reporter.ReportEvent micPass,"比对数据库"," 比对结果与数据库中一致 "
          End If
    End If

    DBClose()

  • QTP连接ORACLE 数据库VBS函数

    2007-09-19 16:49:39

    今天写了个QTP连接ORACLE 数据库函数的VBS,共享一下:

    DBOperation.vbs
    '-----------------------------------------------------------------
    'function:数据库连接
    'call method:在调用文件中先定义Res,Cmd
    'For example:Dim  Res,Cmd
    '             DBConnect()
    '-----------------------------------------------------------------
    Public Sub DBConnect()
          Dim StrCon
          Set Res = CreateObject("ADODB.Recordset")  
          Set Cmd = CreateObject("ADODB.Command")
          'Oracle
          StrCon ="DRIVER={Oracle in OraHome92};SERVER=test;UID=userid;PWD=password;DBQ=test;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=Lo;BAM=IfAllSuccessful;MTS=F;MDI=Me;CSR=F;FWC=F;PFC=6000;TLO=O;"
          Cmd.activeconnection=StrCon
          Cmd.CommandType =1
    End Sub
    '-----------------------------------------------------------------
    'function:执行SQL语句
    'Input parameter: StrSql
    'For example:Dim sql
    '             sql="select * from admin_groups"
    '             ExecuteSql(StrSql)           
    '---------------------------------------------------------

    Public Sub  ExecuteSql(StrSql)
     Cmd.CommandText=StrSql
     Set  Res = Cmd.Execute()

    End Sub

    '---------------------------------------------------------
    'function:关闭数据库
    'For example:DBClose()
    '---------------------------------------------------------
    Public Sub DBClose()
     Set Res=nothing
     Set Cmd.activeconnection=nothing
     Set Cmd=nothing
    End Sub

    调用例子:

    ExecuteFile  "c:\DBOperation.vbs"

    Dim  Res,Cmd

    DBConnect()  '调用连接数据库函数

    sql ="select  count(*) from admin_groups"

    ExecuteSql(sql) ' 调用执行sql函数

      Do while not Res.eof

          Msgbox(Res(0))

          Res.MoveNext

      Loop

    DBClose()  '调用关闭数据库

     

     

Open Toolbar