Automation Guidelines
Automation Guidelines
Org/Group NBCU
Date 9/5/2006
All document control issues pertaining to this document or for information about its access and location please contact the following resource(s): CONTACT INFORMATION Name: Role: Org/Group: Phone: E-mail Pankaj Aggrawal Automation tester NBC Universal *901-4047 [email protected]
REVISION HISTORY
Section/ Page # 1-22
Date 9/5/2006
Page 2 of 25
6/7/2013
Table of Contents
.I Purpose..............................................................................................4 .II Automation........................................................................................4 What is Test Automation?................................................................................................................... 4 How.. .............................................................................................................................................. 6 To ensure the success of test automation success one needs to Think Past the Project and should execute the project similar to the software development projects. To achieve this one needs to have ............................................................................................................................................................ 6 Plan the entire test automation effort........................................................6 ............................................................................................................................................................ 7 Phase I Pre-Planning ................................................................................................................... 8 Phase III - Automation Process - Key Activities .................................................................................8 Criteria to identify good automation hat is Test Automation?..............................................................9 .III General Guidelines...........................................................................10 .IV Quick Test Pro .................................................................................10 Purpose............................................................................................................................................. 10 .V QTP Specific Best Practices.................................................................11 .VI Script Organization...........................................................................13 .A Coding Standards................................................................................................ 13 .B Naming Conventions........................................................................................... 18 .C Implementation.................................................................................................... 20 .VII Function Libraries............................................................................21 .VIII Directory Structure.........................................................................23 .IX Version Control................................................................................23 .A Check In/Check Out............................................................................................. 23 .X Defect Tracking.................................................................................24 .A Defect Logging & Tracking...................................................................................24 .B Defect Flow Overview.......................................................................................... 24
Page 3 of 25
6/7/2013
.I Purpose
The Process of building automated test script is similar to the process of software development. Thus, Software Engineering best practices should be implemented to ensure that the code is readable and comprehensive, maintainable and reusable whenever possible. This document provides details of these Automaton Test Scripting Best Practices. The standards and best practices outlined in this document should be adhered to for any test automation project.
.II Automation
What is Test Automation? Software test automation is automating the steps of manual test cases using an automation tool, to shorten the testing life cycle. As part of manual testing same test cases have to be executed several times. This might be true when application undergoes regression. Due to human error some of the steps might be missed out or skipped. Automation helps to avoid such human errors and also expedite the process. Implementing successful Test Automation in an SDLC requires a detailed planning and effort. It is required to think Past the Project prior to initiating the task of automation and have a clear picture of final goal that has to be achieved. The below sections describe in detail the approach and process to be followed to achieve an effective and optimized solution for successful Test Automation. Why.. Automation saves time and effort which results in reduction of the Test life cycle. Various test cases (including the data driven tests) can be executed using the automation tool with minimal human intervention and effort thus resulting in reduction of cycle time in test execution. Automation techniques can be made to reduce / eliminate human intervention Benefits of test automation are given below Consistency of test execution and eliminating human error Reducing cycle time of regression test cycles Data driven testing Earlier defect detection. Faster Regression Repeatability Coverage Reliability Reusability
Test Automation Guidelines and QTP Best Practices Page 4 of 25 6/7/2013
The graph below depicts the relationship between effort consumed in automation vs. the time elapsed. A higher initial effort in building a test automation effort results in a long-term benefit.
Complex functionality wherever possible should be automated. This leaves enough time for testers to focus on the other granular tasks related to testing. On other hand these scripts can be used to test the application more rigorously thereby reducing the chances of any defects getting deployed into production.
When .. Before initiating test automation one needs to evaluate whether it is a viable/profitable solution. Automation life cycle is a subset of the entire test life cycle and the same can be started during the initial phases of the Software development life cycle. Automation planning can be initiated in parallel to the test planning phase. To know more about activities performed in each phase here Factors to be considered while deciding for automation
Application is stable It is essential that the Application under test (AUT) is stable enough to develop an automated suite, else the effort that goes in for updating and maintenance of the scripts goes very high. Number of regression cycles to be performed In case testing is in its final phases of development or the number of regression cycles to be performed is relatively low, then it is not advisable to go in for test automation. Compatibility of Application Platform with Testing tools
Page 5 of 25 6/7/2013
Depending upon the Application platform and technology, there are various testing tools available in the market. Rational, Mercury Interactive, Segue and Compuware provide most of the popular testing tools. There are some applications, which cannot be recognized using the available testing tools. Thus the automation of such applications is not possible.
Cost Benefit Analysis. Good testing tools that can be used for developing an effective test suite are expensive. The decision of initiating test automation also depends on the factor if the organization is willing to make the necessary investments. In certain cases it might be a viable solution however due to limitation on time or cost it might not be an acceptable solution Availability of Skill team Success of a Test automation project is a result of effective partnership between the test automation team, manual testing team and the development team. It has been observed during the past experience that the manual testers have a fear of losing there jobs in case the test automation is used for testing. Thus the goal of automation should be very clear with in the team as support of the manual testing team would be inevitable make Test Automation a success.
How.. To ensure the success of test automation success one needs to Think Past the Project and should execute the project similar to the software development projects. To achieve this one needs to have Clarity of what one wants to achieve thru automation. Executing the project similar to a software development project Take up test automation as a fulltime effort and not as sideline Plan the entire test automation effort Develop an automation approach, based on the project requirement and CTQs of the customer Create test framework, which are application-independent Create test design & treat it as a separate entity from test framework Ensure the source code / scripts are properly managed & tracked Track defects in the automated scripts and test them before handing it over to the testing team for execution. Develop help files/ support document for the test suite user.
Test Automation cycle needs extensive planning, development and implementation. Based on the various activities to be performed the entire test automation life cycle can be divided in to different phases. Each phase holds its own value in the test life cycle. A standard Automation Process followed in any Test Automation project depicted in the diagram below
Page 6 of 25
6/7/2013
Page 7 of 25
6/7/2013
Phase I Pre-Planning Perform the Gap Analysis to understand the existing scripts and client CTQs / requirements. Application walk through Create the Traceability Matrix Review the existing manual test scripts. Rewrite unclear/ ambiguous test steps and convert them into modular manual scripts. Ensure that the Application to be tested is stable enough to initiate the development of automated scripts. Verify the availability of the test data (Application Data) in the backend. Incase the data is not available in the application, prepare the valid application Align manual scripts on proposed automation strategy Define expected results for each test step/ test case Prepare valid positive test data (script Data) for test steps wherever required. Identify the smoke test manual test scripts set Identify the regression test suite. Phase II - Test Automation Planning
Create Test Automation Strategy Test Design Coding standard Naming Convention Test Automation Architecture for developing the automation framework Creation of Test bed Script design takes care of the concept of modularity and re-usability. This is depicted in the diagram below:
Phase III - Automation Process - Key Activities Some of the key activities that we perform as part of test automation are listed below:
Develop function libraries consisting of reusable functions, using the automation tool, which can be saved in library files Prepare / maintain Test bed Develop the custom log file Identify the custom objects in the application and map them to a standard object. Create test scripts based on the test steps available in manual test scripts Identify and create the checkpoints and synchronization points to be inserted in the scripts Connect to the database (Excel/database) and parameterize the scripts for data driven testing Exception handling for the scripts Comments to ensure the readability of the scripts
Page 8 of 25 6/7/2013
Re-visit the traceability matrix to ensure the coverage between the Automated test scripts and the Manual test scripts Debug scripts and ensure the smooth running of the scripts Do a peer review of the scripts Maintain the various versions of the automated test scripts using the version control system. Create a test script file to call the automated test scripts in a specified series to be executed in a batch mode Run the test suite in batch mode as per the execution plan Prepare the User Manual document to run the automated test scripts
Adhere to the above-mentioned steps to ensure a test suite that has the following features
Re-usability Develop a robust function library to be used across the projects and within the application. Robustness Develop a robust test suite that can be easily used for testing the application in different environments e.g. development, testing and production. Portability To ensure easy installation of the suite in different environments. Modularity Develop modular scripts to ensure maintainability, scalability and readability of the scripts. Scalability - Scalable scripts which can be upgraded/ enhanced. Maintainability The approach should be such where in major effort goes in to the planning and developing the scripts where as least possible effort is required to maintain the same. Data Driven Testing To perform positive and negative tests using data driven scripts.
Existence/property verification:-Test scripts that involve verification of the existence or properties of the object, text, page, image or database . Automation feasibility :- Test scripts which can/cannot be automated ,should be known prior to classifying the same as a good candidate for automation
Quick Test Pro is a Test Automation Tool that helps teams to automate the test cases, and execute automated test run. Mercury Quick Test Professional provides the industrys best solution for functional test and regression test automation - addressing every major software application and environment. Quick Test Professional satisfies the needs of both technical and nontechnical users. It enables you to deploy higher-quality applications faster, cheaper, and with less risk. Quick Test Professional provides an interactive, visual environment for test development. Mercury Quick Test Professional allows even novice testers to be productive in minutes. User can create a test script by simply pressing a Record button and using an application to perform a typical business process. Each step in the business process is automated documented with a plain-English sentence and screen shot.
Image Checkpoint Bitmap Checkpoint Table Checkpoint Page Checkpoint Data base checkpoint Database checkpoint verifies the data contents in the database. 4. Synchronization points Synchronization points are used to ensure that QT Pro does not try to execute the next statement within the script before the application is ready to accept the next command. Browser name.page name.sync statement is used for synchronization. The options that can be used to synchronize the test are as follows Wait Property The synchronization point instructs Quick Test to pause the test until an object property achieves the value that has been specified. When a synchronization point is inserted in to the test, Quick test pro generates a Wait Property statement in the Expert View. Exist or wait One can insert Exist or Wait statements that instruct Quick Test to wait until an object exists or to wait for a specified amount of time before continuing the test. One can also increase the default timeout settings in the Test Settings and Options dialog boxes in order to instruct QuickTest to allow more time for certain events to occur.
5. Smart Identification During a test run, if the script fails to recognize an object using the mandatory properties of that object, it makes use of the assistive properties, which could recognize that particular object. 6. Shared Object Repository QTP can create and utilize the same object repository file for any number of test scripts which helps in saving a huge amount of disk space and also helps in maintaining consistency if any property of an object is updated. 7. Capturing of Active screen This helps in locating the actual object on the screen during any point in the test run. 8. Call to Win runner test scripts Call to other win runner test scripts can be made in the QTP script, thus saving the previous effort made if any. 9. Comment the code in the script wherever required. 10.Exception Handling Do Exception Handling in the script. Exception handling is done in QTP using Exception editor in QTP. 12. Debug the script Debug the scripts to verify smooth and authentic functioning of the scripts and run one complete cycle of test execution before code freeze.
Test Automation Guidelines and QTP Best Practices Page 12 of 25 6/7/2013
13. Create a test script file to call all the test scripts in a specified series in the batch mode. 14. Run the Test suite in a batch mode. 15. Maintain the various versions of the test scripts using the version control system. 16. New Environment Support: Supports Web services, .NET 2.0, Fire fox 1.5, Netscape 8, Macromedia Flex 2, Win XP 64 bit, Internet Explorer 7, and the latest ERP/CRM applications 17. Open XML Report Format for Test Results: Stores test results in an open XML format, enabling you to easily customize the reports according to your own requirements, and to integrate the test result information with other applications. Test results can now be exported to HTML
.A Coding Standards
This section specifies the various standards to be followed by the SDRUP QA team while developing and maintaining the QT Pro scripts. Goals of these standards This section explains the goal of having the coding standards to be used in the development of test scripts. Following are two basic, but very important goals: The use of these guidelines and standards should result in readable code and should encourage adherence. The resulting documentation should be easy to maintain.
Before having the QT Pro code, one should have a process for writing the code. Thus this section will help the Automation Team to use these standards while developing the code and maintaining the QT Pro scripts. Some amount of standardization is especially important in large development organization such NBC Universal, for writing the programs or scripts. The code will be shared amongst the development and UAT team and will also be used and maintained by the SDRUP QA team. Thus it must be clear what the code does, how it should be used, how it can be extended, etc. The standards within this section have been written to balance the group need for standardization with the individual's desires to code in the ways they feel most efficient.
Test Automation Guidelines and QTP Best Practices Page 13 of 25 6/7/2013
Scope and application of the standards. This section is divided into two areas -- Rules and Guidelines. Rules are those coding standards that are "necessary and required" coding practices that have to be followed by the Test Automation engineer. Everyone is expected to follow these "rules". Guidelines are "suggested" coding practices that have been written to recognize the need for individuality and for common coding practices. The purpose of the guidelines is to provide a framework upon which we can all create better code. However, the guidelines are not meant to impede engineering efforts when these guidelines are found to be in direct conflict with an individual's preference, so long as that preference is implemented consistently and is well documented. Finally, because it has been recognize that this opens the code upon to individual stylist coding habits, it is important that these habits are well documented and will then become the basis for all other updates within the affected files.
Documenting code The documentation section is a block of comments for a particular test script, and describes the objectives, flow and dependencies of the script. The documentation section is required for every script and file. Lack of a documentation block will be severely detrimental to readability and maintainability of the script. The code in the test script should be well commented. The test engineer should include the following in the test script. Any updates made in the script should be documented in the form of the comments. The part of code, which has been changed or added to the script, should be commented so that the author or other test engineers can easily locate any change in the script. Date of change, any cross-reference to the Change Control Form / requisition number and the description of the change and the reason for change has to be included in comments. Purpose of using a function, checkpoint, and external file should be specified using the comments. On the beginning on every Test script the associated Test script in the Quality Center should be mentioned. Layout of QTP Script Files The layout for a class will be broken up into the following main sections:
Page 14 of 25
6/7/2013
Action Header
The Header in each Script File will contain the following information / *======================================================= = */ *Action Name - Name of the Action. The action name will specify the module name * * and type of test action * *Action Type Specify the type of action e.g. Functional * *Module Tested Name of the module to be tested * *Object Repository Name of the Object Repository * *Libraries Used Name of Library files (if used) * *Called From Name of the calling action * *Created by Name of the test engineer * *Date Date of creation of the Test Action * *Updated- Name of the test engineer who updated the script with date * *====================================================== == * Action Code Test Action # Corresponding VB script Code
Guidelines Line Spaces Line width should not ordinarily exceed 80 characters. Use your best judgment. IF / Else Statement Place the IF keyword and conditional expression on the same line. E.g. if (expression) { statement ;
Test Automation Guidelines and QTP Best Practices Page 15 of 25 6/7/2013
} else { or }
statement;
While
The WHILE construct uses the same layout format as the IF construct. The WHILE keyword should appear on its own line, immediately followed by the conditional expression. The statement block is placed on the next line. The curly braces may optionally be indented by up to 1 tab space. Examples while (expression) { statement; } or while(expression) { statement; } Do..While The DO..WHILE form of the while construct should appear as shown below: Examples do { statement; } while (expression); or do { } while (expression); Switch The SWITCH construct uses the same layout format as the if construct. The SWITCH keyword should appear on its own line, immediately followed by its test expression. The statement block is placed on the next line. The curly braces may optionally be indented by up to 1 tab space. examples:
Test Automation Guidelines and QTP Best Practices Page 16 of 25 6/7/2013
statement;
switch (expression) { case n: statement; break; case x: statement; // Continue to default case default: statement; break; } or switch (expression) { case n: statement; break; case x: statement; // Continue to default case default: statement; break; } Test Script Template The test script template will specify the template to be used by the testing team for writing the test scripts. Below is the list of various types of files to be created in the development of the test suite and the template to be used for each type of file. Startup file Single startup file to load the application Load function libraries Make the mappings of the custom permanent.
objects
to
standard
objects
Shell Script File Open connection to the test data set (ODBC /Excel) Call script files Close connection to the test data set Object Repository File:- A file with the extension *.tsr. This file contains the information about the objects used in the test. Script file Separate action for each module Separate action file will be created, depending upon the type of testing performed (e.g. functionality, database)
Page 17 of 25 6/7/2013
Script header is to be included in all the action files. Manual test case name, for which a code is being written, is to be mentioned. Comments to be included. Purpose of using a function in the script, is to be specified in the comments. Preferably small action files with modular approach.
.B Naming Conventions
Following are the naming conventions and standards to be followed by the automation team in the interest of script readability and maintainability. Variables (Based on Scope) Scope Global Prefix g_ Followed by Variable type prefix
Notes: Local Variables do not require a scope prefix. Variables (Based on Variable type) Variable Type String Integer Boolean Float Variant Prefix s i b f v Followed Variable segment Variable segment Variable segment Variable segment Variable segment by name beginning of the name name beginning of the name name beginning of the name name beginning of the name name beginning of the name
with upper case for each with upper case for each with upper case for each with upper case for each with upper case for each
Constants All constants should be Upper case. Example: 1. For variable Sales Invoice which is a string and global the naming should be g_sSalesInvoice 2. For variable Invoice Number which is an integer and local the naming should be iInvoiceNumber 3. For constant File Type the naming should be FILETYPE Functions
Test Automation Guidelines and QTP Best Practices Page 18 of 25 6/7/2013
Functions should be created for repeating steps or activities. Identify Function Candidates before creating Scripts.
Function Type
GUI related Checkpoint related Generic Database Access
Followed by Object name of the name Object name of the name Object name of the name Object name of the name
beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment
The function should be named in the following pattern. <Function Type>_<Module Name>_<Function Name> Example: To name a function for Login in Sales Management module, the naming should be gen_SM_Login .1 Function Documentation For VBS functions, the documentation block should be written as follows. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ ' Description: Login to Mercury Tours '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ ' Parameters: ' sURL - URL ' sUserName - User Name ' sPassword Password Return Value: Status of Login (PASS/FAIL) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ .2 Function Parameters The function Parameters should follow the same naming convention specified above. .3 Return Values If a function doesnt return any value create a Sub Procedure instead of a Function.
Page 19 of 25
6/7/2013
Objects Variable Type Browser Page Window Text Box Label Combo Box Check Box Radio Button Button Image Link Frame Dialog Prefix bsr pge win txt lbl cbo chk rad btn img lnk frm dlg Followed by Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name Object name of the name
beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment beginning with upper case for each segment
.C Implementation
.1 Implementation section structure Scripts should generally be divided into three blocks to ensure readability and maintainability: .a Initialization block All resources/environment variables should be loaded in this block
Test Automation Guidelines and QTP Best Practices Page 20 of 25 6/7/2013
Example: ' Create Objects ExecuteFile "..\..\Keyword\Common\Objects\lib_Object.vbs" rc = gen_CreateObjects("..\..\Mercury\Common\Data\dt_Object.xls") .b Execution block Example: Login to Mercury Tours and Find a Flight rc = gen_Mercury_Login(mercury,mercury) rc = gen_Mercury_FindFlight(roundtrip,New York,Paris,Business) .c Cleanup block This block should close open files and unload resources and cleanup Browsers etc. Example: Close the Browser rc = Browser_Close(bsrWelcome) .2 Pathnames Always use relative path instead of absolute path. Example: Instead of using c:\qtp\mercury\common\dt_Obj.xls use a path with reference to the script like ..\..\common\dt_Obj.xls
For Generic Function Library related to Sales Management Module name it as lib_SM_Gen For Checkpoint Function Library related to Sales Management Module name it as lib_SM_Chk
Page 22 of 25
6/7/2013
See section IX: Version Control for a discussion of the directory structure to be used while scripts are under development and stored in ClearCase.
ScriptC (1.0) If the AUT version changes to 2.0, and ScriptA needs to be modified without any changes in ScriptB and ScriptC, Check Out all the scripts using Activity name AUT 1.0. Modify ScriptA and Check In all the Scripts using another Activity name reflecting the updated version of the AUT, i.e. AUT 2.0. AUT 2.0 ---- ScriptA (1.1) ScriptB (1.0) ScriptC (1.0)
.X Defect Tracking
.A Defect Logging & Tracking
All the defects will be tracked in ClearQuest. There will be a dedicated ClearQuest project for each automation effort. For example, there is a ClearQuest project called "FATS" and another ClearQuest project called "FATS Automation." Automation defects should be tracked in the FATS Automation project, not in the regular "FATS" project, and vice-versa. When applying bug fixes to an automation that has been copied to Quality Center, these bug fixes should be applied to the scripts in ClearCase and re-tested before being copied to Quality Center. Automation scripts should be copied to Quality Center only when they are believed to be bug-free and ready for execution.
Page 24 of 25
6/7/2013
Return to Dev
Move to Test
Reopen
Submit Opened
Analyze Analysis
Schedule Design
Design Completed Development Return to Design Hold Hold Design Analysis Hold Development Reopen On Hold
Test Passed
Close Closed
Withdraw Reopen
Withdrawn
Opened
Development
Close
Dev Completed
Page 25 of 25
6/7/2013