Friday, August 26, 2011

Scripting Guidelines or Coding Standards in Test Automation Script

Coding Standards are suggestions that will help you to write QTP Script code using VB Script. Naming conventions for crating QTP Script, objects, variables and procedures. Commenting standard in the scripting, Text formatting and align guidelines for the script.

The main motive for using a regular set of coding Standards is to normalize the structure and coding way of a QTP script or set of scripts, so that you and others team members can easily read and understand the QTP code.
Using good coding standards will results in accurate, readable, and unmistakable QTP Script.
Code that is consistent with other languages like Java script etc,. conventions and as sensitive as possible.

Script Organization


An example of the comment block is as follows:

you can also create a action template, with fallowing information, Click Here to see how to create a action template in QTP.

'Test Script Header
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'@Script Name : < Name of the Script>
'@Script Description : < Description of the Script>
'@Script Author : < Jr.Siva Kumar Eanuga>
'@Email ID: < Shivakumar004@gmail.com>
'@CreationDate : < dd-mm-yyyy>
'@Last Updated Date : < dd-mm-yyyy>
'@PreCondition : < pre requisites to be used for the script>
'@Libraries : < required library files>
'@External Function Reference:
'@DataFiles : < required data files>
'@DtParam : < Name>
'@DtParam : < Name>
'@DtParam : < Name>
'@Modification : < By , Date: >
'@Description: < modification description>
'@Reviewed By : < Sr. Siva Kumar Eanuga>
'@Reviewed Date : < dd-mm-yyyy>
'@Remarks : < Additional information>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'-- Constant Declarations
'declare here your constants
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'--- Global Variable Declarations
'declare here your Global Variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'--- Local Variable Declarations
'declare here your Local Variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'< detailed script>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The End of Script
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Standards of Constant Naming

Constant names should be uppercase with underscores (_) between words.
Ex: USER_LIST_MAX, NEW_LINE

Standards of Variable Naming

For easy readability purpose use the prefixes like below examples, along with descriptive names for variables in your QTP Script code.
Ex:
String -- sName
Object -- oObjectname
Integer, Byte, Long -- nNumber
Array -- arrListitems
Boolean -- bYes
Single, Double -- fPrice
DateTime -- dToday
Error -- errResponse
Currency –- cRupees

Object Naming Standards

For the objects we create in the QTP script, we use prefix “o” (small letter o).

Ex:
ADODB.Connection -- oConn
ADODB.Recordset -- oRset
Scripting.xmlobject -- oXmlobj
Scipting.FileSystemObject -- oFsobj
Scipting.TextStream -- oTxt
Scripting.Dictionary -- oDic
Shell.Application -- oWsh
Excel.Application -- oXls

to be continued .....

No comments: