qtp tutorial

Click here to load reader

Post on 12-Oct-2015

14 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

qtp

TRANSCRIPT

  • 5/21/2018 QTP Tutorial

    1/28

    QTP Tutorial #17Test Automation

    FrameworksKeyword Driven and Linear

    Framework ExamplesWhat is Test Automation Framework?

    In the context of successful implementation ofQTPfor a software testing project we often come

    across the concept of frameworks. Framework is nothing but the approach that we consistently

    follow during the automation processa set of guidelines.

    Personally, I dont like to give names and say that one works better than the other. The selection

    of a certain framework is not the beginning of a project. It is the reverse that is true. In theprocess of devising a testing strategy you build the rules that are applicable to the testers current

    situation and that right there is your framework.

    Having said that, the following are some of the important points we need to consider:

    1.

    Reusability

    2. Scripts easy maintenance

    3.

    Readability of scripts

    4.

    Good workable folder structure for all the test assets

    5.

    No hard coding values

    6.

    No cascade of failures. (i.e. if one test fails, it should not cause the failure or stopping of the

    others)

    This is the basic list and more can be added based on the requirement.

    Any testing strategy that tries to incorporate some or all of these above points is your TestAutomation Framework.

    There are various names and types of frameworks. The following is the list of frameworksaccording to me:

    http://www.softwaretestinghelp.com/qtp-quicktest-professional-tutorial-1/http://www.softwaretestinghelp.com/qtp-quicktest-professional-tutorial-1/http://www.softwaretestinghelp.com/qtp-quicktest-professional-tutorial-1/http://www.softwaretestinghelp.com/qtp-quicktest-professional-tutorial-1/
  • 5/21/2018 QTP Tutorial

    2/28

    Types of Automation Frameworks:

    1. LinearSimplest form of creating a test. Just write a one single program without modularity in

    sequential steps

    2. Keyword drivenCreate different keywords for different set of operations and in the main

    script we can just refer to these keywords.

    3. Data drivenTo run same set of operations on multiple sets of data that are kept in separate

    files, mostly excel sheets.

    4. HybridA combination framework that can be partly data driven and partly keyword driven

    5. BPTThis just means that programs are broken down into business components and are used

    with one or the other of the above types of frameworks

    Linear Framework

    As discussed this approach involves simply writing the code as we record and keep going.

    For example, if the operation that you have to verify is the creation of a new account in gmail the

    following will be the steps:

    a) Open gmail.com

    b) Click on Create Account

    c) Enter the detailsd) Verify the detailse) Create the account

    http://cdn.softwaretestinghelp.com/wp-content/qa/uploads/2013/05/types-of-automation-frameworks.png
  • 5/21/2018 QTP Tutorial

    3/28

    'Open GMailSystemUtil.Run "iexplore.exe", "http://www.gmail.com"'Page SyncBrowser("Gmail").Page("Gmail").Sync Click on create accountBrowser("Gmail").Page("Gmail").WebLink(Create Account).ClickEnter the detailsBrowser("Gmail").Page("Google Accounts").WebEdit(First Name).SetSwatiBrowser("Gmail").Page("Google Accounts").WebEdit(Last Name).SettestFill in several other detailsSubmitBrowser("Gmail").Page("Google Accounts").WebButton(NextStep).click

    The above is an example of how a program that uses the linear method looks like. It is obvious atthis point what the advantages and disadvantages of this method are.

    Advantages:

    1.

    Simplicity. For beginner programmer this method is apt

    2.

    TimeIt does not take a lot of time to create the test

    3.

    Very little planning is required

    Disadvantages:

    1.

    No reusability at all

    2. If there is another script that verifies a certain aspect of the Google Accounts Page then you

    will have to rewrite the code to launch gmail.com page too. So lots of repetition.

    3.

    All the data is directly embedded into code. The hard coding does not let the code be used for

    any other set of data.

    4.

    Error prone and maintenance is difficult

    While the cons outweigh the pros, this method can be used when your aim is strictly to

    accomplish a task without validations.

    The components or test assets in this kind of frameworks are:

    1.

    Test script

    2.

    Object repository (This can be avoided by using descriptive programming if needed)

    Keyword driven Framework

    How can we make the above linear framework test better? How can we overcome the cons?

    Obviously, we need reusability, modularity and readability. Trying to incorporate these features

    and arriving at an optimum solution is nothing but an attempt at creating a new, more improved

    framework.

    http://www.gmail.com/http://www.gmail.com/http://www.gmail.com/
  • 5/21/2018 QTP Tutorial

    4/28

    What are the reusable components?

    Launching of gmail and arriving at the Google Accounts page. This is a given, sincevalidating this page means to first get here. GoTo Google Account can be made into a

    separate function that can be called over and over again.

    Enter the details and validating themYou can further break this up into positive and negativeblocks to include more level of modularity

    Account creationThe final level of validation and accomplishing the task at hand

    Once you have arrived here, not only have you identified components that can be called over andover again, but you have also broken you linear program into modules.

    Functions:

    So far in our series we have not dealt with functions.Functions are nothing but a piece of code

    that does a certain operations. It accepts input parameters from the program that calls it andreturns value to it.

    As a general practice all the reusable pieces of code are grouped into a file that contains all the

    reusable functions. This file is associated as a resource to your QTP test. Typically a function

    library can be a file of the type: .vbs, .txt or .qfl

    Back to our exampleThis is how the function library file can be:

    FunctiongotoGoogleAccount()'Open Gmail

    SystemUtil.Run "iexplore.exe", "http://www.gmail.com"'Page SyncBrowser("Gmail").Page("Gmail").Sync Click on create accountBrowser("Gmail").Page("Gmail").WebLink(Create Account).ClickEnter the detailsEndFunctionFunctionEnterDetails()Browser("Gmail").Page("Google Accounts").WebEdit(First Name).SetSwatiBrowser("Gmail").Page("Google Accounts").WebEdit(Last Name).SettestFill in several other detailsEndFunction

    FunctionSubmitToCreate()SubmitBrowser("Gmail").Page("Google Accounts").WebButton(NextStep).clickEndFunction

    http://www.gmail.com/http://www.gmail.com/http://www.gmail.com/
  • 5/21/2018 QTP Tutorial

    5/28

    Now your actual script will be:

    'Open GMailgotoGoogleAccount()Enter the detailsEnterDetails()

    SubmitSubmitToCreate()

    From the above program it is now clear that we have achieved readability, modularity and if in

    case another program wants to use the login function, we can surely reuse it. All you have to do

    is associate the function library to that new test too and you are good to go.

    You can also see that in your script the function names are functioning as if they areVBScripts

    keywords and hence the name for this framework.

    The components or test assets in this kind of frameworks are:

    1. Test scripts

    2. Shared OR3. Shared function library

    Now, what else would make this program even better? If we could make the EnterDetails()function to take different sets of data and create different accounts and not be limited to the data

    that we hard coded into the program. That exactly is the next step. Data driving your tests and the

    approach where we do this is the data driven framework.

    http://www.softwaretestinghelp.com/qtp-tutorial-9-vb-script-basics-part1/http://www.softwaretestinghelp.com/qtp-tutorial-9-vb-script-basics-part1/http://www.softwaretestinghelp.com/qtp-tutorial-9-vb-script-basics-part1/http://www.softwaretestinghelp.com/qtp-tutorial-9-vb-script-basics-part1/
  • 5/21/2018 QTP Tutorial

    6/28

    QTP Tutorial #16Steps to Insert XML,

    Accessibility, and Database Checkpoints

    Today we will continue with remaining QTP checkpoints i.eXML, Accessibility, and DatabaseCheckpoints. This is the last tutorial onQTP checkpoints.We have covered details of all QTP checkpoints

    in last 4 tutorials.

    XML checkpoint:

    By adding XML checkpoints to your test, you can check the contents of individual XML data

    files or documents that are part of your Web application.

    1. You can perform checkpoints on XML documents contained in Web pages or frames, on

    XML files, and on test objects that support XML.

    2. An XML checkpoint is a verification point that compares a current value for a specified

    XML element, attribute and/or value with its expected value.3. When you insert a checkpoint, QuickTest adds a checkpoint step in the Keyword View

    and adds a Check CheckPoint statementin the Expert View.4. When you run the test, QuickTest compares the expected results of the checkpoint to the

    current results. If the results do not match, the checkpoint fails.

    You can create three types of XML checkpoints:

    1. XML Web Page/Frame Checkpoint. Checks an XML document within a Web page or

    frame.2. XML File Checkpoint. Checks a specified XML file.

    3.

    XML Test Object Checkpoint. Checks the XML data for an object or operation.

    The method to insert this ch