发布新日志

  • QTP: dom and bom [2009年11月11日]

    2009-11-11 10:14:21

    table.insertRow()
    table.deleteRow(<n>)
    table.rows(n)
    table.rows(n).cells(n)
    table,rows(n).insertCell
    table.rows(n).deleteCell

    待写
  • qtp:exit 函数

    2009-11-09 11:37:56

    1、ExitAction() 退出当前操作,无论其本地(操作)循环属性是什么。

    2、ExitActionIteration() 退出操作的当前循环。

    3、ExitComponent()退出当前组件并继续业务流程测试中的下一个组件,无论组件的循环设置是什么。

    4、ExitComponentIteration() 退出当前组件循环并继续该组件的下一次循环,或者,如果当前组件没有其他循环,则继续业务流程测试中的下一个组件。

    5、ExitGlobalIteration() 退出当前的全局循环,并使用全局数据表的下一行开始下一次循环。

    6、ExitRun() 退出测试,无论其全局循环属性是什么。

    7、ExitTest() 退出整个业务流程测试,无论运行时循环设置是什么。

    8、ExitTestIteration() 退出业务流程测试的当前循环并继续下一次循环,或者如果没有其他运行时参数循环,则退出测试运行。

    Exit Do Provides a way to exit a Do...Loop statement. It can be used only inside a Do...Loop statement. Exit Do transfers control to the statement following the Loop statement. When used within nested Do...Loop statements, Exit Do transfers control to the loop that is one nested level above the loop where it occurs.
    Exit For Provides a way to exit a For loop. It can be used only in a For...Next or For Each...Next loop. Exit For transfers control to the statement following the Next statement. When used within nested For loops, Exit For transfers control to the loop that is one nested level above the loop where it occurs.
    Exit Function Immediately exits the Function procedure in which it appears. Execution continues with the statement following the statement that called the Function.
    Exit Property Immediately exits the Property procedure in which it appears. Execution continues with the statement following the statement that called the Property procedure.
    Exit Sub Immediately exits the Sub procedure in which it appears. Execution continues with the statement following the statement that called the Sub.

  • qtp 抓屏并保存

    2009-10-21 18:22:51

    ' captureScreen: capture the screen image and save it as .png
    'Imagepath: the image path, such fxpg ,  "D:\ERM\Report\FXBS\FXPG"
    'imageSaveName: the image Name

    Function captureScreen(Imagepath, imageSaveName)
        Dim reportDay
        Dim imageFormat

        Set ifso = CreateObject("Scripting.FileSystemObject")
        reportDay = cstr(Date)
        imageFormat = ".png"
        imgFolderPath = Imagepath+backslant + reportDay
        
        If ifso.FolderExists(imgFolderPath) Then
            else
            ifso.CreateFolder(imgFolderPath)
        End If

        If ifso.FileExists(imgFolderPath +backslant+ imageSaveName +imageFormat) Then
            imageCout = imageCout +1
            If imageCout = 2 Then
                imageSaveName = imageSaveName + cstr(imageCout)
            End If       

            If imageCout>2 and imageCout =< 10 Then
                imageSaveName = left(imageSaveName, len(imageSaveName)-1) + cstr(imageCout)
            End If

            If imageCout>=10 and imageCout < 100Then
                imageSaveName = left(imageSaveName, len(imageSaveName)-2) + cstr(imageCout)
            End If     
            Set ifso = nothing
           
            captureScreen Imagepath, imageSaveName
           
        else
            desktop.CaptureBitmap imgFolderPath +backslant+ imageSaveName+imageFormat,Ture       
        End If
        Set ifso = nothing
    End Function
  • qtp: 初始化web系统

    2009-10-21 18:18:52

    Function initSystem()

       ' 关闭所有的 Excel文档
       On Error Resume Next
            Set excels = getObject(  ,"Excel.Application")
            For each excelBook in excels.WorkBooks
                 If instr(1, excelBook.FullName, "TestCase") > 0 or instr(1, excelBook.FullName, "TestData") > 0  Then
                     excelBook.Save
                     excelBook.Close
                 End If
            Next
        
            excels.Quit
            Set excels = nothing
        If Err <> 0 Then
            Reporter.ReportEvent micDone, "excel", "没有excel打开."
        End If
        closeSystem
    end Function

    Function closeSystem()
       If Browser("name:="+firstPageName).exist(5) Then
           Browser("name:="+firstPageName).Close
       End If
       closeIEprogress
    End Function

    ' 关闭ie浏览器进程
    Function closeIEprogress()
       Dim wmi,pro_s,p

        Set wmi=GetObject("winmgmts:\\.")
       
        Set pro_s=wmi.instancesof("win32_process")
       
        For Each p In pro_s
       
        if LCase(p.name)="iexplore.exe" then p.terminate()
       
        Next

    End Function
  • QTP:testcase和testcase的操作函数及模板

    2009-10-21 17:58:15


    Dim excelApp
    Dim excelWorkBook
    Dim excelSheet
    Dim fso 'fileSystemObject
    backslant = "\"


    FXPGTestCasePath = "D:\ERM\TestData\FXBS"
    FXPGTestResultPath = "D:\ERM\Report\FXBS\FXPG"


    FXBSTestCasefileName = "*****TestCase.xls"
    FXBSTestDatafileName = "*****TestData.xls"


    Function createExcelFile()
        set excelApp = CreateObject("Excel.Application")
        excelApp.Workbooks.Add
        excelApp.Visible = true
            
    End Function

    Function openExcell(filepath,fileName)
       set excelApp = CreateObject("Excel.Application")
       Set fso = CreateObject("Scripting.FileSystemObject")

        If not fso.FileExists(filepath+backslant+fileName) Then
            createExcelFile
            saveExcelFile excelApp, filepath,fileName
            else
            excelApp.Workbooks.Open(filepath+backslant+fileName)
            excelApp.Visible = true
        end if
        Set excelWorkBook = excelApp.ActiveWorkbook
        Set excelSheet = excelApp.ActiveSheet
       
    End Function

    '获取testcase的值
    Function writeActualResult(excelSheet,row, column, result)
       Set excelSheet = excelApp.ActiveSheet
       excelSheet.Cells(row, column) = result
    End Function


    Function closeExcel( filepathx,fileNamex)
           Set excelWorkBook = excelApp.ActiveWorkbook
        Set excelSheet = excelApp.ActiveSheet
           
        If not fso.FolderExists(filepathx) Then
            fso.CreateFolder(filepathx)
        End If

        If fso.FileExists(filepathx+backslant+fileNamex) Then
            If excelWorkBook.FullName = (filepathx+backslant+fileNamex) Then
                excelWorkBook.Save
            else           
                'fso.DeleteFile(filepath+backslant+fileName)               
                excelWorkBook.SaveAs filepathx+backslant+fileNamex
            end if
        End If

        excelWorkBook.Close   
        excelApp.Quit
        Set excelApp = nothing
        set fso = nothing
    End Function

    Function saveExcelFile( filepath,fileName)
        Set excelWorkBook = excelApp.ActiveWorkbook
        Set excelSheet = excelApp.ActiveSheet
       
        If excelWorkBook.FullName = (filepath+backslant+fileName) Then
            excelWorkBook.Save
            else
                Set fso = createObject("scripting.FileSystemObject")
       
                If not fso.FolderExists(filepath) Then
                    fso.CreateFolder(filepath)
                End If
           
                If fso.FileExists(filepath+backslant+fileName) Then
                    fso.DeleteFile(filepath+backslant+fileName)   
                End If       
                excelWorkBook.SaveAs filepath+backslant+fileName
               
        End If
    End Function

    Function exportFile(currentName, savefilename)

       If fso.FileExists(savefilename) Then
           fso.DeleteFile savefilename
       End If

       excelApp.Workbooks(currentName).SaveAs savefilename
    End Function
    ' for test case
    Dim caseIDColumn, testSummaryColumn, teststepColumn,exceptresultColumn, actualresultColumn, noteColumn
    caseIDColumn = 1
    testSummaryColumn = 2
    teststepColumn = 3
    exceptresultColumn = 4
    actualresultColumn = 5
    noteColumn = 6

    Function testSummary(sheetName,caseID)
       rows = excelApp.Worksheets(sheetName).UsedRange.rows.Count
       For i =1 to rows
           tempValue = excelApp.Sheets(sheetName).cells(i,caseIDColumn)
           If strcomp(trim(tempValue), trim(caseID)) =0 Then
               testSummary = excelApp.Sheets(sheetName).cells(i,testSummaryColumn)
               Exit for
           End If
       Next  
       If len(testSummary) = 0 Then
           reporter.ReportEvent micDone, "case","the case:"+caseID+"不存在"
       End If
    End Function


    Function teststep(sheetName,caseID, stepNo)
       rows = excelApp.Worksheets(sheetName).UsedRange.rows.Count

       For i =1 to rows
           tempValue = excelApp.Sheets(sheetName).cells(i,caseIDColumn)
           If strcomp(trim(tempValue), trim(caseID)) =0 Then
               teststep = excelApp.Sheets(sheetName).cells((i+stepNo-1),teststepColumn)
               Exit for
           End If
       Next  
    End Function


    Function exceptresult(sheetName,caseID, stepNo)
       rows = excelApp.Worksheets(sheetName).UsedRange.rows.Count

       For i =1 to rows
           tempValue = excelApp.Sheets(sheetName).cells(i,caseIDColumn)
           If strcomp(trim(tempValue), trim(caseID)) =0 Then
               exceptresult = excelApp.Sheets(sheetName).cells((i+stepNo-1), exceptresultColumn)
               Exit for
           End If
       Next  
    End Function

    Function actualresult(sheetName,caseID, stepNo, result)
       rows = excelApp.Worksheets(sheetName).UsedRange.rows.Count

       For i =1 to rows
           tempValue = excelApp.Sheets(sheetName).cells(i,caseIDColumn)
           If strcomp(trim(tempValue), trim(caseID)) =0 Then
               excelApp.Sheets(sheetName).cells((i+stepNo-1), actualresultColumn) = result
               Exit for
           End If
       Next  
    End Function

    Function note(sheetName,caseID, stepNo)
       rows = excelApp.Worksheets(sheetName).UsedRange.rows.Count

       For i =1 to rows
           tempValue = excelApp.Sheets(sheetName).cells(i,caseIDColumn)
           If strcomp(trim(tempValue), trim(caseID)) =0 Then
               note = excelApp.Sheets(sheetName).cells((i+stepNo-1), noteColumn)
               Exit for
           End If
       Next 

    End Function

    '获取testdata的值
    caseIDColumn = 1
    variableColumn = 3
    variableVauleColumn = 4

    Function getVariableValue(sheetName,startCaseID, endCaseID,variableName)
       Set excelSheet=excelApp.ActiveSheet
       rows = excelSheet.UsedRange.rows.Count

       For i =1 to rows
           tempValue = excelApp.Sheets(sheetName).cells(i,caseIDColumn)
           If strcomp(trim(tempValue), trim(startCaseID)) =0 Then
               startLine = i          
           End If

               tempValue = excelApp.Sheets(sheetName).cells(i,caseIDColumn)
           If strcomp(trim(tempValue), trim(endCaseID)) =0 Then
               endLine = i       
               Exit for
           End If
       Next 

       If startLine>= endLine Then
           Exit function
       End If

       For i = startLine to endLine
               tempValue = excelApp.Sheets(sheetName).cells(i,variableColumn)
            If strcomp(trim(tempValue), trim(variableName)) =0 Then
                getVariableValue = excelApp.Sheets(sheetName).cells(i,variableVauleColumn)
                Exit for
            End If
       Next
    End Function



    ' 实例
    sheetName = "testCaseData"
    startCaseID = "用例_001"
    endCaseID = "用例_002"

    openExcell FXPGTestCasePath, FXPGTestDatafileName

    url = getVariableValue(sheetName,startCaseID, endCaseID,"url")
    usename = getVariableValue(sheetName,startCaseID, endCaseID,"usename")
    password = getVariableValue(sheetName,startCaseID, endCaseID,"password")

    closeExcel FXPGTestCasePath, FXPGTestDatafileName

    sheetName = "用例"
    openExcell FXPGTestCasePath, FXPGTestCasefileName

    Reporter.ReportEvent micDonel, "用例概要", testSummary(sheetName,startCaseID)

    '' 1. 登陆系统;
    tempResult = login (url, usename,password)
    step = teststep(sheetName,startCaseID, 1)
    expectResult = exceptresult(sheetName,startCaseID, 1)
    If tempResult Then
        Reporter.ReportEvent micPass, step, expectResult
        actualresult sheetName,startCaseID, 1, "pass"
        else
        Reporter.ReportEvent micFail, step, "失败." + expectResult
        actualresult sheetName,startCaseID, 1, "failed"
        exitAction()
    End If

    closeExcel FXPGTestCasePath, FXPGTestCasefileName

    logoff
  • 关于点击checkbox,要用click()

    2009-10-20 10:49:58

    在qtp中:

    document.formName.checkboxName.click(); 测试通过
    ---------------------------------------------------------------

    document.formName.checkboxName.fireEvent('onclick') 测试失败, checkbox没有点击
  • innerHTML、innerText和outerHTML、outerText的区别

    2009-10-20 10:13:32

    innerHTML、innerText和outerHTML、outerText的区别

        * innerHTML 设置或获取位于对象起始和结束标签内的 HTML
        * outerHTML 设置或获取对象及其内容的 HTML 形式
        * innerText 设置或获取位于对象起始和结束标签内的文本
        * outerText 设置(包括标签)或获取(不包括标签)对象的文本

    对于一个id为"testdiv"的div来说,outerHTML、innerHTML以及innerTEXT三者的区别可以通过下图展示出来:
  • QTP: 如何获取所有打开的excel对象

    2009-10-09 12:21:51

    Set excels = getObject( ,"Excel.Application")

    For each excelWorkBook in excels.WorkBooks
        msgbox excelWorkBook.FullName
    Next
  • 为帮助保护您的安全,internet explorer

    2009-10-08 08:53:35

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN]
    "iexplore.exe"=dword:00000000

    将上述代码粘贴到文本编辑工具(譬如记事本)里,另存为 .reg后缀的注册表文件,双击导入即可解决

    如果是遨游浏览器,只需将遨游安装文件根目录下的sp2enable.reg导入注册表就能在maxthon中生效

    或者粘贴以下注册表代码:

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN]
    "maxthon.exe"=dword:00000000
  • qtp注意点

    2009-09-30 10:40:28

    1、函数和变量不能重名, 否则造成运行失败
    2、当使用createObject方法的时候, 一定记得释放空间, 否则出现内存不足的错误
    例如 Set fso = CreateObject("Scripting.FileSystemObject")
        Set fso = nothing
  • QTP的if 语句

    2009-09-28 12:00:06


    dim i
    i = 50
    If 100>= i =>1 Then   ' 100>= i =>1为 false
        msgbox i
    End If

    i =10
    If 10 =< i =<122 Then   ' 10 =< i =<122 为 true
        msgbox "kkk"
    End If

    运行结果为: 弹出对话框 kkk
  • vbs函数:遍历指定文件下,所有指定扩展名的文件

    2009-09-21 16:25:40

    Dim fso
    Dim pathName
    Dim files1, file1

    pathName="D:\ERM\"
     bianli pathName
    Function bianli(pathName)
       set fso=createobject("scripting.filesystemobject")
       set flr=fso.getfolder(pathName)
       Set files1 = flr.Files

        For each file1 in files1
            If strcomp(lcase( fso.GetExtensionName(file1)), "qfl") = 0 Then
                msgbox file1.path
            End If
        Next

        Set folders1 = flr.SubFolders

        For each folder1 in folders1
        
            bianli( folder1)
        Next

    End Function
  • Developers Guide to the Excel 2007 Application Object

    2009-09-16 23:42:39

    Developers Guide to the Excel 2007 Application Object

    http://msdn.microsoft.com/en-us/library/bb978780.aspx
  • 关于在QTP10.0中使用dom html

    2009-09-09 15:12:16

    Dim divs
    Dim div
    Dim input
    set divs = Browser("A").Page("b").Frame("c").Object.getElementsByTagName("Div")
    input = Browser("A").Page("b").Frame("c").Object.createElement("Input")
    input.type = "radio"
    For each div in divs
    div.appendChild(input)
    Next

    总结:如果使用dom语言,前面的结构要求一直
  • vbscript 哈希的用法 [2009年07月21日]

    2009-07-21 17:42:59

    <script. language="vbs">
       dim map,i,sKey,sVal
       set map=CreateObject("scripting.dictionary")
       map.add "key-1","val-1"
       map.add "key-2","val-2"
       map.add "key-3","val-3"   
       
       '通过key找值
       sKey=inputbox("请输入你要查找的关键字")
       if map.Exists(sKey)  then
        sVal=map.item(sKey)
        msgbox "您要找的值是:" & sVal
       else
        msgbox "您要查找的值不存在!" 
       end if
      
       '通过值找key
       dim isFind
       isFind=false
       for each key in map.keys
         if(map.item(key)="val-2") then
           isFind=true
           sKey=key
           exit for
         end if
       next   
      
       if isFind then
         msgbox "找到了对应的key为:"+sKey
       else
          msgbox "没有找到!"
      end if
      
       set map=nothing
    </script>
  • qtp9.2到 QTP10遇到的问题:无法识别window

    2009-07-14 17:57:55

    之前一直使用qtp9.2,知道昨天安装了最新的qtp10.0,遇到的第一个问题:qtp无法识别window

    解决方法:

    步骤:

    1、Automation -> Record and Run setings ->Windows Applications

    2、Check Record and run test on any open Windows-based application

    3、Click Ok

    之后运行代码,就ok了。

  • vbscript 数组在函数中传递

    2009-07-03 11:22:45

    <script. language="vbs"> 
    function array_concat(a1,a2)
     dim i,j,length,a()
     length=ubound(a1)-lbound(a1)+ubound(a2)-lbound(a2)+2
     redim a(length)
     
     
     for i=lbound(a1) to ubound(a1)
      a(i)=a1(i)
      next
      
      for j=lbound(a2) to ubound(a2)
      a(i)=a2(j)
      i=i+1
      next
     
     array_concat=a 
    end function

    dim a,b,c
    msgbox 1
    a=Array(1,2,3)
    b=Array(4,5,6)
    c=array_concat(a,b)

    msgbox Join(c,",")
    </script>

  • 纪录/回归自动化工具缺点

    2008-11-30 09:42:15

    1, 硬编码数值。如果有一个窗口值改变,则脚本不能通过。
    2,非模块编程。
    3,缺乏可重用的标准。
  • 如何选择用例

    2008-11-12 22:25:46

    在自动化过程,如何选择用例。
    1, 选择公用,执行次数多的用例
    2, 选择较稳定的模块的用例
    3。 选择手工测试工作不可能完成的或者是工作量大的,例如需要输入参数多的用例
    4。 选择重要的,产品的卖点的模块。
    5. 选择运动 有规律的测试。
    6. 基线测试 (基线的英文是baseline。一个已经被正式评审和批准的规格或产品,它作为进一步开发的一个基础,并且必须通过正式的变更流程来变更。)


    以上是我的理解,请大家多提建议,一起讨论,
593/3<123
Open Toolbar