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

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

WebTables in UFT - 10 Key points

1. WebTable or html grid are integral part of html pages and a lot of application data is organised in WebTables. QTP provides different methods to interact with the webtable in the web application. In this remaining article, we will discuss key points to interact with the webtables. 
Below image shows how a webTable is divided into column and rows and data can be extracted from cell in the web table.


2. Verify if the table exist in the application
istbleExist=Browser("qaaqtp").Page("title:=.*").WebTable("name:= DataTable").exist

3. In case the table exist in the Page, we can get the count of rows and columns in the application as shown below:

iRowCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:= DataTable").RowCount
'' for each of the  row, get the column count for each row
For rownum=1 to iRowCnt
 iColCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ColumnCount(rownum) 
 MsgBox iColCnt
Next

4. Now we know the number of rows and columns in the table, we can extract cell information using the code below:
CellData= Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").GetCellData(rownum,colcnt)

5. We can perform action on object of specific type in a cell in the webTable based on the cell
ibtnCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable")
.ChildItemCount(4,3,"WebButton")
This will get the number of child items in a particular cell of particular type.

6. This will click on the 2nd  webbutton in row 4 and column 3 of the webtable.
Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItem(4,3,"WebButton",1).click

7. Using HTML DOM also, we can get count of objects in a webtable
ielemCnt = Browser("Google").Page("title:=.*").WebTable("name:=DataTable").object.getElementsbyTagName(strTagName).length

8. We can get row count of element based on the cell text as below:
irownum = object.GetRowWithCellText ("text to search",columnnum, startfromrownum)

9. We can work with webtable together with dynamic descriptive programming as shown below:
Set objDesc = Description.Create
objDesc("micclass").value = "WebElement"
objDesc("html tag").value = "TD"
Set childobjdesc=Browser("Google").Page("title:=.*").WebTable("name:=DataTable")ChildObjects(objDesc)

10. Using ChildItemCount and childItem, we can extract information from webTable as shown below:

Public Function findObjectinWebTable(strobjType,iRow,iCol)
 ''get child count of specific object type
 oChildCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItemCount(iRow,iCol,strobjType)
 If oChildCnt >0
  ''Perform action based on object type
  Set ChldItem = Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItem(iRow,iCol,strobjType,0)
 If (strobjType = "Link" or strobjType ="WebEdit") Then
  ChldItm.Click
  ElseIf(stobjType = "WebCheckBox") Then
  ChldItm.Set "ON"
 End If
End Function

Descriptive Programming in UFT : 10 Key points

1. Descriptive programming is describing the object properties in the code itself instead of defining an object in the object repository.

2. Descriptive programming has two flavors: 
 a.) Static DP
 b.) Dynamic DP

3. Static DP defines the object property in inline description in the Page tree structure as defined below:
''example 3.1) - In case all the object in the tree are defined as static DP
Browser("title:=Bing").Page("title:=Bing").WebEdit("name:=qb").Set "test automation"

''example 3.2) Multiple properties are used to uniquely identify an element,
 the properties are seperated by ,
Browser("title:=ng").Page("title:=ng").WebEdit("name:=qb", "type:=input").Set "test"


4. The structure of element in the page follows the tree structure as Browser --> Page --> WebElement.
We cannot define browser and page as descriptive programming, in case  last element in the tree(WebEdit, WebElement is defined from Object repository.

5. Dynamic description example is shown below:
Set objdescBR = description.Create
objdesc("title").value ="Google"
Set objdescPg = description.Create
objdescPg("title").value ="Google"
Set objdesc = description.Create
objdesc("micclass").value ="Link"
Set objLinks = Browser(objdescBR).Page(objdescPg).childobjects(objDesc)
Msgbox objLinks.count

6. Dynamic description is useful to perform similar action on group of elements. e.g: get the text of all the links in the page.

7. Set objLinks = Browser(objdescBR).Page(objdescPg).childobjects(objDesc) returns list of elements. This can be a list of links in the page or multiple checkbox
in the page.

8. We can access each element of group of element using objLinks(index) as shown below:
For i=0 to objLinks.count -1 to Step 1
 objLinks(i).GetRoProperty("name")
Next

9. Descriptive programming is very useful in case of:

9.1 - Common element definition used across a set of pages in the application. e.g: Canel, OK, New button
9.2 - In case of DP programming used in function libraries, the objects are defined in Function library and can be used in multiple tests.
9.3 - Performing same action with multiple elements with similar properties.
9.4 - Maintaining OR can be complex and OR size may grow considerably in the application. 
9.5 - Application is not ready. 
9.6 - Keyword driven framework.
9.7 - A good approach is to use a mix of Object Repository and Object repository and xpath definition.

10. Regular expression can be used together with Descriptive programming, which can again be part 
of another article 10 things to know, regular expression with descriptive programming.

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

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

Mindmap explaining automation framework

In this mind map, we will discuss on automation framework in QTP explaining:


What is automation framework, what are different types of framework, what are key features of an automation framework and expectations from an automation framework:


Mindmap explaining automation framework

Content in the mindmap:
Automation  Framework in QTP
1. Set of Guidelines
1.1 Coding standards
1.2 Structure of test Data
1.3 Folder structure
1.3.1 Test Scripts
1.3.2 Test Libraries
1.3.3 Test Data
1.3.4 Test results
1.4 Object Repositories


2. Decisions
2.1 Decide automation framework to be used
2.2 Decide object Identification technique
2.3 Decide on set of automation guidelines

3. Framework Types
3.1 Linear
3.1.1 Script created by recording on AUT
3.1.2 Script creation is simple, fast and require minimal knowledge
3.1.3 No reusability of code and  high maintenance cost
3.2 Functional Decomposition
3.2.1 Divide test into logical groups or functions
3.2.2 Reusability of code is better
3.2.3 Scripts cannot be run with multiple set of data
3.3 Data Driven
3.3.1   Test data stored in external files drives automation by executing scripts with multiple sets of data
3.3.2 Covers multiple scenario with same script and change in data does not require change in scripts
3.3.3 Additional effort of creating test data and good knowledge of tool for resource
3.4 Keyword Driven
3.4.1 Object, action and arguments are maintained in an excel sheet in form of keywords
3.4.2 Highly reusable code can be used across applications. Once framework is created, easy to create test scripts.
3.4.3 Initial investment in creating framework is high and understanding framework for new user is comparably difficult
3.5 BPT Framework
3.5.1 BPT Components linked together to create test script using Quality center.
3.5.2 Easier for business users to create scripts
3.5.3 License cost of BPT and dependency on QC
3.6 Hybrid Framework
3.6.1 Uses best features of various frameworks
3.6.2 Highly robust and maintainable if properly implemented
3.6.3 Require skilled automation experts.


4. Great Expectations
4.1 Framework should Support Versioning Controlling for files
4.2 should be executed in different environments
4.3 minimal change in script for object changes
4.4 Robust and easy to interpret reporting system
4.5 Should have strong error handling and recovery scenarios

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


Understanding Parameters in TestNG tests

Parameters can be passed to a method from testNG.xml file. In this article, we will discuss on how to Pass parameter value in the methods.


Focus Area of this article:

  • How to pass a parameter from Testng.xml file to the test method.
  • How to define default value of a parameter in a test method.
  • How to pass multiple parameters through TestNG,xml

How to pass a parameter from Testng.xml file to the test method: 


In the below code, we have defined parameter with name as "Param1". Method mailval has argument test which will accept the value as defined in TestNG.xml file.

package testNG;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class NewTestoptionalParameter {
@Test
@Parameters("Param1")

  public void mailval(String Test)
  {
   System.out.println(Test);
  }
}

In the testNG.xml file, we need to provide the parameter with name and a value assigned to the parameter as seen below. So if we execute this test from testNG.xml file, we will get the output as Parameter has name as param 1.

 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">  
 <suite name="Suite1">  
 <parameter name="Param1" value="Parameter has name as param 1" />  
 <test name="Test1">  
 <classes>  
   <class name="testNG.NewTestoptionalParameter"/>  
 </classes>  
 </test>  
 </suite>  

Let us assume scenario where we have added a parameter in the Test method, but does not define and provide the value of the parameter in the testNG.xml file as shown in the below xml file code.In this case, on execution of the test, we will get the output as blank.

 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">  
 <suite name="Suite1">  
 <test name="Test1">  
 <classes>  
   <class name="testNG.NewTestoptionalParameter"/>  
 </classes>  
 </test>  
 </suite>  

We can assign default value to a parameter using Optional as shown in the code below. Now in case we do not define the parameter in the TestNG.xml file, the argument will work with the assigned default value and will output in console as "testing".

package testNG;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class NewTestoptionalParameter {
@Test
@Parameters("Param1")

  public void mailval(@Optional("testing") String Test)
  {
   System.out.println(Test);
  }
}

Next thing, we can define multiple parameters for a method as shown in the code below:

package testNG;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class NewTestoptionalParameter {
@Test
@Parameters({"Param1","Param2"})

  public void mailval(@Optional("resting") String Test, String Test1)
  {
   System.out.println(Test);
  }
}

And finally , we can define the test parameter at test level as well as suite level. If a parameter is defined at both test as well as suite level, Parameter value defined at test level is considered. 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1">
<parameter name="Param1" value="Parameter has name as param 1s" /> 
<test name="Test1">
 <parameter name="Param1" value="Parameter has name as param 1t" /> 
 <parameter name="Param2" value="Parameter has name as param 2t" /> 
<classes>
    <class name="testNG.NewTestoptionalParameter"/>
</classes>
</test>
</suite>

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

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.