Quicktest Professional Scripting Standards: The Basic Format of The Script
Quicktest Professional Scripting Standards: The Basic Format of The Script
Quicktest Professional Scripting Standards: The Basic Format of The Script
'########################################################################################
##
'#Test/Action Name:
'#Author :
'#Creation Date:
'#Copied From:
'#Modified By:
'#Modification Date:
'#Action Objective :
'#Verifications:
'########################################################################################
Option Explicit
'####Initialize Variables####
i=1
'####TRIM VARIABLES
'Reset SAP app to expected initial condition – Remove if not using for SAP
SAPGuiSession("Session").Reset
'###Validation Point#########
1) All QTP machines will have a copy of the ActionTemplate.mst (shown above)
placed in the dat folder of the QTP folder to foster the formatting standards
stated for all newly created Actions/Components following.
3) Load only those add-ins required to run the test to avoid function library
conflicts.
4) All existing actions will have a header like template shown above.
6) Always reset the initial status of application at the beginning of each script.
For SAP, simply resetting the application takes care of this but for other
applications it is important to ensure that all scripts have an expected initial
and end condition that is the same. For example, starting and ending a script
at the Home Page of a web site.
8) Use x as a place holder for retrieved values in the code if not using
descriptive variable.
11) Use white space where appropriate, such as between if statements, when
navigating to new SAP screen, etc.
12) Indent within flow control (looping) and conditional statements (if/then and
Select Case) one tab.
13) Object names in QTP script should be descriptive. (If process of finding name
is too cumbersome/ time consuming please make note of it in QA Audit)
19) If possible, import data sheets directly to the local sheet where used - use
index position of table to direct it to correct sheet. (This is for new scripts.)
21) Use underscore and “Act” for verification parameter names describing
information retrieved/returned from application at runtime. (Example:
ReturnedRecords_Act) (Not Applied to existing reusables – previously used _Val”)
22) Use underscore and “Exp” for verification parameter names describing
information retrieved/returned from application to set baseline or expected
value. (Example: ReturnedRecords_Exp) (Not Applied to existing reusables)
23) Use underscore and “Out” for output parameters names. (Example:
VendorNumber_Out) (Not Applied to existing reusables)
25) Standard checkpoints should only be used when verifying texts and other
generic validations. Dynamic validations more often require custom
checkpoints but can also use standard checkpoints if able to put values in
datatable.
26) Avoid using hardcoded values if possible. Hardcoded values should only be
used for “any old data” pieces that do not affect outcome or business process
flow.
29) All functions should be stored in the ‘BPT Resources’ folder under the
‘Libraries’ folder in Quality Center.
30) All shared object repositories should be stored in the ‘BPT Resources’ folder
under the ‘Object Repositories’ folder in Quality Center.
32) Only declare needed input and output parameters. (Extraneous parameters
can confuse in case of maintenance needs. – Often a result of copying
components and making changes but forgetting to change options)
Optional:
33) Use the “Generate ‘With’ statements” option found in the Options General
tab to ensure coding is grouped by current focused window.
34) Any scripts that are audited should be transformed to use the ‘With’ by
selecting EditAdvancedApply With menu item.
'####TRIM VARIABLES
StageOfDevelopment = Trim (StageOfDevelopment)
Script ….
'##VALIDATION POINT
x =JavaWindow("Search").JavaStaticText("Your Search Returned").GetROProperty("label")
rc = CompareValue(RecordsReturned_Val,TempArray(1),"Number of Records Returned")
Best Practices
Object Repository
• Object Repositories should be created prior to creation of scripts.
– Rename objects logical name to reflect user interface
• Makes scripts more readable and more easily maintained
• Enforces uniformity of reference
– Map custom objects prior to scripting
• Allows custom objects that behave like standard objects to be
treated as standard giving greater context sensitivity and
increases reliability
– Use shared object repositories in all Apps but SAP – otherwise
business process fosters local repository method as one-time use.
– Create one Shared Object Repository for application functionality
• For instance – Creating sales order – Materials Management, etc
• currently all reusables have own local repository –
should share one
• Do not overlap objects by storing same in multiple
repositories
• * Set as Default when working in same area – client setting in
Action Properties –Associated Repositories tab option.
Reusable Actions
• You can use principles of Modular Scripting or Business Process Testing
(BPT) even if just using QTP
• Reusable actions imply generic code
• Use reusable actions to mimic common Business Actions
• Code should be generic to allow for variations of business process
• Data entry / Validations should be data driven
• Use custom checkpoints whenever possible to provide greater flexibility
• Use Function Libraries for commonly used low-level activity
• ie: – manipulate external files
• Perform calculations
• Work with custom objects
• Associate function libraries with scripts and set as default
• Create external function libraries and organize by task type
• ie: Calculation, String Manipulation, File manipulation etc.
• Use the “Record on any open Browser” option for Web Apps
– You control the initial condition of browser in script
– Use the SAPGuiSession(“Session”).Reset command for SAP
• Use the “Record on any open Application” for Desktop Apps
– You control the initial condition of AUT in script
• Run Options – make sure the following are checked:
– Allow other Mercury products to run tests and components
– Save still image captures to results: select For errors and warnings
– Normal run mode with 100 milliseconds delay
– Automatically generate “With” statements after recording to establish
focus and increase readability of script. (General option)
– Ignore Quality Center (Web option)
• Test/Component Settings
– Make sure proper associated add-ins loaded – only those needed.
– Run on all rows if global datatable has multiple rows
– Establish realistic timeout value – currently 20
• Action Settings
– Each new action will automatically be formatted to fit current format
requirements – be sure to provide needed information where
appropriate.
– ActionTemplate.mst will be stored locally at:
• C:\Program Files\Mercury Interactive\QuickTest Professional\dat
Reusable\Flexible Code
Always think in terms of “where else can I use this” or “how can I make this as
generic (usable) as possible”. See the example above for the synchronization
function. Although it was created for a use in a specific application, the code is
written so that any windows application could use it without changing any code.
This train of thought will make your reusable code and your scripting efforts
more efficient not just for yourself but the entire team. This does not merely
apply to functions but components and actions as well. You need to get out of
the mode of thinking “how do I get this one business process piece to work?”, to
thinking “how do I make this work and make it so that it is most easily reused
and maintained?”.
• Descriptive Programming
– Use when the properties of an object are dynamic and its properties
are unknown for each iteration of the script
– Use descriptive programming in Web apps for dynamically created
objects like text links and web elements where expectations can be
defined or “actuals” easily retrieved.
– Use when same object is duplicated dynamically based on data input
and varies widely.
Recovery Scenarios
• Recovery Scenarios can be used for unexpected situations / errors / common
pop ups
• Use recovery scenarios when the pop up messages are predictable unless
messages are BP status related.
• Weigh Positive vs. Negative testing needs
• Use conditional logic for predictable errors and put logic in the script and not
in recovery scenario.
• Checkpoints should only be in script – never in RS.
• *Makes script execution more reliable and maintenance more efficient
providing one point of maintenance when/if things change.
For example, the VNet home page is comprised of various links to other pages.
Some of these links are to dynamic materials (ie news stories), others are to static
web pages that will always be there (ie Mission Statement, Committee) . The
ones that will always be there can be considered “always expected” so they will
pretty much be “positive” tests. Those that won’t always be there can be either
positive or negative depending on when the testing takes place.
If testType = “Pos” then a=0:b=1 else a=1:b=0 End If ‘where testType tells if pos or neg test
If Exp_Condition = Act_Condition Then
Reporter.ReportEvent a, “Conditional Check”,”The condition specified above was met.”
Else
Reporter. ReportEvent b, “Conditional Check”,”The condition specified above was not met.”
End If
BPT Specific Information (Left in for possible shift back to BPT Usage)
1. All user defined function libraries will have a header that indicates the
functions contained within and a description of each for easy perusal.
2. Only “Add-In” libraries created by QTP for use in registering the add-
in functions and the template library file will remain directly in the
Libraries Attachment area. All others will find a place in the functional
structure shown above.
5. All procedures should be developed with the intention that they will
be reused by other scripts. Avoid private Subs in cases where the Sub
is to be called only once within a script. If it is needed multiple times
then it is acceptable to declare/define a Sub at the beginning of the
script. However, it is suggested that you analyze the procedure to see
if/how it could be written to be more generic and thus gain more
efficiency for script creation.
6. All function procedures will have a header similar to the one shown
above in the example function. The header is to include:
a. The function name with the parameters declared.
b. An objective statement to define what the function does
c. A list of the parameters and a description of what they mean so other users
will know how to use the function.
d. The author name
e. Date Created
f. Modification information – be specific as to what you changed and why.
10. Register your function within the project where you created it
whenever possible. This will allow other users to find your functions
using the Step Generator. (If you do not register the function to a specific test object,
the function is automatically defined as a global function. Global functions can be called by
selecting the Functions category in the Step Generator (for function libraries), or the
Operation item in the Keyword View. A list of global functions can be viewed alphabetically
in the Operation box when the Functions category is selected in the Step Generator (for
function libraries), in the Operation list when the Operation item is selected from the Item
list in the Keyword View.)
11. Functions should not contain statements that pass/fail the step, however they
should provide information in the form of an output variable value that can be
used within the script/action to perform a check. We can not always assume
that a function failure is a bad thing, especially in terms of negative testing
unless the test type is taken into consideration when developing the function
and it is made powerful enough to handle pos/neg logic. (see the section on
efficient coding)
12. Recognize that a function is a procedure. There are two kinds of procedures –
Functions and Subs. If your procedure does not return a value then it is to be
declared as a Sub – otherwise update your Function to send a return value
indicating success or failure.