[QTP]Sample for TP: Login

主要的几个文件:

  • Configuration.xml:
    < Parameters >
        
    < Login >
            
    < txtLogin > Login </ txtLogin >
            
    < userName > Agent Name: </ userName >
            
    < password > Password: </ password >
            
    < btnOk > OK </ btnOk >
            
    < LoginExcep > Flight Reservations </ LoginExcep >
            
    < mainForm > Flight Reservation </ mainForm >
        
    </ Login >
    </ Parameters >

  • clsParameters.vbs:
    Class Parameters
        
    Private   xmlObj, root

        
    Private   sub  Class_Initialize()
            
    Set  xmlObj  =  XMLUtil.CreateXML()
            xmlObj.LoadFile(
    " Configuration.xml " )
        
    End Sub

        
    Private   Sub  Class_Terminate()
            
    Set  xmlObj  =   Null
        
    End Sub

        
    Public   Function  getValue(thePath)
            getValue 
    =  xmlObj.ChildElementsByPath(thePath).Item( 1 ).Value
        
    End Function

        
    Public   Sub  setValue(thePath, theValue)
            element 
    =  xmlObj.ChildElementsByPath(thePath).Item( 1 )
            element.setValue(theValue)
            xmlObj.SaveFile(
    " Configuration.xml " )
        
    End Sub

        
    Public   Function  getAllParameters(thePath)
            
    Dim  element, coll
            
    Set  coll  =  xmlObj.ChildElementsByPath(thePath)
            xcount 
    =  coll.Item( 1 ).ChildElements.Count()
            
    ReDim  arrParameters( CInt (xcount))
            
    For  I  =   1   to  xcount
                
    Set  element  =  coll.Item( 1 ).ChildElements.Item(I)
                arrParameters(I) 
    =  element.ElementName  +   " : "   +  element.Value
            
    Next

            getAllParameters 
    =  arrParameters
        
    End Function
    End  Class

    Function  SplitParameter(paras, element)
       
    Dim  arrItem, result, x
       
    For   Each  x  In paras
            arrItem 
    =   Split (x,  " : " 2 1 )
            
    If   UBound (arrItem)  >   0   Then
                
    If   arrItem( 0 =  element  Then
                    result 
    =  arrItem
                    
    Exit   For
                
    End   If
            
    End   If
       
    Next
        SplitParameter 
    =  result
    End Function

  • QTP的Action: actionLogin, 设置Action Call Property: Data table iterations为Run on all rows:
    ExecuteFile  " clsParameters.vbs "
    Dim  testId, allParameters, arrParameters
    Dim  tagMainForm, tagLogin, tagUserName, tagPassword, tagBtnOk, tagBoxException, tagErrMessage

    Set  allParameters  =   New  Parameters
    arrParameters 
    =  allParameters.getAllParameters( " /Parameters/Login " )
    tagMainForm 
    =   " text:= "   +  SplitParameter(arrParameters,  " mainForm " )( 1 )
    tagLogin 
    =    " text:= "   +  SplitParameter(arrParameters,  " txtLogin " )( 1 )
    tagUserName 
    =    " attached text:= "   +  SplitParameter(arrParameters,  " userName " )( 1 )
    tagPassword 
    =   " attached text:= "   +  SplitParameter(arrParameters,  " password " )( 1 )
    tagBtnOk 
    =    " text:= "   +  SplitParameter(arrParameters,  " btnOk " )( 1 )
    tagBoxException 
    =     " text:= "   +  SplitParameter(arrParameters,  " LoginExcep " )( 1 )
    tagErrMessage 
    =   " window id:=65535 "

    If  Window(tagMainForm).Exist  Then
        Window(tagMainForm).Close
    End   If

    If    not  Dialog(tagLogin).Exist  Then
        SystemUtil.Run 
    " flight4a.exe " , "" , " C:Program FilesMercury InteractiveQuickTest Professionalsamples lightapp " , " open "
    End   If

    With  Dialog(tagLogin)
        .Activate
        .Check CheckPoint(
    " Login " )
        .WinEdit(tagUserName).Set DataTable(
    " UserName_text " , dtLocalSheet)
        .WinEdit(tagPassword).Set DataTable(
    " Password_Text " , dtLocalSheet)
        .WinButton(tagBtnOk).Click
        
    If   .Dialog(tagBoxException).Exist( 3 Then
            
    With  .Dialog(tagBoxException)
                .Static(tagErrMessage).Check CheckPoint(
    " ErrMessage " )
                .WinButton(tagBtnOk).Click
            
    End   With
        
    ElseIf  Window(tagMainForm).Exist( 5 Then
            
    With  Window(tagMainForm)
                .Activate
                .Check CheckPoint(
    " Flight Reservation " )
            
    End   with
        
    End   If
    End   With

  • QTP中的DataTable:
    DlgException_Static_textUserName_textPassword_text
    Please enter agent name  
    Agent name must be at least 4 characters long.aa 
    Please enter passwordaaaa 
    Password must be at least 4 characters longaaaaaa
    Incorrect password. Please try againaaaaaaaa
     mercurymercury

结束。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值