Tuesday, April 16, 2013

Utility Objects


1. The Crypt Object:
This object encrypts strings in a format that the QTP SetSecure function understands

myVar=Crypt.Encrypt(“mercury”)
msgbox myVar

2. The OptionalStep object:
This object is used to make a statement optional in situation where the statement might fail.

     OptionalStep.Window(“Flight Reservation”).WinButton(“Insert Order”).click

3. The pathfinder Object
This object is used to find the absolute path to a file. 

Through navigation: QTP allows setting folder paths in the Tools OptionsFolders
During run time: 
Msgbox  PathFinder.Locate(“<path of the file to be searched>”)

4. The RandomNumber object:
This object provides a method to get a random number between two specified values.
Msgbox RandomNumber(1,100)

5. The SystemUtil object:
This object is used to run and close process. Below are few examples of starting process;

‘Run internet explorer
SystemUtil.Run “iexplore.exe”

‘Run internet explorer and pass the starting URL
SystemUtil.Run “iexplore.exe”, http://www.gmail.com

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

Script to find total number of winEdits in Flight Reservation window


'Create DP object
Set winEd=Description.Create
winEd("class Name").value="WinEdit"
set winEditCnt=Window("text:=Flight Reservation").ChildObjects(winEd)
msgbox winEditCnt.Count
For num=0 to winEditCnt.Count - 1
msgbox winEditCnt(num).GetRoProperty("attached text")
Next


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

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