Sunday, 25 August 2013

How to use ByRef parameter calling in Vb Scripting.

Most of the time automation personnel don't use the ByRef parameter functionality.
They use normal function calling with which is by default byVal.

Now actually most of the time tester don't know these two feature.so first I m gonna explain there two one by one.

1.ByVal Function calling.

Syntax:

var1=ADD(parameter1,parameter2)




Function ADD(val1,val2)

 val1=val1+1
  ADD=val1+val2


End Function


Function ADD(ByVal val1,ByVal val2)

 val1=val1+1
  ADD=val1+val2


End Function


now in this case the parameter calling is ByVal.In fact both of the statements are identical.

when we byval prefix , it means only a copy of the parameter is going within the function.Any Changes made within  the parameter wont reflect the in the actual called value.
but if we use below syntax


var1=ADD(parameter1,parameter2)
Function ADD(ByRef val1,val2)

 val1=val1+1
  ADD=val1+val2


End Function


in this case any changes made in val1 will reflect in parameter1 too.



QTP Tutorial

Hi Folks  a page is getting launched , which will be dedicated to QTP Tutorials
This is collect step by step process to learn QTP Automation, within BPT Framework.

A New Page Dedicated to DataBase Testing

Hi Folks this is a page which will be dedicated to Database Testing

A New Page Dedicated to HP-Quality Center

Hi Folks this is a page which will be dedicated to HP-Quality Center .
We will discuss about HP-QC/HP-ALM along with HP OTA related topics here

Function Calling In VB Scripting, use of parenthesis

In VB scripting we notice two type function call syntex as per below

syntex1
Object.func1 parm1,param2

syntex2
Object.func2(param1,param2)

Now the question is what is difference between these two syntax.The answer is quite simple , it depends on the context . NO matter what the function is , if you are going to assign the return value to some variable or the result of the function call is used as input for some other function then the function should have the parameters in parenthesis.

example
msgbox "Hi"
msgbox trim(" Hi ")

Tuesday, 11 June 2013

How to Get Column No for any field/ColumnName in WebTable

Below is a piece of code which should be part of ur .QFL file.this will return the column no for specfic cell text(in specfic row).
this is very essential function as by defect VBScript/QTP lib provide only row no not column for cell data


Function gettingColNo( tbleObj,ColName,RowNo) 
 colcount= tbleObj.ColumnCount(row)
  For colNum =1 To colcount
   ColHeader = tbleObj.GetCellData(RowNo,colNum)
   If inStr(Lcase(ColHeader),Lcase(ColName)) > 0 Then
    blnResult = True
    gettingColNo= colNum
    Exit For
   End If
  Next        
  If  colNum > colcount  Then
    blnResult = False
    'your custom code to hadle false condtion, like reporting to parent function or qc
  End If
End Function


How to Get a unique row in a webTable Object with Defined column Names

Recently I came across the situation where I need to insert a row in a table and then the validate the
same in the table, whether the row is successfully added or not.
I have written a piece of code which i think will be usefull for u guys in your projects as well.
This is a very common feature of PRPC framework based applications.In which almost everything is composed of Tables
Now there are the few thing we need to make sure that the row is added .

1. We need to check the row count of the table before the row is inserted.Which we can later
    compare  to the row count after the insertion.
2. Once we are sure that the row is added. we need to make sure we have the exact row added which
     we were supposed to .

now for this step 2 we can write a func. which we can use in projects.

I believe it will be usefull for u guys.






 Function Fn_UniqueFirstRow(tblObj,strColNames,strValues)

strRowNum="-1"
aryColNames=Split( strColNames,";")
aryValues=Split(strValues,";")
rowFound=False
rowCount=tblObj.GetROProperty("rows")
If rowCount>0 Then
 If UBound(aryColNames)=UBound(aryValues) Then
  colCount=UBound(aryColNames)
  For rowCounter=1 to rowCount
   '---compile the actual row Value for each row and compare
   MsgSTR=""
   For colCounter=0 to  colCount
    colName=Trim(aryColNames(colCounter))
    '----Now here I m expecting that you have some function to get column   
    '---number, 'if not i will be posting that as well later
    colNumber=Fn_ColumnNumber( colName,tblObj,1)
    colData=Trim(tblObj.GetCellData(rowCounter,colNumber))
      If colCounter=0 Then
        MsgSTR=colData
      Else
        MsgSTR=MsgSTR&";"&colData
     End If
    Next
    If StrComp(Trim(MsgSTR),Trim(strValues)) = 0 Then
     rowFound=True
     strRowNum=rowCounter&";"&" Unique is row found with given values"
     Exit For
    End If
  Next
   If  Not rowFound Then
    strRowNum="-1"&";"&"Unique row doesnt exist"
   End If    
   Else
    strRowNum="-3"&";"&"Col Names and col Values arent in same number"
   End If
  Else
   stRowNum="-2"&";"&"Table has no rows"
  End If
   Fn_UniqueFirstRow=strRowNum
 End Function