QTP - 指令碼相關收集

科敏發表於2014-03-18

1)生產隨機數列

    第一種方法
    randomize'更新反回的資料
    funcation rand(k,n)
    n="int((k-1)*rnd+1) rand=n
    end funcation
    
    第二種方法
    n="randomnumber.value(1,255)
    
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>

2)wintreeview一些操作


    選擇一個條目:wintreeview.select(item)'根是0
    根的名稱:wintreeview.getitem(0)

<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>

3)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 where table_name 'XXX' "
    Rs.open sql,conn',1,3

<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>

4)QTP如何測試滑鼠右鍵選單


    以QTP附帶的訂票網站sample為例,edit控制元件username滑鼠右鍵,點選paste(第4個選單項)

    cur_replay_type Setting.WebPackage("ReplayType")
    'Run mouse operations using the mouse, if using browser events
    Setting.WebPackage("ReplayType")    
    Browser("Browser").Page("Welcome: Mercury Tours").WebEdit("userName").Click micRightBtn
    Setting.WebPackage("ReplayType") cur_replay_type
    
    index=4
    Set WshShell CreateObject("Wscr&#299;pt.Shell")
    For To index
        WshShell.sendKeys "{DOWN}"
    Next
    WshShell.sendKeys "{ENTER}"
    Set WshShell nothing

<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>

5)QTP測試頁面字型顏色的辦法


    set &#333;bj Browser().Page().WebElement().Object
    Get the  object
    set iStyle= obj.currentstyle
    Get the attribute
    sColor iStyle.color

<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>

6)從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
    <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>

相關文章