发布新日志

  • How to parameterize your link

    2006-12-22 02:38:45

    There is a better way to parameterize your link. We could utilize Descrīption object since it has 5 method following provided:

     Add Method

    Count Property

    Remove Method

    RegularExpression Property

    Value Property

      

    Let’s read info from a XML / Excel file first, and pass to Data Table.

    And then, extract the value from Data Table, put it into Descrīption object, then we could use it.

    In this way, we could easily maintain our application configuration (like hostname or URL) when the environment changed.

     

    Here is sample code

     

    *****************************************************

    For intLoop = 1 to N

        strText=DataTable.Value(...)

        Set LinkDesc = Descrīption.Create()

        LinkDesc ("Text").Value = strText

        Browser("").Page("").Link(LinkDesc).Click

        DataTable.GetSheet("").SetNextRow

    Next

    *****************************************************

     

  • How to connect to MySQL in QTP

    2006-12-22 02:37:00

    Since elements (links, data etc) on web page sometime are floating, so we need to select from database.

    Here I have made a paragraph of statement for DB connection and data selecting, and I have successfully connected with WEBDEV database. FYI.

     

    ****************************************************************************************

     Set Conn = CreateObject("ADODB.Connection" )

    str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=webdev;DATABASE=intranet;user id=root ; password=xxxxx"

    Conn.open str

    Set Rs = CreateObject ("ADODB.Recordset" )

    sql = "select * from `user`;"

    Rs.open sql,conn,1,3

    If (not Rs.eof) then

    Rs.MoveFirst

    ' show the first piece of record from user table'

    MsgBox Rs(0)

    MsgBox Rs(1)

    MsgBox Rs(2)

    MsgBox Rs(3)

    MsgBox Rs(4)

    MsgBox Rs(5)

    MsgBox Rs(6)

    end if

     Rs.close

    Set Rs = Nothing

    Conn.close

    Set Conn = Nothing

  • How to output MySQL data to a file

    2006-12-22 02:35:33

    This is the way how to output your MySQL result to a file:

     ********************************************************************************

     Set Conn = CreateObject("ADODB.Connection" )

    str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=webdev;DATABASE=intranet;user id=root ; password=xxxx"

    Conn.open str

    Set Rs = CreateObject ("ADODB.Recordset" )

    sql = "select * from `user` limit 5;"

    Rs.open sql,conn,1,3

     '**********  Define variable  *******

    Dim fso, myfile,i

    Set fso=CreateObject("scrīpting.FileSystemObject")

     '**********  Point TXT file name  *******

    Set myfile=fso.openTextFile("C:\result.txt",8,false)

     '**********  wtite to TXT file  *******

    While Not Rs.eof

         for i=1 to 6

                myfile.writeline Rs(i)

          next

         myfile.writeline " "

         Rs.movenext

    wend

     '**********  Close file  *******

    myfile.close

     '**********  Close result  *******

    Rs.close

     Set Rs = Nothing

    Conn.close

    Set Conn = Nothing

  • How to output MySQL value to your data table

    2006-12-22 02:33:24

    When we test our applications, we may want to check how the application performs the same operations with multiple sets of data. In general we use different set of data from data table to parameter test. So, here is the way how to select data from MySQL database and insert to data table.

     **************************************************************************************************

    Set Conn = CreateObject("ADODB.Connection" )

    'Set cmd = CreateObject("adodb.command")

     str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=webdev;DATABASE=intranet;user id=root ; password=xxxxxx"

    Conn.open str

    Set Rs = CreateObject ("ADODB.Recordset" )

    sql = "select * from `user` limit 1;"

    Rs.open sql,conn,1,3

     While Not Rs.eof

         For i=1 to 6

                '**********  write to data table

                DataTable("Intranet_user"&i,"Global") = Rs(i)

          next

                Rs.movenext

                DataTable.Export ("C:\user.xls")

    wend

    Rs.close

    Set Rs = Nothing

    Conn.close

    Set Conn = Nothing

     *************************************************************************************** 

  • How to parameter instance in QTP by using describing program

    2006-12-22 02:28:14

    Sometime, our tests need to be parameterized with multiple sets of data selected from database. For example:

     Browser("Browser").Page("Experiments Listing").Link("I-1019”).Click

    In this sentence, we’re trying to parameterize the link color in RED in order to locate specific record we want. Obviously, it is no way to parameterize the link directly on itself, because QTP need identify object from object repository when you run the test every time. If the object you’ve  parameterized doesn’t exist, error message alert.

     Firstly, we need to know the regular discipline of the link. It’s an ascending queue? descending queue? or sorted by date? by alphabet? by updated etc. and make your expression based on this.

     Subsequently, we intent to parameterized the link by using describing program and let QTP doesn’t look up object from object repository any more:

     Browser("Browser").Page("Experiments Listing").Link("text:=I-1019").Click

     Here I made a sample scrīpt for selecting Experiments record on RMTS, FYI.

    Notice, 1.make sure the data table “exp0” has existed

                2. change the configuration part in color RED to your own.

     

    '*************login the VPN

    Browser("Browser").Dialog("Connect to webdev").WinEdit("User name:").Set "Theravance\jfang"

    Browser("Browser").Dialog("Connect to webdev").WinEdit("User name:").Type  micTab

    Browser("Browser").Dialog("Connect to webdev").WinEdit("Password:").SetSecure "458702cde80f2dd36e8c89416e0012a10be23b658a410073fdafe5c9d530"

    Browser("Browser").Dialog("Connect to webdev").WinEdit("Password:").Type  micReturn

     '*************select data from MySQL database

    Set Conn = CreateObject("ADODB.Connection" )

    str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=webdev;DATABASE=intranet;user id=root ; password=xxxx"

    Conn.open str

    Set Rs = CreateObject ("ADODB.Recordset" )

    sql = "select * from `experiment` order by 'experimentID' desc limit 1;"

    Rs.open sql,conn,1,3

    While Not Rs.eof

         For i=0 to 0

    '************* write to data table

                                        DataTable("exp"&i,"Global") = Rs(i)

          next

                Rs.movenext

    wend

    Rs.close

    Set Rs = Nothing

    Conn.close

    Set Conn = Nothing

     ''************* locate the link by using programmatic descrīptions

    Dim i

    i=DataTable("exp0","Global")

    Browser("Browser").Page("Experiments Listing").Link("text:="&i).Click

Open Toolbar