Monday 17 February 2014

Multiple scripts can be run from batch runner

The Run Multiple tests together using qtp use : Test Batch Runner

Below is the process to use Test Batch Runner:

First Create 2 or 3 more scripts usng QTP,Save your QTP Scripts,In Windows,Click on the Start Menu,
Then ALl Programs,Then Browse to qtp, Tools,then click on the Test Batch Runner,Then click on Add,Then Browse to locate the saved qtp scripts one by one.then click on Batch,Then Run
Create multiple script files and add to the test batch
runner as batch file with the extension of .mtb
when ever you require just open the batch file and select
desired scripts and execute.

Monday 10 February 2014

VBScript Variables


VBScript Variables
VBScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.
Rules for VBScript variable names:
    Must begin with a letter
    Cannot contain a period (.)
    Cannot exceed 255 characters

In VBScript, all variables are of type variant that can store different types of data.
Declaring (Creating) VBScript Variables

Creating variables in VBScript is most often referred to as "declaring" variables.

You can declare VBScript variables with the Dim, Public or the Private statement. Like this:
Dim x
Dim carname

Now you have created two variables. The name of the variables are "x" and "carname".

You can also declare variables by using its name in a script. Like this:
carname="orange"

Now you have also created a variable. The name of the variable is "carname". However, this method is not a good practice, because you can misspell the variable name later in your script, and that can cause strange results when your script is running.
If you misspell for example the "carname" variable to "carnime", the script will automatically create a new variable called "carnime".  To prevent your script from doing this, you can use the Option Explicit statement. This statement forces you to declare all your variables with the dim, public or private statement.
Put the Option Explicit statement on the top of your script. Like this:
Option Explicit
Dim carname
carname=some value
You assign a value to a variable like this:
carname="orange"
x=10
The variable name is on the left side of the expression and the value you want to assign to the variable is on the right. Now the variable "carname" has the value of "orange", and the variable "x" has the value of "10".

When you declare a variable within a procedure, the variable can only be accessed within that procedure. When the procedure exits, the variable is destroyed. These variables are called local variables. You can have local variables with the same name in different procedures, because each is recognized only by the procedure in which it is declared.

If you declare a variable outside a procedure, all the procedures on your page can access it. The lifetime of these variables starts when they are declared, and ends when the page is closed.

Tuesday 28 January 2014

Record and Playback in qtp



Initial development of automated tests with QTP is usually done by record-and-playback. A user’s actions are captured via Microsoft’s Component Object Model (COM). These are recorded into Actions, a kind of subroutine, as VBScript commands. All manipulated objects that QTP recognizes are also added to the object repository. Once recorded, the scripts are editable in either Keyword View or Expert View.
After clicking on the playback button all these actions will be played back. During playback, QTP attempts to identify and perform operations on the same objects, again using COM.
NormalRecording Mode: It records the actions performed by the user on the application objects like Edit boxes, List boxes and Links. QTP records each action as one step in the QTP script. Step is nothing but one line in the code.


·         Launch QTP
·         Create a new test by selecting  File>New>Test
·         Click Record button or select Automation>Record or press the Record command shortcut key F3.
·         The Record  and Run settings dialog opens as shown below, Enter Application URL in the box as shown in our case .When  you are done with recording click the Stop button or select Automation>Stop or press F4.
·         Save Your Test.
·         Run the test by clicking Run.


AnalogRecording Mode: This mode enables you to record the exact mouse and keyboard operations you perform in relation to either the screen or the application window. This mode is useful when you want to record mouse movements, for example recording a signature or drawing performed by dragging the mouse. To record in analog mode , first start normal recording then select Automation>Analog Recording. The Analog recording dialog box opens up as shown below.
Record relative to the screen: QTP records any mouse movement or keyboard input relative to the top
  left coordinates of your screen(i.e. desktop).

  Record relative to the following window: QTP records any mouse movement or keyboard input
   relative to the coordinates of the specified window.
Low Level Recording:
 Low level recording mode is used only when exact coordinate of the operation is essential. To record a test using low level recording mode, start the normal recording session then select Automation>Low Level Recording to start recording in low level
(code created in low level recording)
Window("Oracle VM VirtualBox Manager").Window("Create New Virtual Machine").WinObject("Cancel").Click 40,17

This code states that Cancel button was clicked at  coordinate 40,17. This coordinate is measured by taking top left corner of the object( Here it is the Cancel button) as reference (0,0).

Use Analog recording mode only when normal recording mode does not accurately record your operations.
Use analog recording for the applications in which the actual movement of the mouse is what you want to record, like drawings, signatures etc.
Use low level recording when you need to record the exact location of the operation on your application screen.
Running Tests:
QTP always run from the first step, unless you specify otherwise.To run a test , open it and select Automation>Run or press F5.The Run dialog box opens, in the dialog box specify the result location. Temporary run result folder saves run results in a temporary folder.This option overwrites any results previously saved in this folder. Click OK to start the Run session.
Test Result Window: When a run session ends, you can view run session results in the Test Results window. The run result tree is located in the left pane in the Test Result window
Recordand Run Settings Dialog: This Dialog box is used to instruct QTP , which application to open when you begin to record or run your test.
Windows Application Tab: As shown in figure below.There are two radio buttons, if we select first one QTP records and run test on any application and if we select a second one, we can specify the applications on which QTP should record or run test.
  Web Tab: Web Tab as shown below also have two radio buttons, if select the first one,QTP records and run test on application opened on any browser and if we select the second one, QTP records and runs tests by opening application in a new browser of the specified type.

Thursday 23 January 2014

Dynamic arrays



An array can hold more than one value. An array lets you address many data values through the same variable. Think of an array as a list (e.g., a list of usernames). You reference each item in this list with a common name and index number. The common name is the name of the array variable. The common name typically includes the prefix arr to denote that the variable contains data of the subtype Array. The index number is an integer subscript that denotes an item's relative location in the list. The indexes always increment sequentially, starting from 0. For example, if an array has three items, the indexes are 0, 1, and 2. The 0 index represents the first position, the 1 index represents the second position, and the 2 index represents the third position in the array.
There are two types of arrays:
Static arrays
Dynamic arrays
Static array has to be declared with the number of elements that the array can hold (i.e. arr(5)).  If we don’t know the number of elements to be stored in the array, then the dynamic array can be used.
Syntax:
Dim arr()
ReDim keyword should be then used to declare the number of elements that the array can hold.
Syntax:
Dim arr()
ReDim arr(3)
Example:
Dim arr()
ReDim arr(3)
    arr(0)=10
    arr(1)=15
    arr(2)=20
msg=""
For i=0 to 3
    msg=msg&"Arr("&i&") : "&arr(i)&vbnewline
Next

msgbox msg

ReDim arr(4)
arr(4)=20
msg=""
For i=0 to 4
    msg=msg&"Arr("&i&") : "&arr(i)&vbnewline
Next
msgbox msg
In the above example, array is initially sized with five elements.  Array elements with indices 0 to 5 are initialized and displayed using for loop.  The array is resized with ReDim keyword and then the added array element is initialized with the statement “arr(4)=20”.

Output before resizing the array:
dynamicarray1
Output after resizing the array:
dynamicarray2
We will use the Preserve keyword with the ReDim in the above example.
Dim arr()
ReDim arr(5)
    arr(0)=10
    arr(1)=15
    arr(2)=20
    arr(3)=25
msg=""
For i=0 to 4
    msg=msg&"Arr("&i&") : "&arr(i)&vbnewline
Next

msgbox msg

ReDim Preserve arr(6)
arr(4)=20
msg=""
For i=0 to 4
    msg=msg&"Arr("&i&") : "&arr(i)&vbnewline
Next
msgbox msg
preserve
Output shows the array element values starting from Arr(0) to Arr(6).  Preserve keyword preserves the values of the array elements before ReDim statement.  Hence, if we resize the array with ReDim and add new elements does not erase the earlier values of the array.

Follow the steps below to use the dynamic arrays:

Declare the array with no size – Dim array_name()
Re-declare the size of the array with ReDim & Preserve – ReDim Preserve array_name(number of elements)

Friday 17 January 2014

About other VB Built functions in QTP


About all the built-in VBScript functions. The page is divided into following sections: Date/Time functions; Conversion functions; Format functions. Math functions; Array functions. String functions; Other functions
Date/Time Functions
Function         Description
CDate Converts a valid date and time expression to the variant of subtype Date
Date    Returns the current system date
DateAdd         Returns a date to which a specified time interval has been added
DateDiff         Returns the number of intervals between two dates
DatePart         Returns the specified part of a given date
DateSerial      Returns the date for a specified year, month, and day
DateValue      Returns a date
Day     Returns a number that represents the day of the month (between 1 and 31, inclusive)
FormatDateTime       Returns an expression formatted as a date or time
Hour   Returns a number that represents the hour of the day (between 0 and 23, inclusive)
IsDate Returns a Boolean value that indicates if the evaluated expression can be converted to a date
Minute            Returns a number that represents the minute of the hour (between 0 and 59, inclusive)
Month Returns a number that represents the month of the year (between 1 and 12, inclusive)
MonthName   Returns the name of a specified month
Now    Returns the current system date and time
Second            Returns a number that represents the second of the minute (between 0 and 59, inclusive)
Time   Returns the current system time
Timer  Returns the number of seconds since 12:00 AM
TimeSerial      Returns the time for a specific hour, minute, and second
TimeValue     Returns a time
Weekday        Returns a number that represents the day of the week (between 1 and 7, inclusive)
WeekdayName          Returns the weekday name of a specified day of the week
Year    Returns a number that represents the year
Conversion Functions
Function         Description
Asc      Converts the first letter in a string to ANSI code
CBool Converts an expression to a variant of subtype Boolean
CByte Converts an expression to a variant of subtype Byte
CCur  Converts an expression to a variant of subtype Currency
CDate Converts a valid date and time expression to the variant of subtype Date
CDbl   Converts an expression to a variant of subtype Double
Chr     Converts the specified ANSI code to a character
CInt    Converts an expression to a variant of subtype Integer
CLng  Converts an expression to a variant of subtype Long
CSng   Converts an expression to a variant of subtype Single
CStr    Converts an expression to a variant of subtype String
Hex     Returns the hexadecimal value of a specified number
Oct      Returns the octal value of a specified number
Format Functions
Function         Description
FormatCurrency       Returns an expression formatted as a currency value
FormatDateTime       Returns an expression formatted as a date or time
FormatNumber         Returns an expression formatted as a number
FormatPercent          Returns an expression formatted as a percentage
Math Functions
Function         Description
Abs     Returns the absolute value of a specified number
Atn      Returns the arctangent of a specified number
Cos      Returns the cosine of a specified number (angle)
Exp     Returns e raised to a power
Hex     Returns the hexadecimal value of a specified number
Int       Returns the integer part of a specified number
Fix       Returns the integer part of a specified number
Log     Returns the natural logarithm of a specified number
Oct      Returns the octal value of a specified number
Rnd     Returns a random number less than 1 but greater or equal to 0
Sgn      Returns an integer that indicates the sign of a specified number
Sin       Returns the sine of a specified number (angle)
Sqr      Returns the square root of a specified number
Tan     Returns the tangent of a specified number (angle)
Array Functions
Function         Description
Array  Returns a variant containing an array
Filter   Returns a zero-based array that contains a subset of a string array based on a filter criteria
IsArray           Returns a Boolean value that indicates whether a specified variable is an array
Join     Returns a string that consists of a number of substrings in an array
LBound                Returns the smallest subscript for the indicated dimension of an array
Split    Returns a zero-based, one-dimensional array that contains a specified number of substrings
UBound          Returns the largest subscript for the indicated dimension of an array
String Functions
Function         Description
InStr   Returns the position of the first occurrence of one string within another. The search begins at the first character of the string
InStrRev        Returns the position of the first occurrence of one string within another. The search begins at the last character of the string
LCase Converts a specified string to lowercase
Left     Returns a specified number of characters from the left side of a string
Len     Returns the number of characters in a string
LTrim Removes spaces on the left side of a string
RTrim            Removes spaces on the right side of a string
Trim   Removes spaces on both the left and the right side of a string
Mid     Returns a specified number of characters from a string
Replace           Replaces a specified part of a string with another string a specified number of times
Right   Returns a specified number of characters from the right side of a string
Space  Returns a string that consists of a specified number of spaces
StrComp        Compares two strings and returns a value that represents the result of the comparison
String  Returns a string that contains a repeating character of a specified length
StrReverse     Reverses a string
UCase Converts a specified string to uppercase
Other Functions
Function         Description
CreateObject Creates an object of a specified type
Eval    Evaluates an expression and returns the result
GetLocale       Returns the current locale ID
GetObject       Returns a reference to an automation object from a file
GetRef            Allows you to connect a VBScript procedure to a DHTML event on your pages
InputBox        Displays a dialog box, where the user can write some input and/or click on a button, and returns the contents
IsEmpty          Returns a Boolean value that indicates whether a specified variable has been initialized or not
IsNull  Returns a Boolean value that indicates whether a specified expression contains no valid data (Null)
IsNumeric      Returns a Boolean value that indicates whether a specified expression can be evaluated as a number
IsObject          Returns a Boolean value that indicates whether the specified expression is an automation object
LoadPicture   Returns a picture object. Available only on 32-bit platforms
MsgBox          Displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked
RGB   Returns a number that represents an RGB color value
Round            Rounds a number
ScriptEngine  Returns the scripting language in use
ScriptEngineBuildVersion   Returns the build version number of the scripting engine in use
ScriptEngineMajorVersion  Returns the major version number of the scripting engine in use
ScriptEngineMinorVersion  Returns the minor version number of the scripting engine in use
SetLocale        Sets the locale ID and returns the previous locale ID
TypeName     Returns the subtype of a specified variable
VarType         Returns a value that indicates the subtype of a specified variable