Wednesday, April 10, 2013

Datatable methods




I) Add Sheet: Adds the specified sheet to the run time data table
          Datatable.AddSheet(“My Sheet”)

ii) Delete Sheet :  Deletes the specified sheet from the run time data table
          Datatable.DeleteSheet(“My Sheet”)

iii) Export : Saves a copy of the run-time Data Table in the specified location
          Datatable.Export (“C:\Vamsi.xls”)

iv) Export Sheet : Saves a copy of the specified sheet of run-time datatable in the specified location.
          Datatable.ExportSheet “C:\Vamsi.xls”,sheetid/”Sheet Name”

v) Get Current Row : Returns the current ( active ) row in the first sheet in the run-time data table (global sheet)
          msgbox Datatable.GetCurrentRow

vi) Get Row Count : Returns the total number of rows in required sheet
          msgbox Datatable.GetRowCount
          msgbox Datatable.GetSheet(“Local Sheet”).GetRowCount
          msgbox Datatable.GetSheet(“My Sheet”).GetRowCount

vii) Get Sheet : Returns the specified sheet from the run-time data table.
          Msgbox Datatable.GetSheet(“Local Sheet”)
          The following example uses the GetSheet method to return the “My Sheet” sheet of the run-time data table in     order to add parameter to it.
          Datatable.GetSheet(“My Sheet”).Addparameter “Time”,”10:00”

viii) Get Sheet Count : Returns total number of sheets in run-time data table.
          Msgbox Datatable.GetSheetCount

ix) Import : Imports the specified Microsoft Excel file to the run-time data table.
          Datatable.import (“C:Vamsi.xls”)

x) Import Sheet : Imports a sheet of specified file to a specified sheet in the run-time data table. The data in the imported sheet replaces the data in the destination sheet
          Datatable.importSheet “C:\Vamsi.xls”,1(sheet source), “Name”(destination)

x) Set Current Row : Sets the specified row as the current active row in the run-time data table
          Datatable.SetCurrentRow(2)


xii) Set Next Row : Sets the row after the current active row as the new current row in the run-time data table.
          Datatable.SetNextRow

xiii) Set Previous Row : Sets the row above the current active row as the new current row in the run-time table.
          Datatable.SetPrevRow   

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Verify Parameter (Column) existence in a Sheet



          Function isparameterExists()
                      On Error Resume Next
                      isparameterExists=True
                      Err.Clear
                      Set objSheet=Datatable.GetSheet(1).Getparameter("val123")
                      If Err.Number <>0 Then
                                isparameterExists=False
                      End If
                      msgbox isparameterExists
          End Function
          Call isparameterExists()

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Verify Sheet existence



          Method 1
Function isSheetExists()
                    On Error Resume Next
                    isSheetExists=True
                    Err.Clear
                    Set objSheet=Datatable.GetSheet("Global")
                    If Err.Number <>0 Then
                             isSheetExists=False
                    End If
                    msgbox isSheetExists
          End Function
          Call isSheetExists()

          Method 2
          shtCnt=Datatable.GetSheetCount
          For shtNum=1 to shtCnt
                   If Datatable.GetSheet(shtNum).Name=”Action1” Then
                             Msgbox “Action 1 sheet exist”
                   End If
          Next  

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

DataTable



A Data Table provides a way to create data driven test. It is similar to MS Excel spreadsheets and can be used to run an Action multiple times. Data table has one global data sheet which is accessible to all actions and each action has its own private data table also known as local data table. 

Types of Data Table:
There are 2 types of data table
 i) Design time data table :   A data table during script design time is known as design time data table.
              Note: Any changes to this are saved when the script is saved.

 ii) Run-time data table:  The run time data table contains a copy of the design time data table when a script is executed. It may contain values that are changed during script execution and are presented in the test result summary
          Note: The changes made to the data table during run-time are not saved to design time data table.

Setting data table iterations:
          To run a test case for some number of iterations we need to set the iterations of global data table in the Test Settings dialog, which is invoked using File → Settings → Test Settings window  → Run ( tab ) → Select required data table iterations radio buttons.
          Note: We can set the iteration settings for an Action call by going into the keyword view and then right clicking on the Action and selecting Action Call Properties

Accessing a data from the data table:

          msgbox datatable("val")
          msgbox datatable.GlobalSheet.getparameter("val").value
          msgbox datatable.GlobalSheet.getparameter("val").ValueByRow(2)
          msgbox datatable.value("val",dtGlobalSheet)
          msgbox datatable.Value("val",1)
          msgbox datatable.LocalSheet.Getparameter("val1").ValueByRow(2)
          msgbox datatable.GetSheet(2).Getparameter("val1").ValueByRow(2)

Entering data into data table:

          datatable.value("COLUMN NAME",dtGlobalSheet)=VALUE

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Monday, April 8, 2013

Bitmap check point

Bitmap check point is used to compare the bitmap files.

Script : Write a script to compare given bitmap files.

Optional Explicit
Dim filePath1,filePath2
filePath1=”D:\Vamsi\file1.bmp”
filePath2=”D:\Vamsi\file2.bmp”
Set bmpObj=CreateObject(“Mercury.FileCompare”)
compareResult=bmpObj.IsEqualBin(file1,file2,0,1)
If compareResult=0 Then
    Msgbox “not match”
    Else
        Msgbox “match”
    End If

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Text Area Check point

It is used for checking the text present in the specified area.

Navigation:

Keep the tool under record mode -> Insert menu ->check point -> Text area check point -> Select the desired text by using cross hair icon ->Click OK -> Select any options like Match case, Ignore spaces, Exact Match, Text not displayed -> Click OK

Coding Text area check point:

Script:
Ex: In Note Pad       
There is a QTP class
There is no prerequisite
There is a monitor

Now identify whether “is” exists between “class” and “no”

Option Explicit
Dim foundTxt, startPos, endPos
Dim substr, actualtxtpos

foundTxt=window("Notepad").WinEditor("Edit").GetVisibleText()

startPos=InStr(foundTxt,"class")
endPos=InStr(foundTxt,"no")

substr=mid(foundTxt,startPos,endPos + len(“no”))

actualtxtpos=InStr(substr,"is")
If  actualtxtpos<>0 Then
    Reporter.ReportEvent micPass,"text should be displayed","Text is displayed"
Else
    Reporter.ReportEvent micFail,"text should be displayed","Text is not displayed"
End If

Script: Write a script to extract file name, file path and drive letter

Option Explicit
Dim filePath,firstloc,driveName
Dim filePathVal,secondloc,filename
filePath=”D:\Vamsi\Test data\sample.xls”
    firstloc=Instr(filePath,"\")
driveName=mid(filePath,1,firstloc-2)
msgbox driveName
secondloc=InstrRev(filePath,"\")
filePathVal=mid(filePath,firstLoc+1,secondLoc-4)
msgbox filePathVal
fileName=mid(filePath,secondLoc+1,len(filePath)-secondLoc)
msgbox fileName

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Text check point

Text check point is used for checking the text present in the specified object.
Navigation :
Keep the tool under record mode ->Insert menu -> Check point -> Text check point -> select the desired object with handler pointer -> click OK -> select any option like Match, Ignore spaces, Exact Match, Text not displayed -> Click OK

Coding the Text check point:

We have to do the following for implementing text check point via code.

1.    Specify the text to be checked.
2.    Get the text visible on the application
3.    Check whether the expected text exists in the captured text.
4.    Report to QTP results.

Script: Verify “version 4.0’ text is displaying in Help

Option Explicit
Dim expText=”version 4.0”
Dim getText, txtPos
expText="Version 4.0"
getText= window("Flight Reservation").Dialog("About Flight Reservation").GetVisibleText()

txtPos=Instr(getText,expText)
If txtPos<>0 Then
    Reporter.ReportEvent micPass,"Text should be found","Text is found"
Else
    Reporter.ReportEvent micFail," Text should be found","Text is not found"
End If
   
    GetVisibleText() method: It returns the text that is visible on the object during runtime.
    InStr() function: It compare the actual text with expected text and returns the position.

    Script: Write a Script to count number of occurrences for a given string in actual string.

    Method 1
    Option Explicit
    Dim actualTxt,exptxt,indx,instCnt
actualTxt=”My name is James there is not pre-requisite for learning qtp”
    expTxt=”qtp”
    indx=0
    instCnt=0
    Do
        Indx=InStr(indx+1,actualTxt,expTxt)
        If indx > 0 Then
            instCnt=instCnt + 1
        Else
            Exit Do
        End If
    Loop While (True)
   
Method 2

Option Explicit
    Dim actualTxt,exptxt
actualTxt=”My name is James there is not pre-requisite for learning qtp”
    expTxt=”qtp”
msgbox (len(actualTxt)-len(Replace(actualTxt,expTxt,””)))/len(expTxt)


Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...