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

Showing posts with label QTP Tutorials. Show all posts
Showing posts with label QTP Tutorials. Show all posts

Using Parameterization for data driven testing in QTP/ UFT

UFT/ QTP enables us to configure the values for properties and other items by defining a value as a constant or a parameter. We can also use regular expressions for some values to increase the flexibility and adaptability of our tests. A parameter is value that is defined or generated externally and is retrieved during a run session. A parameter for example can take value from an external source like excel sheet or UFT data tables.

The major advantage or need of using parameters in test is to create data driven tests. 

Let me explain this with an example. Suppose there are two edit controls in the Page Username and Password and user clicks on login button to login.

Suppose the requirement is to create test which will validate different users are able to login into application successfully. If we use constant value for Username and Password and have to validate for 100 Users, we will need to create 100 tests, Maintaining 100 tests is a tedious task and time consuming activity. 

Let me explain this with an example, suppose there is change in identification property of the Username edit box. E.g. Name of Username field is changed to E-Mail and the user using constants is using the local object repository for each test. We need to make change in each of the tests. Maintenance is also difficult because of rework for minor change in script. Also keeping the test executor understand the difference between the tests and which test is for which purpose is difficult task with growth in size of test suite.

Using Parameters in the test solves the above problem, we can iterate the same test steps execution using multiple data set and can compare the expected result with the pre-defined data stored in the data source. 

For e.g for successful login or incorrect password, parameterization using data table object, the code is like:

Parameterization

Browser("qaautomationqtp").page("qaautomationqtp").WebEdit("UserName").Set DataTable("UserName", dtGlobalSheet)

Browser("qaautomationqtp").page("qaautomationqtp").WebEdit("Password").Set DataTable("Password", dtGlobalSheet)

Browser("qaautomationqtp").page("qaautomationqtp").Webbutton("SignIn").Click

In the above example we use the global sheet to drive the data. We can upload data from external excel file or database to datatables in QTP and also extract back the information from data tables to excel using data table import/export methods. Once we have data in the local sheet or global sheet in data table, we can use data as shown in above code in QTP.

By data driven testing using parameterization, we need to create only a single test for 100 of tests using hardcoded approach and also the data is managed at a single place, hence improving the maintenance of the test.

Next question is what all we can parameterize in QTP, we can parameterize :

  • Checkpoints properties

  • Object properties for a selected step.

  • Operation arguments defined for a selected step.

  • Object properties in Object Repository.



The different ways in which data can be parameterized in QTP/UFT are as follows:


  • Test parameters enable us to use values passed in the test.
  • Action parameters enable us to pass values from other actions in the test.
  • Using Random Number, we can parameterize the value where any random numeric value can be provided.

  • Environment variable can be used for parameterization in QTP

    • Using datatables in QTP/UFT, we can parameterize the data. Before running the test we need to specify in Test Setting or action settings in QTP, how many iteration the test needs to be executed


    This article "Working with data tables" explains how to work with data tables in details.

    This article Environment variable explains how to work with environment variable in QTP.


    How to send e-mail using outlook object in QTP

    This post explain how to send e-mail using microsoft outlook object with or without any attachments. In the next article we will explain how to read information from an e-mail message.

    ''Function Description - This function sends a mail to end user
    '' Arguments - SendtoUser - Mail will be send to user mentioned in send to
    ''Subject - Subject of the mail
    ''Body - Text of the mail
    ''Attachment - Path of attachment to send e-mail

    SendMailUsingOutlook "SendToUser@test.com; testZ@test.com"," Subject", "Body", ""

    Function SendMailUsingOutlook(SendToUser, Subject, Body, Attachment) 

    '' create an object of outlook application and creating a new e-mail object
        Set objOutlook=CreateObject("Outlook.Application") 
        Set objMail=objOutlook.CreateItem(0) 

    '' Provide details of the mail object
        objMail.to=SendToUser
        objMail.Subject=Subject 
        objMail.Body=Body 

    '' attach a file with the e-mail, provide path of the attachment in the folder
        If (Attachment <> "") Then 
            objMail.Attachments.Add(Attachment) 
        End If 
    '' Send the e-mail
        objMail.Send 
    '' close the instance of Outlook application object
        objOutlook.Quit 

    ''release the object created    Set objMail = Nothing 
        Set objOutlook = Nothing 
    End Function 

    How to create a database checkpoint in QTP

    A database checkpoint compares the values returned by SQL query during checkpoint execution. Below are the steps to create a database checkpoint in QTP


    • Navigate to Insert>Checkpoint>Database Checkpoint.


    • Define whether to define SQL statement manually or using Microsoft Query


    • Select the database or query if previously defined as shown below.We select QT_Flight_32 database.Click on OK.

    • Select the required columns/tables to be selected in SQL and click on next button.


    • Define conditions for selected columns in the above step and define sorting criteria. Click Next>Next


    • Click on finish



    • Change the properties of database checkpoint and select whether to insert the checkpoint before or after current step and clcik on OK. A database checkpoint is created and inserted in the test.



    Understanding Object Repositories Manager: Managing Objects

    1.  How to Import Object Repository from xml file


    Object repository can be loaded from an external xml file using object repository manager.


    Importing and exporting Object Repositories to/from xml file


    2.  How to export Object Repository to a xml file


    Object repository can be exported to an external file using object repository manager.


    3. Defining Objects manually in object repository 


          A new test object can be added manually using object repository manager. Below are the steps to add object manually in the object repository

    Adding Object manually in Object repository

    • Navigate to Resources>Object Repository Manager
    • Navigate to Object>Define New Test Objects
    • Define new test Object with environment, name, and class of object and add description properties to object.
    • Click on Add to add object.
    • Save object repository as shared object repository


    4.       Add Object to repository

    • User can add an object from  application without recording
    • Navigate to Resources>Object Repository Manager.
    • Navigate to Object>Add Objects
    • Focus on object to be added and click.
    • Object is added to repository.


    5.       Navigate and Learn

    • User can add required objects from application using Navigate and Learn.
    • Navigate to Resources>Object Repository Manager.
    • Navigate to Object>Navigate and Learn or press F6.
    • Define the filter for objects to be added.
    • Click on learn button.
    • Object will be added to object repository


    ·          
    Options of Working with object

    6.       Update Object from Application

    • User can update objects from application with below steps
    • Navigate to Resources>Object Repository Manager.
    • Select an object to be updated. Please note updated object class should be same as the class of object by which it is to be updated.
    • Navigate to Object>Update from application
    • Object properties are updated

    How to debug a test in QTP: Complete Tutorial

    Debugging is the process of locating and fixing or bypassing bugs in computer program code.Before starting debugging in QTP,We need to install Microsoft debugger for debugging. This can be done during QTP Installation.

    Below are the options available in Debug Menu and will discuss the same in detail:



    Pause:

    To detect and isolate defects in a test or function library, you can control the run session using the Pause command. This will pause the test run and you can check for state of objects, and values in variable at the moment of pause to get the issue. You can temporarily suspend a run session by choosing Debug > Pause or clicking the Pause button. The Test execution will resume if we Press F5 or Run.

    Step Into :

    While navigation into a function definition from the function called in script. We can use Debug>Step Into or Press F11 or click on Step into button. Using Step Into, we can debug in the function called in script and run each step line by line in the function.

    Step Over:

    Step Over does debugging line by line in the script, but does not debug into a function called within script, but executes the function as a step and moves to next step in the Test. We can use Step Over using F10 Key or Debug>Step Over or icon for Step Over in the QTP IDE.

    Step Out:

    Suppose we have step into a function as explained in Step To, and wants to come out of the function or Action, we use Step Out Option. We can use Step Over using shift + F11 Key or Debug>Step Out or icon for Step Out in the QTP IDE.

    Run To Step:

    You can instruct QTP to run from the beginning of the test or action or from the current location in the test and to stop at a particular step. This is similar to adding a temporary breakpoint to a step.
    To select Run to Step, Insert your cursor in the step in which you want QuickTest to stop the run and choose Debug > Run to Step or press Ctrl+F10

    Debug from Step

    You can instruct QuickTest to begin your debug session from a particular step instead of beginning the run at the start of the test or action. Before you start debugging from a specific step, make sure that the application is open to the location.
    To debug a test from step, Insert your cursor in the step where you want QuickTest to start the run and choose Debug > Debug from Step.

    Using BreakPoints in QTP:

    We can use breakpoints to suspend a run session and inspect the state of your application or mark a point from which to begin stepping through a test or function library.
    Breakpoints are applicable only to the current QuickTest session and are not saved with the tests.
    Test execution pauses at the step where we provide breakpoint. A breakpoint can be inserted using Debug > Insert/Remove Breakpoint or clicking Insert/Remove Breakpoint button or pressing F9 key on the step.
    To enable\disable a breakpoint,i.e enable a checkpoint if disabled below or vice versa, Press Ctrl + F9 or select Debug > Enable/Disable Breakpoint
    We can enable disable all breakpoint by selecting Debug > Enable/Disable All Breakpoints or click the Enable/Disable All Breakpoints button.


    Debug Viewer in QTP:










    We can  use debug Viewer in QTP to view, set, or modify the current value of objects or variables in your test or function library,  To view Debug Viewer, Choose View > Debug Viewer or click the Debug Viewer button.

    Below are the tabs in Debug Viewer:


    Watch Tab

    This is used to view the value of any variable or an expression in the test. To add an expression, Click the expression and choose Debug > Add to Watch.

    Variables Tab

    QTP automatically displays the current value of all variables in the current action or function in the Variables tab—up to the point where the test or function library is stopped or paused. We can change value of a variable manually also in variables tab. This will be reflected in test.

    Command tab

    This is to execute a line of script to set or modify the current value of a variable or VBScript object in your test or function library.


    All About Working with datatables and data Sheets in QTP: Methods and properties

    Methods for Datatable object


    Following are the methods and properties for interaction with data tables in QTP

    1. Datatable.AddSheet  

    Adds the specified sheet to the run-time Data Table
    datatable.AddSheet(strSheetName)

    2. DeleteSheet

    Deletes the specified sheet from the run-time Data Table.
    Datatable.DeleteSheet(strSheetName)

    3. Export Method

    Saves a copy of the run-time Data Table in the specified location.
    datatable.Export(strExcelFile)

    4.ExportSheet Method 

    Exports a specified sheet of the run-time Data Table to the specified file.
    DataTable.ExportSheet(FileName, DTSheet)

    5.GetCurrentRow

    Returns the current (active) row in the first sheet in the run-time Data Table (global sheet).
    row = DataTable.GetCurrentRow

    6. GetRowCount Method

    Returns the total number of rows in the longest column in the first sheet in the run-time Data Table (global sheet).
    DataTable.GetRowCount

    7. GetSheet Method:

    Returns the specified sheet from the run-time Data Table.
    MyParam=DataTable.GetSheet ("MySheet").AddParameter("Rower", "9")

    8. GetSheetCount

    Returns the total number of sheets in the run-time Data Table.
    intSheet = datatable.getSheetCount

    9.  Import Method:

     Imports the specified Microsoft Excel file to the run-time Data Table.
    DataTable.ImportSheet(FileName, SheetSource, SheetDest)

    10. ImportSheetMethod:

    Imports a sheet of a specified file to a specified sheet in the run-time Data Table.
    DataTable.ImportSheet(FileName, SheetSource, SheetDest)

    11.SetCurrentRow Method:

    Sets the specified row as the current (active) row in the run-time Data Table.
    DataTable.SetCurrentRow(RowNumber)
    DataTable.GetSheet("MySheet").SetCurrentRow(2)

    12. SetNextRow Method 

    Sets the row after the current (active) row as the new current row in the run-time Data Table.
    DataTable.SetNextRow
    DataTable.GetSheet("MySheet").SetNextRow


    13. GlobalSheet Property 

     Returns the first sheet in the run-time Data Table (global sheet).
     DataTable.GlobalSheet.AddParameter "Name", "Nitin"

    14. LocalSheet Property

    Returns the current (active) local sheet of the run-time Data Table.
    DataTable.LocalSheet.AddParameter "Name", "Nitin"


    Methods For DTSheet Object:


    Below are the methods to work with the specified sheet in datatable.

    1. AddParameter Method 

    Adds the specified parameter (column) to the sheet in the run-time Data Table, sets the value of the first row to the specified value

    DataTable.GetSheet("dtGlobalSheet").AddParameter "Name","Nitin"
    DataTable.AddSheet("MySheet").AddParameter("Name", "Nitin")
    paramname = DataTable.LocalSheet.AddParameter("Name", "Nitin").Name 

    2. DeleteParameter Method

    Deletes the specified parameter from the sheet in the run-time Data Table.
    DataTable.GetSheet("MySheet").DeleteParameter("Name") 

    3. GetCurrentRow Method

    Returns the row number of the current (active) row in the run-time Data Table sheet. 
    row = DataTable.GetSheet("MySheet").GetCurrentRow 

    4. GetParameter Method 

    Retrieves the specified parameter from the run-time Data Table sheet. 
    DataTable.GetSheet("ActionA").GetParameter("Date").RawValue

    GetParameter("ParamName").value retrieves or sets the value of the cell in the current (active) row of the parameter in the run-time Data Table. 
    DataTable.GetSheet("Action1").GetParameter("Destination").Value="Pithoragarh"

    DataTable.GetSheet("Action1").GetParameter("Destination").ValueByRow(7) - This gets value for parameter Destination in sheet Action 1 in row 7.

    5. GetParameterCount Method 

    Returns the total number of parameters (columns) in the run-time Data Table sheet.
    paramcount = DataTable.GetSheet("Test").GetParameterCount

    6. GetRowCount Method

     Returns the total number of rows in the longest column in the run-time Data Table sheet.
     rowcount = DataTable.GetSheet("Test").GetRowCount


    Descriptive programming examples and comparison with Object Repository

    Comparing Descriptive Programming with Object Repository


    Suppose we record on Google page for testing and then click back for Search button, steps will be recorded in QTP as shown below. An object reposiory stores all the objects used in the recording. Issue with Object repository is that we need to associate object repository with test for execution and if the project size increase, it becomes difficult to maintain the repository.

    Browser("Google").Page("Google").WebEdit("q").Set "TESTING"
    Browser("Google").Page("Google").WebButton("btnG").Click
    Browser("Google").Page("testing - Google Search").Link("Search").Click

    Suppose we do not want to use objects from object repository, we can use descriptive programming to describe the objects.


    Descriptive programming can be implemented in following two ways:

    1. Using Static description:

    Suppose we have to define description for 
    Browser("Google").Page("Google").WebEdit("q").Set "TESTING"

    We need to do the following:


    1. Use object spy to identify the object in the page, mostly for html pages, html id is unique for the object, so will use html Id as property for the object.




    Browser("title:=Google").Page("title:=Google").WebEdit("html id:=gbqfq").Set "TESTING":

    Also in case of multiple object with similar properties, for example, multiple instances of browser, we can use ordinal identifier to identify the object

    the above code using ordinal identifier and using regular expressions can be written as:

    Browser("title:=.*","index:=0").Page("title:=Goog.*").WebEdit("html id:=gbqfq","index:=0").Set "TESTING":


    2. Using Description Object


    In descriptive programming, we can create description object and define the description of the object. For above code, we can create description object for each of the following:

    Set objdescBR = description.Create
    objdescBR("title").value ="Google"
    Set objdescPg = description.Create
    objdescPg("title").value ="Google"
    Set objdescEdit = description.Create
    objdescEdit("html id").value ="gbqfq"
    objdescEdit("index").value =0

    Browser(objdescBR).Page(objdescPg).WebEdit(objdescEdit).Set "TESTING1"

    Description object can be very useful if we want to perform similar actions of multiples, for e.g checking multiple checkbox, providing same text in multiple edit box and so on. 

    We will describe some examples on Descriptive Programming


    1. Getting total number of links in the page:


    Set objdescBR = description.Create
    objdescBR("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

    Similar to this example, we can fine multiple objects type in the page based on class of the object, Please give it a try for Images, and checkbox in the page


    2. We can also like clicking on a link with a particular name or entering value in a particular edit box with code similar to as  below:


    Call clickLink("Orkut")

    Public Function clickLink(LinkName)
    Set objdescBR = description.Create
    objdescBR("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)
    For i = 0 to objLinks.count - 1
    If (objLinks(i).getroproperty("name") = LinkName) then
    objLinks(i).click
    End If
    Next
    End Function


    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.


    How to write to Text Files using fileSystemObject in QTP

    Using FileSystemObject we can write data to a text file. Below are the steps to write to a text file.


    1. Create an instance of the FileSystemObject

     This is done through
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    2. Use OpenTextFile to open an existing file or CreateTextFile to create a new text file to write data into.

    Set otf = objFSO.CreateTextFile(FilePath,[OverWrite])
    where FilePath is path of file to be created.OverWrite – Flag for overwriting content 

    OR

     Set otf = objFSO.OpenTextFile(FilePath,ioMode)

    where FilePath is path of file to be opened.ioMode – Define mode in which file to be opened. Use 1 to overwrite data and 8 to append data. 


    3. Use below methods to write to the file.


    a. Write(strText) - Write specified string in the text file.

    Otf.Write(strText)

    b. Writeline(strText) - writes a specified string and newline character.

    otf.writeline(strText)

    c. WriteblankLines(intLine) - Writes the specified number of blank lines in the text file

    otf.WriteblankLines(4)

    4. Close the text file.

    otf.close This will close the file. It will close the text file. Note file is saved automatically when we write to a text file.


    5. Set all objects as nothing