Professional Documents
Culture Documents
Table of Contents
1. Introduction....................................................................................................................................... 2
1.1. Purpose...................................................................................................................................... 2
1.2. Intended Audience..................................................................................................................... 2
2. Naming Convention........................................................................................................................... 3
3. Header.............................................................................................................................................. 3
4. Comments......................................................................................................................................... 3
5. Indentation........................................................................................................................................ 3
6. General guidelines............................................................................................................................ 3
Page 1 of 9
WinRunner Coding Standard (WRCS)
1. Introduction
Any good automation code needs guidelines or coding standards to be followed to be readable,
presentable and at the same time ensure it is executable. The coding standard brings in the good
rules being followed across projects into the project and hence value adds to the project. It also
decreases the maintenance cost, as it is well documented and readable.
1.1. Purpose
This document details the coding standards for Win runner scripting that will make the code
presentable and readable.
Page 2 of 9
WinRunner Coding Standard (WRCS)
2. Naming Convention
The first letter or letters of the variable name will indicate data type of variable. Second letter will be in
uppercase for the name (if the string name is composed of two words then recommended to use
Capital letter for each word). Use of the "_" underscore character should be avoided.
Sr.
Data type Example
No.
1. Strings strVariableName
2. Number nName
3. Boolean bName
4. Any return value rcValue
5. Flag flgStepNo
All global variables should be declared at the top of the script immediately following the script
header.
Parameters passed to or from (in or out or in/out) should immediately follow global variables.
Local variables can be declared at the time of use.
All variables must have descriptive comments added on the same line the variable is
declared.
Page 3 of 9
WinRunner Coding Standard (WRCS)
Function name can start with prefix (fn). First letter should be capital. Name should be
meaningful i.e. it should describe what the function is all about.
Even if no prefix (fn) is attached with the function, there is no harm because the two small
braces always recognize functions uniquely.
For Example:
getValue() or fnGetValue()
All parameters passed to or returned from a function must be declared and commented –
please see rules for global variables and local variables in section of variable declaration.
It should appear immediately below the script header and after the variable declarations.
The declaration should include the type of the parameter (in or out or in/out).
For Example:
Tests related to web site registration might be called register or register.gui.
3. Header
3.1. Start of script
- To be more precise, incase of “Test Cases Covered”, we should have the “Test Case ID” which
is mentioned is our test case document.
- Instead of having log of all the “History”, we can have the “Creation Date”, “Last Modified Date”
and may be “Name of the person, if required, with these columns.
- Either ---- or ### can be used to mark the start or end of script
Page 4 of 9
WinRunner Coding Standard (WRCS)
#_______________________________________________________________________________________________
# Project name - Mighty Joe
# Module - Login
# Script name - Login to Application
# Test case covered - Initial Gui Checks / Error Msgs Validation / Functional / etc
# Data files - none
# Dependencies - none
# Description - This script details scripts for initial GUI checks for the Login window
# Pre-conditions - Desktop (Before invoking application) No application window exist
# Post-conditions - No application window exist
# Global Variables used (if called script) -
# Functions Used, if calling script - none
# Revision history----------------------------------------------------
# Author - Tester Name Date - DD/MM/YYYY Ver -Draft
# Reviewed By - TL Date - DD/MM/YYYY Ver -1.0.0
# Reworked By - Tester Name Date - DD/MM/YYYY Ver -1.0.0
# Reviewed By - TL Date - DD/MM/YYYY Ver- 1.0.1
#_____________________________Start of Script_________________________________
--------------------Code Here-----------------------------
# Parameters Passed
--------------------Code Here-----------------------------
--------------------Code Here-----------------------------
# Test Case 1 - Login to Application with Admin rights - End
--------------------Code Here-----------------------------
# Test Case 2 - Login to Application with superuser rights – End
#_____________________________End of Script_______________________________
Page 5 of 9
WinRunner Coding Standard (WRCS)
“Test Case ID” is more suitable instead of “Test Cases Covered”, if test case ids are used
For Example:
###########################################################
### Test Case Id:
### Test Step:
### Expected result:
###########################################################
Pass/fail routine
###########################################################
#------------ End of Test Step
###########################################################
###########################################################
#-------------Start of the Script
###########################################################
###########################################################
#-------------End of the Script 1.0
###########################################################
Page 6 of 9
WinRunner Coding Standard (WRCS)
For Example:
########################################################
### Module Name:
### Description:
### Revisions :
### No. Date Developer Addition/Change
### 2 09/11/07 Rahul
### 1 09/11/07 Ashish
#########################################################
#########################################################
### Function: <Function Name> CopyFile()
### Description: <What this function does>
### Input Parameters:<Type of parameter it takes>
### Returns <Return Value>
### Usage: <How to use the function in the scripts>
Page 7 of 9
WinRunner Coding Standard (WRCS)
Note: Its Better to have Company’s Name in “Author” section instead of person’s Name.
4. Comments
4.1. Comments Usage Conventions
Adding comments to a script is recommended. Comments are important elements in a script.
Good and consistent commenting practices facilitate an understanding of what the script and its
functional sections do in conjunction with the script header. Make sure that comments explain the
code and not just a cut paste or earlier comments.
Comment starts with #. There should be proper comments in the scripts. Comments for each line
are not required. Instead, use comments for groups of closely related lines or whenever the code
is confusing or may be difficult to understand. For extensive explanations, an indented section
with a meaningful name (describing functionality for particular code) can be used.
For Example:
#-------Invoking application---------
fnStartPureCMS();
It is mandatory to add comments preceding sections of a test script. The comment should
describe the test scenario that is being performed.
It is mandatory to add comments to all variable declarations. The comment should explain
what data gets assigned to the particular variable.
It is mandatory to add comments to all array declarations. The comment should explain what
data gets assigned to the particular array.
Page 8 of 9
WinRunner Coding Standard (WRCS)
It is mandatory to add comments to all calls or call statements. The comment should explain
what the called test or function will do. For example:
5. Indentation
Indentation should be used to clearly define and allow easy access to different sections of the scripts
and compile module. The test script includes places for functions, variables and user action in form of
scripts where as compile module includes user-defined function.
6. General guidelines
1. Hard-coded paths and machine names should be avoided in test scripts. This makes them very
difficult to move from one machine or environment to another. Instead all those will be kept into a
excel file and can be used in the scripts as variable.
2. Unnecessary user messages should be suppressed. – Delete or comment out all debug user
messages, trial code routines. This will ease the batch runs for scripts
3. While running the script synchronization problem may occur. The synchronization problem should
be covered with code only. i.e. the delay for window synchronization should not be set under
Settings-> General options. It should be done with the help of coding whenever needed.
4. The script should complete its run even though verification/check fails. Appropriate setting should
be done for it Setting->Run options of Win runner.
5. User load commands instead of reload whenever it is possible as reload places compiled function
libraries into memory.
6. Consider debugging scenarios while coding itself (Date, time stamps, Level of verbosity in the
result file, Level of Pausing etc.).
Page 9 of 9