Wednesday, January 21, 2015

Synchronization


1.1       Synchronizing Your Tests


When you run tests, your application may not always respond with the same speed. For example, it might take a few seconds:

·         For a progress bar to reach 100%
·         For a button to become enabled.
·         For a button to become enabled
·         For a window or pop-up message to open

You can handle these anticipated timing problems by synchronizing your test to ensure that Quick Test waits until your application is ready before performing a certain step

1.2       Options to Synchronize Tests

There are several options that you can use to synchronize your test:

·         You can insert a synchronization point, which instructs Quick Test to pause the test until an object property achieves the value you specify.
  • You can insert Exist or Wait statements that instruct Quick Test to wait until an object exists or to wait a specified amount of time before continuing the test.
  • You can also increase the default timeout settings in the Test Settings and Options dialog boxes in order to instruct Quick Test to allow more time for certain events to occur.

1.2.1 Inserting Synchronization Point

  • Begin recording your test.
·         Display the screen or page in your application that contains the object for which you want to insert a synchronization point.

  • In Quick Test choose Insert > Step > Synchronization Point. The mouse pointer turns into a pointing hand.

  • Click the object in your application for which you want to insert a synchronization point.
If the location you click is associated with more than one object in your application, the Object Selection – Synchronization Point dialog box opens.

Select the object for which you want to insert a synchronization point, and click OK.
The Add Synchronization Point dialog box opens.

·         The Property name list contains the test object properties associated with the object. Select the Property name you want to use for the synchronization point.

  • Enter the property value for which Quick Test should wait before continuing to the next step in the test.

  • Enter the synchronization point timeout (in milliseconds) after which Quick Test should continue to the next step, even if the specified property value was not achieved.

  • Click OK. A Wait Property( )step is added to your test.

For example, if you insert a synchronization point for the Update Order button, it may look something like this:

Window("Flights").WinButton("Update Order").WaitProperty "enabled", 1, 3000

1.2.2  Adding Exist and Wait Statements


You can use Exist and/or Wait statements in the Expert View to instruct Quick Test to wait for a window to open or an object to appear.

Exist statements return a Boolean value indicating whether or not an object currently exists.
Example following statement returns whether Flights Table is displayed:
y=Window("Flight Reservation").Dialog("Flights Table").Exist
 
Wait statements instruct Quick Test to wait a specified amount of time before proceeding to the next.

Example following statement waits for 10 seconds:
Wait (10)

Global synchronization Settings

Modifying Timeout Values
  • To modify the maximum amount of time that Quick Test waits for an object to appear, change the Object Synchronization Timeout (Test > Settings > Run tab).
  • To modify the amount of time that Quick Test waits for a Web page to load, change the Browser Navigation Timeout (Test > Settings > Web tab).


Tuesday, January 20, 2015

View object methods using Object Spy

Open your browser or application to the page containing the object on which you want to spy.

Choose Tools > Object Spy to open the Object Spy dialog box. Alternatively, click the Object Spy button from the Object Repository dialog box.

Click the Methods tab.

Click the pointing hand. Both Quick Test and the Object Spy are minimized so that you can point to any object on the open application.

Note: If the object you want is partially hidden by another window, hold the pointing hand over the partially hidden window for a few seconds. The window comes into the foreground. You can now point and click on the object you want. You can configure this option in the Options dialog box.

If the object on which you want to spy can only be displayed by performing an event (such as a right-click or a mouse-over to display a context menu), hold the Ctrl key. The pointing hand temporarily turns into a standard arrow and you can perform the event. When the object on which you want to spy is displayed, release the Ctrl key. The arrow becomes a pointing hand again.

Click the object for which you want to view the associated methods. The Object Spy returns to focus and displays the object hierarchy tree and the run-time object or test object methods associated with the object that is selected within the tree.


To view the methods of the test object, click the Test Object Methods radio button. To view the methods of the run-time object, click the Run-Time Object Methods radio button.


Tip: You can use the Object property to activate the run-time object methods displayed in the Object Spy.



If you want to view methods for another object within the displayed tree, click the object on the tree.


If you want to copy the syntax of a method to the clipboard, click the method in the list. The syntax is displayed in the selected method syntax box. Highlight the text in the selected method syntax box and use Ctrl + C to copy the text to the clipboard, or right-click the highlighted text and choose Copy from the menu.

Use the Object Spy


Using the Object Spy, you can view the properties of any object in an open application. In addition to viewing object properties, the Object Spy also enables you to view both the run-time object methods and the test object methods associated with an object and to view the syntax for a selected method.

To view object properties:

Open your browser or application to the page containing the object on which you want to spy.

Choose Tools > Object Spy to open the Object Spy dialog box and display the Properties tab. Alternatively, click the Object Spy button from the Object Repository dialog box.

In the Object Spy dialog box, click the pointing hand. Both Quick Test and the Object Spy are minimized so that you can point to and click on any object in the open application.

Note: If the window on which you want to spy is partially hidden by another window, hold the pointing hand over the partially hidden window for a few seconds. The window comes into the foreground. You can now point and click on the object you want. You can configure the length of time required to bring a window into the foreground in the General tab of the Options dialog box.

If the object on which you want to spy can only be displayed by performing an event (such as a right-click or a mouse-over to display a context menu), hold the Ctrl key. The pointing hand temporarily turns into a standard arrow and you can perform the event. When the object on which you want to spy is displayed, release the Ctrl key. The arrow becomes a pointing hand again.

Click the object for which you want to view properties. The Object Spy returns to focus and displays the object hierarchy tree and the properties of the object that is selected within the tree.

To view the properties of the test object, click the Test Object Properties radio button. To view the properties of the run-time object, click the Run-Time Object Properties radio button.

Tip: You can use the Object property to retrieve the values of the run-time properties displayed in the Object Spy.

You can use the GetTOProperty and SetTOProperty methods to retrieve and set the value of test object properties for test objects in your test. You can use the GetROProperty to retrieve the current property value of the objects in your application during the test run.

If you want to view properties for another object within the displayed tree, click the object in the tree.

If you want to copy an object property or value to the clipboard, click the property or value. The value is displayed in the selected property/value box. Highlight the text in the selected property/value box and use Ctrl + C to copy the text to the clipboard or right-click the highlighted text and choose Copy from the menu.

Note: If the value of a property contains more than one line, the Values cell of the object properties list indicates multi-line value. To view the value, click the Values cell. The selected property/value box displays the value with delimiters indicating the line breaks. 

Wednesday, January 14, 2015

Object Repository

Based on Context, the Object Repository is of two types.
Local Object Repository - As the Name Suggests, the Object Repository is applicable only for that Action for which the repository has been created/recorded. As we know that QTP creates a New Test with 1 action by default. Local Object Repository can be opened by traversing to Resources -> gt;Object Repository. This is the default OR in QTP.
 Shared Object Repository - The Object Repository is Shared across actions/modules which would be mapped for two or more actions/scripts. Local objects can be exported to be saved into Shared Object Repository by using the option "Export Local Objects" Options. Shared Object Repository can be opened by traversing to Resource ->gt; Object Repository Manager
 Below are the major differences between Local and Shared OR
Local Object Repository(LOR)
Shared Object Repository (SOR)
This Object Repository is available one for each action.
This type of OR is available for multiple tests and for multiple actions.
This is the OR that is available for each tests by default.
This type of OR is usually used in frameworks considering reusuability and maintainability.
Local Object Repository is Editable in Object Repository.
Shared Object Respository is read only by default but can be edited in Object Repository Manager.
It is NOT a standalone file that can edited.
SOR is a standalone file that can be edited easily.
It is Saved with an Extension .bdb
SOR is saved with an extension .tsr
It Should be used when not many tests are working on the same screens of the application under test.
SOR Should be used when there are different scripts interacting with the same type of the object.



The Object Repository dialog box displays a test tree of all objects in the current action or the entire test.




You can use the Object Repository dialog box to view or modify the properties of any test object in the repository or to add new objects to your repository.



The top part of the dialog box displays information about the object:

Information
Description
Logical name
The name that Quick Test assigns to the object.
Class
The class of the object.
Find
Opens the Find dialog box, where you can find a property or value that occurs several times in the same action.
Replace
Opens the Replace dialog box, where you can modify a property or value that occurs several times in the same action.


Viewing the Object’s Properties

The default properties for the object are listed in the Properties pane of the dialog box. The pane includes the properties, their values, and their types:

Pane Element
Description
Type
 icon indicates that the value of the property is currently a constant.

 icon indicates that the value of the property is currently a Data Table parameter.
 icon indicates that the value of the property is currently an environment variable parameter.
 icon indicates that the value of the property is currently a random number parameter.
Property
The name of the property.
Value
The value of the property.
Enable Smart Identification
Indicates whether or not Quick Test uses Smart Identification to identify this object during the test run if it is not able to identify the object using the test object description. Note that this option is available only if Smart Identification properties are defined for the object’s class in the Object Identification dialog box.
Note: When you select Disable Smart Identification during the test run in the Run tab of the Test Settings dialog box, this option is disabled, although the setting is saved. When you clear the Disable Smart Identification during the test run check box, this option returns to its previous on or off setting after the test run.
Add/Remove
Opens the Add/Remove Properties dialog box which lists the properties that can be used to identify the object.


Object Identification in QTP


Object Identification While Recording

Stores Object as Test Object, Determining the class it fits.
For each test object class, Quick Test always learns a list of Mandatory properties or Assistive properties. Checks whether this description is enough to uniquely identify the object. If it is not, Quick Test adds assistive properties, one by one, to the description, until it has a unique description.

Object Identification during Test Run

Searches for a run-time object that exactly matches the description of the test object
It expects to find a perfect match for both the mandatory and any assistive properties of test object

Uses Smart Identification mechanism to identify an object, even when the recorded description is no longer accurate.

Monday, January 12, 2015

Understanding the QTP Result Pane


When Quick Test finishes running the test, the Test Results window opens.

Initially, the Test Results window contains two panes for displaying the key elements of your test run.
  • The left pane displays the test results tree, an icon-based view of the steps that were performed while the test was running. Similar to the test tree in Quick Test main screen, it is organized according to the Web pages visited during the test run and can be expanded (+) to view each step. The steps performed during the test run are represented by icons in the tree. You can instruct Quick Test to run a test or action more than once using different sets of data in each run. Each test run is called iteration and each iteration is numbered. (The test you ran had only one iteration.)
  • The right pane displays the test results details. The iteration summary table indicates which iterations passed and which failed. The status summary table indicates the number of checkpoints or reports that passed, failed, and raised warnings during the test.
Your test run succeeded because Quick Test was able to navigate the Mercury Tours site just as the test was originally recorded. In this section, you will inspect the steps Quick Test performed when running your test, and how the application window appeared when a step was performed.




  1. View the test results for a specific step.

In the test results tree, expand (+) Test Recording Summary >
Recording Iteration 1 (Row 1) > Action1 Summary > Welcome Mercury > Find a Flight
.
Highlight "fromPort":Select "New York" in the test results tree.



The Test Results window now contains three panes, displaying:
·         the test results tree, with one step highlighted
·         the test results details of the highlighted step
·         The Active Screen, showing a screen capture of the Web page on which the step was performed.
When you click a page in the test results tree, Quick Test displays the corresponding page in the application view. When you click a step (an operation performed on an object) in the test results tree, the corresponding object is highlighted in the application view. In this case, the Departing From text box is highlighted.

       2.  Close the Test Results window.
Choose File > Exit.

Test Results Tree Symbols


Indicates a step that succeeded or passed.


Indicates a step that failed.


Indicates a warning, meaning that the step did not succeed, but it did not cause the action or test to fail.


indicates a step that failed unexpectedly, such as when an object is not found for a checkpoint.


Indicates an optional step that failed and therefore was ignored. Note that this does not cause the test to fail.

Indicates that the Smart Identification mechanism successfully found the object.


Indicates that a recovery scenario was activated.


Indicates that the test run was stopped before it ended.


Recording Levels in QTP


There are three types of recording available in QTP:

1.        Normal Recording

 
Records the objects in your application and the operations performed on them. This mode is the default and recognizes the objects in your application regardless of their location on the screen. When working with specific types of objects or operations, choose from the following, alternative recording modes.

       Records the test in terms of GUI objects.

2.        Analog Recording

Enables you to record the exact mouse and keyboard operations  This mode is useful for recording operations that cannot be recorded at the level of an object, for example, recording a signature produced by dragging the mouse.
enables you to record the exact mouse and keyboard operations you perform in relation to either the screen or the application window.

3.        Low Level Recording

 Enables you to record on any object in your application. This mode records at the object level and records all run-time objects as Window or Win Object test objects.Use low-level recording for recording in an environment or on an object not recognized by Quick Test.
You can also use low-level recording if the exact coordinates of the object are important for your test or component.
Note: Steps recorded using low-level mode may not run correctly on all objects.
                                                      or
This mode records at the object level and records all run-time objects as Window or Win Object test objects.

Running a Test


Here you will run the test you recorded.
1)     Start Quick Test and open the Recording test.
If Quick Test is not already open, choose Start > Programs > Quick Test Professional > Quick Test Professional.
·         If the Welcome window opens, click Open Existing.
·         If Quick Test opens without displaying the Welcome window, choose File > Open
Or click the Open button.
In the Open Test dialog box, locate and select the Recording test, then click Open.

2)     Confirm that all images are saved to the test results.
Quick Test allows you to determine when to save images to the test results. In this lesson, all images should be saved to the test results.

Choose Tools > Options and select the Run tab. In the Save step screen capture to test results option, select always.

Click OK to close the Options dialog box.

3)     Start running your test.
Click Run or choose Test > Run. The Run dialog box opens.
Select New run results folder. Accept the default results folder name.
Click OK to close the Run dialog box.


Watch carefully as Quick Test opens your browser and starts running the test. In the browser, you can see Quick Test perform each step you recorded; a yellow arrow in the left margin of the test tree indicates the step that Quick Test is running.

Thursday, January 8, 2015

Record and Playback

Create and Execute Basic Scripts 

1.        Recording Tests

  1. Start Quick Test and open a new test.
·         If Quick Test is not currently open, choose Start > Programs > Quick Test Professional > Quick Test Professional.

In the Add-in Manager, confirm that the Web Add-in is selected, and clear all other add-ins. Click OK to close the Add-in Manager and open Quick Test.

Note: While Quick Test loads your selected add-ins, the Quick Test splash screen is displayed. This may take a few seconds. If the Welcome window opens, click Blank Test.
Otherwise, choose File > New, or click the New button.
A blank test opens.

·         If Quick Test is already open, check which add-ins are loaded by selecting Help > About Quick Test Professional. If the Web Add-in is not loaded, you must exit and restart Quick Test. When the Add-in Manager opens, select the Web Add-in, and clear all other add-ins.
Choose File > New, or click the New button.
A blank test opens.

Note: If the Add-in Manager does not open when starting Quick Test, choose Tools > Options. In the General tab, select Display Add-in Manager on startup. When you exit and restart Quick Test, the Add-in Manager opens.

  1. Start recording.
·         Choose Test > Record or click the Record button The Record and Run Settings dialog box opens.

In the Web tab, select Open the following browser when a record or run session begins.

·         Choose a browser from the Type list and confirm that the URL in the Address box is for example. http://newtours.mercuryinteractive.com.

·         Confirm that Close the browser when the test is closed is selected.
·         In the Windows Applications tab, confirm that Record and run on these applications is selected, and that there are no applications listed.

This setting prevents you from inadvertently recording operations performed on various Windows applications (such as e-mail) during a recording session.

·         Click OK.

Quick Test begins recording, and your browser opens to the Mercury Tours Web site.

  1. Login to the Mercury Tours Web site.
In the User Name and Password boxes, type the name and password you registered with Mercury Tours.

Click Sign-In.

The Flight Finder page opens.

  1. Enter flight details.

Change the following selections:
Departing From: New Delhi
On: Jan 29
Arriving In: Benguluru
Returning: Jan 31
Service Class: Business class

Click CONTINUE to accept the other default selections. The Select Flight page opens.

Note: When entering dates while recording this test, do not click the View Calendar button, which opens a Java-based calendar. Your test will not record the date selected using this calendar because you did not load the Java Add-in for this tutorial.

To check which add-ins have been loaded, click Help > About Quick Test Professional. To change the available add-ins for your tests, you must close and reopen Quick Test Professional.

  1. Select a flight.
Click CONTINUE to accept the default flight selections. The Book a Flight page opens.

  1. Enter required passenger and purchase information.
Enter the required information (fields with red text labels) in the Passengers and Credit Card sections. (You may enter fictitious information.)
In the Billing Address section, select Ticketless Travel.
At the bottom of the page, click SECURE PURCHASE. The Flight Confirmation page opens.

  1. Review and complete your booking.
Click BACK TO HOME. The Mercury Tours home page opens.

  1. Stop recording.
In Quick Test, click Stop on the test toolbar to stop the recording process.
You have now reserved an imaginary business class ticket from New Delhi to Benguluru. Quick Test recorded your Web browser operations from the time you clicked the Record button until you clicked the Stop button.
Save your test.
Select File > Save or click the Save button. The Save dialog box opens to the Tests folder.
Create a folder named Tutorial, select it, and click Open.
Type Recording in the File name field.
Confirm that Save Active Screen files are selected.
Click Save. The test name (Recording) is displayed in the title bar of the main Quick Test window.

2.        Running a Test

Here you will run the test you recorded.
1)     Start Quick Test and open the Recording test.
If Quick Test is not already open, choose Start > Programs > Quick Test Professional > Quick Test Professional.
·         If the Welcome window opens, click Open Existing.
·         If Quick Test opens without displaying the Welcome window, choose File > Open
Or click the Open button.
In the Open Test dialog box, locate and select the Recording test, then click Open.

2)     Confirm that all images are saved to the test results.
Quick Test allows you to determine when to save images to the test results. In this lesson, all images should be saved to the test results.

Choose Tools > Options and select the Run tab. In the Save step screen capture to test results option, select always.

Click OK to close the Options dialog box.

3)     Start running your test.
Click Run or choose Test > Run. The Run dialog box opens.
Select New run results folder. Accept the default results folder name.
Click OK to close the Run dialog box.


Watch carefully as Quick Test opens your browser and starts running the test. In the browser, you can see Quick Test perform each step you recorded; a yellow arrow in the left margin of the test tree indicates the step that Quick Test is running.

Modify Date_Change Date_Calculated Date


'###############################################################################
'Name: Calculate_Date
'Created[By] : msrivastava
'@Description Purpose: This function is used to add to or remove days from a given [dtDate] and return
'new date, in the correct format.
' @Documentation Parameters:  <dtDate>-  Date to be modified.
'<intDay>- number of days to be added/subtracted by. use (-)negative to subtract.
'###############################################################################
Public Function Calculate_Date(dtDate, intDay)
Dim NewDate, chkDate, val, DateFormat, FormatDate

Reporter.ReportEvent micInfo, "Calculate Date", "Add ["& intDay& "] days to a given ["& dtDate& "] and return New Date."
on error resume next
val = DataTable("DateFormat", dtGlobalSheet)
If err.number <> 0 Then
DateFormat = "en-US"
else
DateFormat = DataTable("DateFormat", dtGlobalSheet)
End If

If instr(1, DateFormat, "GB") > 1 Then
NewDate = ConvertDate(dtDate)
End If

NewDate = DateAdd("d", intDay, dtDate)
chkDate = Weekday(NewDate)
Select Case chkDate
Case 1
NewDate = DateAdd("d", intDay+ 1, dtDate)

Case 7
NewDate = DateAdd("d", intDay+ 2, dtDate)
End Select
 
'once weekday is set, format to the based on business unit.
'GetDate(inDate, fmt)
    FormatDate = GetDate(NewDate, DateFormat)

'Return reformatted date
Calculate_Date = FormatDate
End Function

Format Date Function


'###############################################################################
'Name: GetDate()
'Created[By] : msrivastava
'@Description Purpose: This function is used to format our date depending on the format code
'@Documentation Parameters: <inDate>  Date to be reformated
'<fmt> containing the formatting code for the date
'###############################################################################

Public Function GetDate (inDate, fmt)'(IntlDateCodes fmt)
    Dim outDate
Dim dtTime
Dim sDay, sMonth, sYear, sHour, sMinute

'Get our current date
inDate = DateValue(inDate)
'Break it out into month, day, and year
' For the month, day, minute, or hour we might end up with a single digit. In that case, check the length.
' If the length is one, append a 0 to make it two characters.
' Day
sDay = Day(inDate)
If Len(sDay) = 1 Then
sDay = "0" & sDay
End If
' Month
sMonth = Month(inDate)
If Len(sMonth) = 1 Then
sMonth = "0" & sMonth
End If
' Year
sYear = Year(inDate)
' Hour
sHour = Hour(Now)
If Len(sHour) < 2 Then
sHour = "0" & sHour
End If
' Minute
sMinute = Minute(Now)
If Len(sMinute) < 2 Then
sMinute = "0" & sMinute
End If
'Check the date format and stick the date pieces together with slashes in between, based on the language
Select Case fmt
Case "en-GB"
outDate = sDay & "/" & sMonth & "/" & sYear 'dd/mm/yyyy format

Case "en-GB_Short"
outDate = sDay & "/" & sMonth & "/" & right(sYear, 2) 'dd/mm/yy format

        Case "en-US"
outDate = sMonth& "/"& sDay& "/"& sYear  'mm/dd/yyyy format

Case "Archive"
outDate = sYear& "-"& sMonth& "-"& sDay  'yyyy-mm-dd format

Case "Archive_Strip"
outDate = sYear& sMonth& sDay  'yyyymmdd format

Case "Short"
            outDate = sMonth& "/"& sDay& "/"& right(sYear,  2)   'mm/dd/yy format

Case "Strip"
outDate = sMonth & sDay & sYear    'mmddyyyy format

Case "Short_Strip"
outDate = sMonth& sDay& right(sYear, 2)  'mmddyy format

Case "Strip-GB"
outDate = sDay & sMonth & sYear    'ddmmyyyy format

Case "Dmd Date-time"
outDate = sMonth & sDay & sHour & sMinute  'mmddhhmm  format

Case "-Year"
outDate = sMonth & sDay 'mmdd  format

Case "StripZeros"
outDate = Month(inDate)& "/"& Day(inDate)& "/"& sYear

Case "SysDate"
outDate = DateAdd("d", 0, inDate)   '#DATE#  format

Case "Underscore-US"
outDate = sMonth& "_"& sDay& "_"& sYear    'mm_dd_yyyy format

Case "DateTime-US"
dtTime = sHour& ":"& sMinute 'mm/dd/yyyy hh:mm
outDate = sMonth& "/"& sDay& "/"& sYear& " "& dtTime 'mm/dd/yyyy hh:mm

Case "DateTime-GB"
dtTime = sHour& ":"& sMinute 'dd/mm/yyyy hh:mm
outDate = sDay & "/" & sMonth & "/" & sYear& " "& dtTime 'dd/mm/yyyy hh:mm
    End Select

   GetDate = outDate
End Function