Showing posts with label WebTable. Show all posts
Showing posts with label WebTable. Show all posts

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 

Thursday, 25 April 2013

QTP: Handling WebEdit in WebTable Object.

Using web table in conventional WebApps Testing is quite uncommon.\
As we know all the WebButton, Webedits ,WebLists are ususallu linked with a webtable in webpage.
If we direct object validation for WebEdit as it may look like as below
UserName:  [     ]
Here [] represents the webedit.
Normally what people do is they add this webedit obj in there rep and do their validations. But in my opinion this is not a smart work.

We should access them from User Name field because this is how a Manual SME will see the Username name webedit. Because in approve stated approch webedit can be any where in page but next to username field and it will still be passed.

SO what should we do?????? Hmmm

right a function which handle the webtable it will get the value /Child tiem next to given cell data (In this case UserName)
Now when u pass the value "User Name" to func it you can access anything which is next to this field. By the use of functions u can get the falue /fill the value etc..
yes yes .. i know it will take alot of time to right the func for all cases.
but once it is written it is quite easy to use those in daily scripts.. and belive me your Test Case will req very low maintainence, as it wont be tackling webedit directly it is hadling the webtable, so it wont matter if the prop of Webedit chnages in future.