Thursday, March 31, 2011

Retrive the column data from database in vbscript


Function retrive_Column_Data()
    Dim fieldname1 As String
    Dim cntAs Integer
    Dim fieldsArr()
   
    cnt= 0
    Set rs = CreateObject("adodb.recordset")
  
    sqlquery = "enter here Select query"
    Set rs = CreateObject("adodb.recordset")
    rs.Open sqlquery, con
    rs.movefirst
   
    While Not rs.EOF
       
        cnt= cnt+ 1       
        rs.movenext
       
    Wend
   
    rs.movefirst
    ReDim testdatadetailsarr(cnt- 1)
   
    While Not rs.EOF
       
        For I = 0 To cnt- 1
            fieldname1 = rs("dbcolumnName_1")
            fieldname2=  rs("dbcolumnName_2")
            fieldsArr(I) = fieldname1 & "," & fieldname2
            rs.movenext
           
        Next
       
    Wend
   
    retrive_Column_Data= fieldsArr
    Set rs = Nothing
    Erase fieldsArr

End Function

Function to find row count from database in vbscript

Function rowCount()
   
    Dim cnt As Integer
   
    cnt = 0
   
    sqlquery = "enter here Select query"
    Set rs = CreateObject("adodb.recordset")
    rs.Open sqlquery, con
    If rs.BOF = False And rs.EOF = False Then
   
        rs.movefirst
   
        While Not rs.EOF
       
            cnt = cnt + 1
            rs.movenext
           
        Wend
       
    rowCount = cnt
    End If
    Set rs = Nothing
   
End Function

Adodb connection in vbscript

Function OpenDBConnect()
   
    Set con = CreateObject("adodb.connection")
    con .ConnectionString = "Enter here Connection string"
    con .Open

End Function

Wednesday, February 23, 2011

What is Transactions ?

Sometime you want to know the time script or part of script is taking time to execute in such case Transactions will help to find out.
You define transactions within your test by enclosing the appropriate sections of the test with start and end transaction statements.
How to Inserting Transactions
You define the beginning of a transaction in the Start Transaction dialog box.

·         click the step where you want the transaction timing to start point
·         Insert Start Transaction.
                    


·         The Start Transaction dialog box opens.
·         Enter Transaction name
·         Select radio button as per your need
 To insert a transaction before the current step, select Before current step.
 To insert a transaction after the current step, select After current step.
·         Click OK.
How to Ending Transactions
You define the end of a transaction in the End Transaction dialog box.
·         Click the step where you want the transaction timing to end.
·         Insert End Transaction. The End Transaction dialog box opens.
                         
  • The Name box contains a list of the transaction names you defined in the
Current test. Select the name of the transaction you want to end.
  • Select radio button, where to insert the end of the transaction:
                 To insert a transaction before the current step, select Before current step.
 To insert a transaction after the current step, select After current step.
  • Click OK.

Tuesday, February 22, 2011

What is Exists property in QTP

You can use Exist statements to wait for a window to open or an object to appear.
E.g Browser(“x”).page(“y”).webbutton(“z”).exists

Exists returns Boolean value. Basically, it is used for user define checkpoint

E.g
if Browser(“x”).page(“y”).webbutton(“z”).exists then
            Reporter.Report ,,”pass”
            Else
            Reporter.Report ,,”Fail”
End if

Difference between Exists and Wait
Exists:   Exists will wait till timeout, if object doesn’t exist and return false and start execution
Wait: Wait will wait till default time or user specific time and start execution.

What is Synchronization

Some time running application may not always respond with the same speed. Sometime due to server slow process your response will get late. How to handle such type of situation?

With the use of Synchronization concept in QTP
           
·         Use of Sync property:  You can insert a synchronization point, which tells QTP to pause the test until an object property achieves the value.

E.g. Browser(“x”).page(“y”).webbutton(“z”).sync

  • Use of Wait Statement: You can insert Exist or Wait statements that tell QTP to wait until an object exists or to wait a specified amount of time before continuing the test.
E.g.  
            Wait(10) or Wait // After 10 second, qtp start execution below statement
Browser(“x”).page(“y”).webbutton(“z”).sync

  • Increase timeout time: You can also increase the default timeout settings in the Test Settings and Options dialog boxes in order to tell QTP to allow more time for certain events to occur.
We can set from here File >> Settings >> Run, Increase Object Synchronization timeout limit.

Thursday, February 17, 2011

How to write in Excel Sheet


set xlapp = createobject("Excel.Application")
set wb = xlapp.workbooks.open("D:\test.xls")
set sh = xlapp.worksheets(1)
rc = sh.usedrange.rows.count
for j = 2 to rc

     ' write must be bases on condition
     sh.cells(j,2) = "pass"

Next

xlapp.Visible = True
wb.close
xlapp.quit
set xlapp = nothing