Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Showing posts with label Automation Concepts. Show all posts
Showing posts with label Automation Concepts. Show all posts

Properties for object identification in QTP

QTP learns the properties of test objects to uniquely identify the object at run time. There are predefined set of properties for object classes in each environment.


Object are classified as Object classes for each environment. For e.g. environment Standard Windows environment as shown below will have all the test object class defined and defined are the mandatory and assistive properties to identify the object. Also we can set smart identification On for the object and the default ordinal identifier.to identify the object. 


To have a look at Object Identification properties for an object, Navigate to Tools>Object Identifier.


Let us understand the object Identification Window:


1. Environment: Lists all the environment for which objects are defined.


2. Object Classes:
List all the controls available for the environment selected.


3. Mandatory Properties:
These are the properties QTP always learns for the test object class selected.


4. Assistive Properties: In case object is not uniquely identified using the mandatory properties, there are some assistive properties which are learned to uniquely identify the object.


5. Smart Identification
is false by default, but can be checked for identification.


6. Ordinal Identifer: In case object is not identified using the above properties , Ordinal identifier is used to identify the object

List of Regular Expression for UFT/QTP

Regular expression are used to match input text with the pattern provided by regular expression engine. A pattern consists of one or more character literals, operators, or constructs. Below table explains the different regular expression patterns to identify the input text matches the expected pattern


Regular expression are used to validate the input text provided with the expected pattern. e.g : validating date format is correct or telephone number  provided is in correct format.



Reg. Expression

Description

( .)

 A dot matches single character (.) eg test. will match dot followed by any single character.example: testa, test5 

 [ab]

Matches either of the character in the list. e.g 23[ab] will match both 23a or 23b but not 23r

[^ab]

Matches all the characters excluding the the character in the list. e.g 23[^ab] will not match both 23a or 23b but will match23r,235 or 23 followed by any character other

 \b

Matches a word at boundary. e.g test/b will match entest but not entester

 [x-y]

Matches a single character in the range. e.g 23[a-d] will match 23a,23b,23c,23d but not 23r

 [^x-y]

Matches a single character not in the range. e.g 23[^a-d] will not match 23a,23b,23c,23d but 23r

 \B

Matches a word not at boundary. e.g test/b will match entest but not entester

 \W

Matches any non-alphaNumeric character excluding underscore

 \w

Matches any alphaNumeric character including underscore

*

Wildcard character matching the multiple occurence of preceding character. e.g rat* will match ra, rat, rattt, ............i.e multiple occurence of preceeding character t in this example.

 .*

Wildcard character matching the multiple occurence of preceding character.Preceeding character is . in case, so ra.* will match any string starting with ra

+

Similar to * but atleast one occurence of the character should match.e.g : rat+ will match rat but not ra

 ?

 matches zero or one occurrences of the preceding character. For example: ra?t match rt or rat only

 |

Matches either of the character seperated by |.example nes(t|l)ey will match nestey or nesley.

 \d

Matches a digit character

\D

Matches a non- digit/numeric character

\

marks the next character as special character or a literal. e.g \n is for new line ; \\ for \ and \d for a digit character

^

matches the pattern at start of line. e.g: ^test will match testing, tester but not autotest.

 $

matches the pattern at end of line. e.g: test$ will match autotest but not tester.

 |

Matches either of the character seperated by |.example nes(t|l)ey will match nestey or nesley.

 {}

Matches the start and end of qualifier expression. e.g a{4,5} will match aaaa or aaaaa

Reference:  Regular Expression Language - Quick Reference

To view or not the test results in UFT

Once a test is executed in QTP/UFT, test results are displayed. UFT provides us the option to view the test results once the test execution completes. Follow following steps for the same.
  • Navigate to Options>General.
  • There is checkbox "View results when run session ends". In case the checkbox is checked, UFT results are launched automatically once the test execution completes. In case not checked, the results are not launched automatically once execution completes.


viewrunresults

ReConnecting to Remote sessions using group policy edit

In QTP/UFT automation suite execution,we may require to connect remotely to multiple machines through remote desktop connection for monitoring test execution, We may face issue in remote connection being disconnected due to network issues/remote sessions. 


ReConnecting to Remote sessions using group policy edit
To allow smooth test execution, we should reconnect to the remote sessions in case of any network disconnect. In this post, I will share what we can do to reconnect remote connection in case of session disconnect due to network issues and failures.

  • Using experience in Remote Desktop Connection

    • Go to Run>mstsc
    • In Remote Desktop connection window, Go to Experience Panel.
    • Select checkbox "Reconnect if the connection is dropped"
By default, a maximum  of twenty reconnection attempts are made at five second intervals.


  • Defining Group policy for Remote Desktop connection

    • Navigate to group policy for the machine

      • Navigate to run> gpedit.msc
      • Local group Policy editor Window is displayed.
      • Click on Administrative Templates\Windows Components\Remote desktop Services\Remote Desktop Session Host\Connections
ReConnecting to Remote sessions using group policy edit

  • Policy Settings

ReConnecting to Remote sessions using group policy edit

    • Automatic Reconnection- If policy setting is enabled, automatic reconnection is attempted for all clients running Remote Desktop Connection whenever their network connection is lost.
    • Configure keep-alive connection interval - This policy setting allows you to enter a keep-alive interval to ensure that the session state on the RD Session Host server is consistent with the client state. If you enable this policy setting, you must enter a keep-alive interval. The keep-alive interval determines how often, in minutes, the server checks the session state. The range of values you can enter is 1 to 999,999.

MindMap: Testing Process in QTP

In this article, we will discuss the mindmap for testing process in QTP (the same approach can be used with other tools also).Below are the steps in the testing process for QTP to be followed:
  • Analyse the application under test
  • Perform a proof of concept for understanding automation feasibility.
  • Design the automation test strategy and automation framework
  • Create test scripts and integrate with external tools like quality center or ALM.
  • Execute test scripts.
  • Define strategy for support and maintenance of automation suite.

Testing process in QTP/ UFT
MindMap explaining testing process in QTP

MindMap for Automation testing

This mind map illustrates the basic information about automation testing. Following information is mapped in the below mind map:

  • What is automation testing
  • What are the different phases in automation process.
  • What are different types of frameworks.
  • What are different automation tools.
  • What are the advantage of Automation testing

Automation testing mindmap


Tips to be followed for a successful test Automation

We associate a lot of Return on Investment with software automation. There is high expectation from test automation that it will reduce the long regression cycles. But more often than not, we see a lot of maintenance cost associated with the test automation.


In this article, we will discuss why does automation fails and what needs to be done to ensure test automation pass. I have collected the information from feedback received from multiple test automation developers and personal experience.


  • Wait and Study application First –In daily life, we learn is to understand the problem and then react. Similarly, we should never rush into software automation. First step before starting automation is to say hello to the application or system of applications which needs to be automated. Ask questions on the technologies in which the application is developed. E.g.: Is it a web application. Are different technologies used in the application, or there any web services used in the application and so on.
  • Understand the expectation from the client on the scope for the automation.
  • Choose the best tool for automation – Based on the technology used in the application, objects in the application, Choose the best tool for automation. E.g.: Tool A is an open source tool supporting Web application only. Tool B supports both Web Application and web Services both and Tool C supports only Web Services. We have to understand the limitations and benefits of different tools and choose the best suited tool for automation.
  • Do a small Proof of concept on the application to understand whether automation is feasible and we are able to cover the complex scenario in the application with focus mainly on interaction with application, e.g.: Object Identification, Interaction with external cards and systems. Another focus area should be which framework approach will be best suited for the automation, whether to go for Keyword, hybrid, data driven or BDD framework.
  •  Get an initial closure on the scope of the automation with the client in the project and the possible estimate to complete the automation, and the expected maintenance cost for the automation.

Right, we have reached a stage, where we as well client feel automation is possible. Now comes the real part, creating the framework for the Project.


Framework is like the initial building blocks. If it is strong, the building will be strong and will sustain for a longer period of time. Below are the key features of a robust framework structure:


  •  Key Component of an automation framework should be :

    • Error handling

    • Test Reporting – Test Reporting should be clean and easy for a tester to interpret which all tests fail or Pass.

    • Different classes/libraries for different types of methods or functions. E.g. suppose we are creating a project in Selenium. We can create different classes for reporting, common functions, database interaction, and different classes for selenium scripts where WebDriver interacts with application.

    • Creating different libraries helps in better maintenance of automation as we need to change the specific library code. Also suppose we move from Selenium to any other tool in future, the framework will be intact and change required in few classes only.

    • Test data Management for test data, global constant and environment variables

    • Maintaining constants and description properties in property file or separate location. In case property of object changes, we will make changes in the file without going in the scripts.

  • One of the reason for automation failing is the automation suite grows too bulky; Try to divide the test suite into logical units with flexibility to end users to easily select the subset of test suites to be executed.
  • With increasing popularity of agile, the code should be continuously integrated and run with CI.
  • Maintain Version control of automation code to ensure we maintain history of automation code and test artifacts.
  • Reviews and dry run for both positive and negative scenario should be done in the dev phase.
  • Never try to automate the application 100%. Automating one time tests scenario cause load of the automation code growing it larger and making it difficult to maintain.
  • Comments as much as possible in the code. Understanding code of another person or own code, if revisited after long time is very difficult, it becomes more difficult if there are no or very less comments in the code

The list can be huge, but again as we discuss, as we should not try to cover 100% of scenarios in automation. On similar line, creating a post with very large information will fail the purpose of the post. Hope you like the post. Many thanks




How to create a Hybrid Framework in QTP

A hybrid Framework is a framework that uses features of multiple frameworks and is more robust. For e.g, we can create data in external files as in data-driven approach, or creation of keywords as in keyword driven framework. 


Before understanding what needs to be a part of hybrid framework, it is necessary to know what are essential requirements of a framework, Below are the points that needs to be considered before creating a framework.

1. Identify where Test Artifacts needs to be maintained 


Test Artifacts can be maintained in test management tools like Quality Center or can be stored in a shared repository. Using a test management tool, For e.g HP ALM provides following features 

  •  Version controlling of test scripts, function libraries, Object repository, recovery scenario and test data
  •  Multiple Users can at the same time can access the resources in tool.
  • Option to run  set of tests and defining the execution flow can be done using test management tool.


In case of test management tool not available, Test Artifacts should be maintained in a shared folder, so that multiple user can have access to the  resources. In this case, we will require a driver script that will execute multiple test script in a batch and also can be scheduled.

2. Object Identification


Objects Identification is very important and can be identified in number of ways. Some of them are as follows

  • Using Object Repository
  • Using Descriptive Programming
  • Using HTML dom.
  • Using XPath/CSS

A hybrid approach can use a mix of various object identification techniques and can maintain object of different types in different vbs files which can be executed during test initialization.

3. Error Handling and Recovery Scenario


For expected errors, error handling should be implemented in the code and recovery scenario can be used to avoid interruption in test script execution.Code should have enough error handling defined.

4. Reporting


For each failed/passed step in test script execution, reporting in QTP results or user defined html results should be done. Reporting should not be direct using reporter.reportevent but should be wrapped in a function with arguments defined for taking screenshot or exiting the test based on flag status of the argument.

5. Test Data Management


Test data is an important factor in hybrid framework design. Preparation of test data should take into considerations factors like:

  • What are the validations required for test data preparation in fields
  • Can any random data be entered in the fields.
  • How much data is required. e.g bulk data required to execute scripts for multiple iterations.
  • What will be the source of data. Data can be stored on an excel file or can be imported from database at run time if specific existing data is required.
  • In case of large data requirement, test data generation tools like GenerateData can be used.

6. Libraries Management


For each test script execution, An initialization library should be called at the start of script execution which should load the required environment variables, object repositories and other function libraries with application specific code.
Similarly before exit from test script execution, function to close all process that were called during script execution should be executed. Also Code should have enough error handling and reporting, minimum hard code data, and should follow standing coding practices

Understanding QTP Testing process


Quick Test Professional  testing process consists of following phases:


Pre-conditions before testing:


Before recording in QTP ,Please ensure following :

1. Application on which to record is open after qtp is launched.

2. Add-ins based on application are loaded.

3. Unnecessary instances of Internet Explorer and other applications are closed.

4. Ensure record and run settings are as expected and will record on the AUT.



Recording a session on your application


Click on record button in QTP and perform actions on AUT. QTP records every action performed and each element on which action is performed is stored as object in object repository. QTP displays each step in keyword view as tree and in expert view as vbscript.
For Recording, press F5 OR Click on record button.



Enhancing your test

1. Add Checkpoint to define pass/fail condition in the test.

2. Break lines of Codes into functions and increase reusability of test code.

3. Use data table to parametrize data used in the test.

4. Add regular expressions, output value in the test.

5. Add logic and conditional or loop statements that enables to add checks in the test.



Debugging your test

Debug a test to ensure that it operates smoothly and without interruption.To use debugging features , please install Microsoft script debugger. Use breakpoints to pause a test at breakpoints.


Running your test

On running a test using QTP, We know whether the expected behaviour of application matches the current behavior. A test will show pass/fail based on checkpoint on error handling defined through Code.


Analyzing the test results

Once a test is run, we have to analyse results to understand the behavior of AUT. We can analyse whether checkpoint pass or user defined error handling is passed or not.


Reporting defects

Once defects are found in application , they should be reported to concerned team and the tests should pass in case error/defects are resolved




Guidelines and features of different Automation frameworks in QTP

Definition :

A test automation framework is a set of assumptions, concepts and tools that provide support for automated software testing. An Automation Framework is a set of guidelines that you can follow during test case scripting to achieve successful automation results and high return on investment.

Guidelines in creating the automation framework:


1.  Select the tool to be used for test automation
2.  Select type of automation framework to be implemented in the automation based on project complexity and the tool.
3.  Define folder structure to be used for Object repositories, function libraries, test script, test data and other artifacts to be used for interaction.
4.  Validate proper interaction between various resources used in the framework.
5.   Define a driver script to execute test in batches.
6.   Define proper test results reporting to be used in automation.
7.   Define proper error handling and recovery scenarios to be implemented.
8.   Validate functions are created with proper coding standards and ensure high reusability in the framework.

Salient Features


Salient features of good automation framework are as follows:

  • High reusability of automation framework. Functions, structure used in framework should be reusable and easy to implement during script preparation.
  • Maintenance of the framework should be easy and easy to understand for new user.
  • Framework should ensure minimum effort from end user during script execution.
  • Test Results should be self explanatory.
  • Framework should be be able to run scripts smoothly without any issues and proper error handling should be defined in framework.
  • Automation Framework should be robust with good exceptional handling.
  • Automation Framework should be reliable.
  • Automation framework should be application independent.
  • Return on investment should be high in long run for automation. Framework should be choosen and created in such a manner to ensure high ROI.


Types of Automation Framework


Following are the types of Automation Frameworks.

1. Linear Framework:

     Linear scripts are created with steps written in a linear manner. Steps are recorded in this framework using record- play mechanism. This framework does not require any automation expertise as steps are recorded by record and play method.  This is useful for stable application with only a few tests with the same set of data as data is hard coded in this method.

2. Modular or function decomposition Framework:

In this approach test scripts  are first analyzed to find out the reusable flows. Steps for these flows are grouped together to create functions. Still test data is hard coded in this framework although reusability is improved.

3. Data Driven Framework:

      In Data driven framework data is stored in external files in the form of excel file, text files, database. Test data interacts with code through the external file. Since data is stored in an external file, test can be run with multiple set of data without any change in the code.

4. Keyword Driven Framework: 

      In Keyword Driven Framework we create a set of Keywords & Data Tables, the entire functionality of application gets captured as step by step instructions for every test. We create different keywords and associate different actions with these keywords in this framework. Once framework is prepared, it is much easier to implement using keywords defined.

5. Hybrid Framework:  

      This framework  is created by combining different features of different frameworks  and creating a framework with required features of the framework discuss like creating reusable functions, using data driven techniques and defining keywords all in the same framework.

6. BPT Framework:

      Business process testing framework divides test case flow into multiple Business Components. These business component are reusable and can be used in different tests to create workflow and business tests. This framework is maintained in quality center and requires QC to create framework and execute.


Coding Standards: Best Practices in QTP

 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. Coding standard brings in the good rules being followed across projects into the project and hence adds value to the project. It also decreases the maintenance cost, as it is well documented and readable.


General Guidelines

·         Use Option Explicit.
·         Use an ampersand (&) for concatenating strings instead of ‘+’.
·         Set the objects to nothing for cleaning the memory.
·         Declare only one variable in a line.
·         The code should be properly indented.
·         Framework code should be designed and developed with minimal possible loops and conditions for reduced complexity and enhanced maintainability.
·         Modular code for increased re-usability and reduced redundancy.
·         Code should be well indented with tabs. (Tab width should be 4).
·         Values passed and returned to the functions should use simple variables.
·         Reduce the use of global variables within the function. The scope of the variable should be decided based on the standards.

Commenting standards

Comments help to make the code more maintainable. Comments should be used extensively to explain the logic behind most statements. One space should be used between the two slashes. For extensive explanations, an indented section with a meaningful name should be used. 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. Comments on blocks of code are preferable and should express insights and explanations of the code that may not be obvious by looking at the code.  

Code comments

·         Comments need to be included for all complex pieces of code
·         Comments inside a code should follow the same indentation as the code
·         If the code block inside braces is long, the ending brace should carry comments indicating closure of which loop
·         Significant lines in the code should be provided with inline comments to better explain the line of code's purpose and make it easier for subsequent developers to understand the code faster and more thoroughly

Indentation

·          Indentation should be used to clearly define and allow easy access to different sections of the scripts, loops, conditional statements and Functions/Sub Routines, etc. 
·         One Tab (4 spaces) spacing should be maintained in Loops.
·         Comments inside a code should follow the same indentation as the code

Hard coding

Hard coding has to be avoided at all possible scenarios. Particularly 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 excel file or environment variables and can be used in the scripts as variable. This would be very helpful when we have many environments where the script has to be run.

Suppress user messages

While coding we have a tendency to use message boxes and input boxes for the purpose of debugging. We should ensure that 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 and ensure proper execution of script.