Monday, April 15, 2013

Descriptive Programming



There are two ways to create Descriptive programming:
1.   By using description objects
2.   By using description Strings.

By using description objects:

By using this approach we create a description object and define the properties and values for identification.
     ‘Create Description object
     Dim btnObj
     Set btnObj=Description.Create
     btnObj(“Class Name”).value=”WinButton”
     btnObj(“text”) =”OK”

     Using above created DP object in script:

     Dialog(“text:=Login”).WinButton(btnObj).Click

     Script: Write a Script for Login by using description objects concept

     By using Description Strings:

By using this method of descriptive programming we don’t need to create a    description object, instead we use a description string to recognize the objects.
It means that we are maintaining object properties and their values in script itself.

Ex: Dialog(“text:=Login”).WinButton(“text:=OK”).click

Converting an OR based script to DP based script:

     OR based script:

     Dialog(“Login”).Activate
     Dialog(“Login”).WinEdit(“Agent Name:”).set “james”
     Dialog(“Login”).WinEdit(“Password:”).set “mercury”
     Dialog(“Login”).WinButton(“OK”).click

     DP based script:
              Script: Write a Script for Login by using description strings concept

     Dialog(“text:=Login”).Activate
     Dialog(“text:=Login”).WinEdit(“text:=Agent Name:”).set “james”
     Dialog(“text:=Login”).WinEdit(“text:=Password:”).set “mercury”
     Dialog(“text:=Login”).WinButton(“text:=OK”).click
     If Window(“Text:=Flight Reservation”).Exist Then
               Window(“Text:=Flight Reservation”).Close
     End IF

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

When to use Descriptive Programming



Below are some of the examples when Descriptive Programming is considered a good alternative to using a traditional Object Repository to define a test object:

1.   When the objects in the application are dynamic in nature and need special handling to identify them at runtime.
Ex: Clicking a object which changes according to the user navigation of the application
2.   When Object Repository is getting very large. If the size of Object Repository increases too much then it decreases the performance of QTP during runtime.
3.   When we don’t want to use an Object Repository at all.
4.   When modification to an OR object is required but the Object Repository in which the object resides in either Read Only or it is located in a shared OR and the changes may affect other scripts outside of our control.
5.   When we want to take action on large number of similar/uniform objects, for example we have 30 textboxes on a page and their names are in form of txt_1, txt_2 through txt_30. In this situation adding 30 entries to the Object Repository would not be a good programming approach, but using dynamically defined DP statements would be.

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

Difference between Actions and Functions




Actions are unique to QTP while functions are supported by both VB Script and QTP. Actions can optionally pass and receive input and output parameters. When used, input parameters must be passed first, followed by output parameters. A parameter cannot serve both as an input as well as an output parameter. In addition to supporting output parameters, Action can also return a value. An object/array can't be use as an action parameter. Lastly Actions are maintaining object repository where as functions are not.

Write a function to verify an Excel file is exists, if not create it.



Option Explicit
Dim fileSysObj,msExcelObj,msWorkBook
Dim msWorkSht

Function fileExist(filePath)

Set fileSysObj=CreateObject("Scripting.FileSystemObject")
fileExist=fileSysObj.FileExists(filePath)
If fileExist=True Then
                             msgbox "File is exists"
                             Set fileSysObj=Nothing
Else
                             Set msExcelObj=CreateObject("Excel.Application")
                             Set msWorkBook=msExcelObj.WorkBooks.Add
                             Set msWorkSht=msWorkBook.WorkSheets("Sheet1")
                             msWorkBook.SaveAs filePath
                             Set msWorkSht=Nothing
                             Set msWorkSht=Nothing
                             Set msExcelObj=Nothing
End If

End Function

Call fileExist("D:\sample1.xls")

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

Function parameter

Functions allow two types of parameter declaration.
    1. ByVal    2. ByRef

ByVal: Using ByVal parameter we pass the values to the function and use the values within the function.
    Any changes in the value will limit to the function.

ByRef: Using ByRef parameter we pass the reference of the parameter.
    Any changes made to the values inside the functions will be accessible in function as well as calling script.

    Note: ByRef parameter always be a variable name
     Note: If parameter type is not specified QTP will consider as the ByRef parameter.

Ex:  Function addition(Byval a,ByRef b)
       b=b+1
       msgbox b
       End Function

       k=10
       l=20
      Call addition(k,l)
      msgbox k               “returns 10
      msgbox l                 “returns 21



Return values in Functions:
    Declaring the parameters ByRef , we can returning values

Ex: Function Sample1(ByVal x,ByRef y)
          x=x+1
          y=y+1
          sample1=x+y
          msgbox x             'displays 11
          msgbox y             ' displays 21
       End Function

       k=10
       l=20
       val=sample1(k,l)
       msgbox val                    'displays 32
       msgbox k                       ' displays 10
       msgbox l                        ' displays 21

Note: Function name acts like a return variable and thus we can use function name for returning value.

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

User Defined Functions

Syntax:     Public | Private Function <Function Name> (parameters)

                <Statements>
                <Exit Function>
            End Function


Public: Indicates that the Function is accessible to all scripts.

Private: Indicates that the Function is accessible only to the script where it is declared

Function: It is a key word

Function Name: Name of the function

Parameters: List of variables that are passed to the function when it is called.

Statements: Any group of statements to be executed within the body of the Function procedure.

Exit Function: It causes an immediate exit from a Function.

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

Difference between Call to Copy Action and Call to Existing Action


Comment Call to Copy Call to Existing
Pre-requisite No Yes
Section in the test Action section External action section
Is action editable Yes No
Is data table editable Yes No
Is OR is editable Yes No
Statement RunAction “Copy of <Action name>”,One Iteration RunAction “ <Action name>[<test name>],OneIteration

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...