yash - qtp_automation

Upload: austinfru

Post on 03-Jun-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Yash - QTP_Automation

    1/106

    QTP Fundamentals

  • 8/13/2019 Yash - QTP_Automation

    2/106

    Contents Fundamentals of Automation Introduction to QTP Testing Process with QTP Object Repository

    Actions Data Tables Parameterization Check Points VB Script Basics File System Objects

    Frameworks

  • 8/13/2019 Yash - QTP_Automation

    3/106

    What is Automation ? Test Automation is the use of Software to control the execution of

    tests & the Comparison of results actual with the predicted.

    A software program test another software program, that is referredto as Automation Software Testing

    A third-party tool is used to test the application

    Use of Automation Tools reduce the test time as well as the cost

  • 8/13/2019 Yash - QTP_Automation

    4/106

    Why Automation? Avoid the errors that human make when they get tired after

    multiple repetitions

    The test program wont skip any tests by mistake

    Requires less human intervention therein reduce the ExecutionTime

    Required easy cycle of Regression Testing

  • 8/13/2019 Yash - QTP_Automation

    5/106

    Benefits of Test Automation Allows more testing to be done

    Testing is consistent, repeatable

    Useful when new patches released

    Makes configuration testing easier

    Increases speed and efficiency

  • 8/13/2019 Yash - QTP_Automation

    6/106

    What Can be Automated? The test cases that need to be run on every new build

    Test that use multiple data values for the same action

    Compatibility Testing

    Regression Test Case Application with objects that doesnt change in the short term.

  • 8/13/2019 Yash - QTP_Automation

    7/106

    What cannot be Automated? Usability Testing

    Not For Short-Time(One Time- Testing)

    Ad-hoc Testing

  • 8/13/2019 Yash - QTP_Automation

    8/106

    Functional/RegressionTesting Tool Rational Robot

    Win Runner

    QTP

    Silk Test

    QA Run

    Web FT

    RFT (Rational Functional Tester)

  • 8/13/2019 Yash - QTP_Automation

    9/106

    Things to be done before Automation

    Identify the various types of test to be covered

    Identify all the modules of the product

    Identify all the functionality of the each module

    Identify all the test cases, which tests the functionality ofthe each module

    Identify the complete scenarios that cannot be automated

    Plan the control & Sequence of the Test

    Decide the repository format

    Freeze the folder structure and Automation Framework to be

    used to the project

  • 8/13/2019 Yash - QTP_Automation

    10/106

    Automation Life Cycle

    Analyze Application and requirements

    Identify test Scenarios

    Identify the testTool

    Decide your Framework

    Design/Record the Test Scripts

    Enhance the Test Scripts

    Debug Test Script

    Analyze the Results

    Reporting Test Results

    and Defects

    Execute the Test Scripts

  • 8/13/2019 Yash - QTP_Automation

    11/106

    Overview Of Automation Plan

    Manual Testing by Live-support Team

    Manual Test ExecutionTest

    Patch 1

    Test

    Patch 2

    Test

    Patch 3Hot Fix Hot Fix

    Main Release

    Automation in Parallel to Manual Execution

    Automation

    POC

    Start

    Automation

    Scripting

    Test Automation for repeatable scenarios

    Test Automation for new customizations

    Automation

    Pack

  • 8/13/2019 Yash - QTP_Automation

    12/106

    Risks associated in Automation Lack of Skilled Resources

    Initial cost for Automation is very high.

    Do not think to automate your UI if it is not fixed

    It would be bad idea to automate testing work in early development cycle

    (Unless it is agile environment). Script maintenance cost will be very high insuch cases.

    You cannot 100% automate your testing work.Areas like User interface,

    documentation, installation, compatibility and recovery where testing must be

    done manually

  • 8/13/2019 Yash - QTP_Automation

    13/106

    Introduction To QTP Developed by Mercury Interactive in 2002 It Supports for both Web Application & Window

    Application

    Developed from Web Functionality

    QTP supports both Technical & Non-Technical people

    QTP runs only on windows platform, not supporting Unix,Linux , Mac etc..

  • 8/13/2019 Yash - QTP_Automation

    14/106

    Environment needs for QTP

    System Requirement : IBM-PC (or) Equivalent to P3

    Hardware Drive : 250MB of Free Memory space

    RAM : 256MB of RAMOS : M/S windows 2000 server with 3-4 service pack

    M/S windows XP with 1-2 SPM/S windows 2003 with no service packM/S win Vista 64 bit (Ver 9.5 feature)

    Web Browser : MS Internet Explorer 5.5 , AOL 8.0, 9.0 ,

    Netscape Navigator 6.11, 6.22, 6.23, 7.02, 7.1,9FireFox 3.0 (Ver 9.5 feature)

    QTP 9.5 Supported Technologies: Power builder , .NET 3.5 ,

    Oracle Form-10 ,114 , Apps 12

  • 8/13/2019 Yash - QTP_Automation

    15/106

    Overview of QTP

    1) Testing Process of QTP

    2) Windows Structure of QTP

    3) Add Ins of QTP4) Architecture of QTP

    5) Execution process in QTP

    6) Development of Automation Test

    7) Recording Modes in QTP

    8) Object Repository

    9) Object Spy

    10) Transaction

    11) Virtual Object

    12) Check Points

    13) Actions

    14) Exception Handling

    15) Object identification

    16) Ordinal Identifier

    17) Smart Identification

    18) Output Values

    19) Synchronization point

    20) QTP Run Modes

    21) Regular Expressions

    22) Descriptive Programming23) Environment Variables

    24) VB-Script

    25) How to work with Functions

    26) Associated Library

  • 8/13/2019 Yash - QTP_Automation

    16/106

    Testing Process of QTP1) Freeze the folder structure2) Do Necessary Add-ins

    3) Create Object Repository

    4) Record & Run Settings

    5) Develop Automation Test Scripts

    6) Enhance/ Customize Automation Test Scripts

    7) Debug Automation Test8) Execute Automation Test

    9) Analyze Test Results

    10) Report defects

  • 8/13/2019 Yash - QTP_Automation

    17/106

    Window Structure of QTP

    1) Test Pane

    2) Active Screen

    3) Data Table

    4) Debug Viewer

  • 8/13/2019 Yash - QTP_Automation

    18/106

    Keyword View

  • 8/13/2019 Yash - QTP_Automation

    19/106

    Expert View

  • 8/13/2019 Yash - QTP_Automation

    20/106

    Add Ins of QTPIt gives information about the technology supported by the QTP

    By default three Add Ins are there in QTP

    1) ActiveX

    2) VB3) Web

    Additional Add ins:

    1) Java

    2) Oracle

    3) People soft4) .NET

    5) Terminal Emulator

    6) SAP

    7) Siebel

  • 8/13/2019 Yash - QTP_Automation

    21/106

    Add In Manager

  • 8/13/2019 Yash - QTP_Automation

    22/106

    Development of Automation Test1) Recording

    2) Writing

    3) Function Generator

  • 8/13/2019 Yash - QTP_Automation

    23/106

  • 8/13/2019 Yash - QTP_Automation

    24/106

    Recording Modes of QTP 3) Low Level Recording Mode : Low level whether or not QuickTest

    recognizes the specific object or the specific operation. This moderecords at the object level and records all run-time objects as

    Window or WinObject test objects. Use Low Level Recording forrecording in an environment or on an object not recognized byQuickTest

  • 8/13/2019 Yash - QTP_Automation

    25/106

  • 8/13/2019 Yash - QTP_Automation

    26/106

    Run Modes Run Modes ToolOption Run Tab

    Normal Mode :-By default, QuickTest records in the normal recordingmode.Its runs your test or component with the

    execution arrow to the left of the Keyword View orExpert View,marking each step or statement as it isperformed

    Fast Mode:- This instructs QuickTest to run your test withoutthe test to run faster.

    displaying the execution arrow for each step, enabling

  • 8/13/2019 Yash - QTP_Automation

    27/106

    Record & Run Settings

  • 8/13/2019 Yash - QTP_Automation

    28/106

    Run a Test and Save Results

  • 8/13/2019 Yash - QTP_Automation

    29/106

    View Test Results

  • 8/13/2019 Yash - QTP_Automation

    30/106

    Object RepositoryObject Repository:-It is nothing but a storage location. It contains the

    collection logical name and physical description of a

    particular object.

    Logical Name:For Naming Convention

    Physical Description :is Nothing but expected physical properties

    There are two types of Object Repositories are available in QTP-1) Per Action (.mtr)

    2) Shared Object Repository (.tsr)

  • 8/13/2019 Yash - QTP_Automation

    31/106

    Object Repository Dialog Box

  • 8/13/2019 Yash - QTP_Automation

    32/106

    Object Spy

    Object spy is used to display or view all the physical properties andmethods of an object or a window based on the requirement.

    Example: If window(Login). Exists Then

    Msgbox(Pass)

    elseMsgbox(Fail)

    End If

    Using the Object Spy, wecan view the properties ofany Object in the openapplication.

  • 8/13/2019 Yash - QTP_Automation

    33/106

    How QTP Recognizes Objects

    For each object class, QTP has a default set of properties that it always

    learns.

    1.Mandatory Properties.

    2.Assistive properties.

    3.Ordinal Identifier. Usually, only a few properties are needed to uniquely identify an object.

  • 8/13/2019 Yash - QTP_Automation

    34/106

    Object Identification

    By using object identification we can map customer userdefined object to standard Class.

    Two types of propertiesare their in object Identification:

    1) Mandatory Properties2) Assistive properties

  • 8/13/2019 Yash - QTP_Automation

    35/106

    Ordinal Identifier

    By using ordinal identifier options quick test able to identify an

    object under ordinal identifier.

    Three Componentsare available in ordinal identifier

    1) Index2) Location

    3) Creation time

  • 8/13/2019 Yash - QTP_Automation

    36/106

    Smart Identification

    Quick test unable to identify the object, it is change randomly. To identifysuch object we need to use Smart Identification.

    Two propertiesare available in Smart identification

    They are-1) Base Filter Properties

    2) Optional Filter Properties

  • 8/13/2019 Yash - QTP_Automation

    37/106

    SynchronizationPoint

    Synchronization point enables the anticipated time problems between the application and

    QTP.

    A progress bar reaches 100% completion.

    A status message appears.

    A button becomes enabled.

    A window opens and is ready for data entry.

    A pop-up message appears in response to an operation.

    There are 2types of synchronization points:

    1) Sync

    2) Wait Property

  • 8/13/2019 Yash - QTP_Automation

    38/106

    How to ADD Synchronization Identify the object to be synchronized.

    Navigate to the window where the object is located.

    Locate the step in the test that corresponds to the object.

    Start recording and add the synchronization point.

  • 8/13/2019 Yash - QTP_Automation

    39/106

    Two ways to set Synchronization

    Global synchronization value for all Objects.

    Instructs Quick Test to wait for all the objects for a specific amount of time.

    Synchronization of a specific Object.

    Instructs Quick Test to wait for a specific object only.

  • 8/13/2019 Yash - QTP_Automation

    40/106

  • 8/13/2019 Yash - QTP_Automation

    41/106

    How to synchronize the Test

    We can synchronize the test by

    1.Inserting a synchronization point

    Insert Step Synchronization point

    Window(Flights).WinButton(Updateorder).WaitPropertyenabled,1,1000

  • 8/13/2019 Yash - QTP_Automation

    42/106

    Synchronization of a Specific Object

    Menu Insert Step

    Synchronization Point

    Quick Test shall pause the

    test until the object property

    achieves the value

    specified here (or until thespecific timeout amount is

    exceeded).

    Quick Test uses one of the

    objects properties as the

    waiting criteria. E.g. Text

    property for window, Labelproperty for buttons etc.

  • 8/13/2019 Yash - QTP_Automation

    43/106

    Virtual ObjectVirtual Object is used to identify the properties of similar objects

    in a particular Area.

    Example:In normal recording if we select the paint brush

    window, the script will look like this-

    Window(Paint).ActivateWindow(Paint).Winobject(colors).Click 72,16

    Window(Paint).Winobject(colors).Click 80,14

    Window(Paint).Close

    If we are using Virtual object, the script will look like this-

    Window(Paint).ActivateWindow(Paint).Winobject(colors).Virtual Button(RED)

    Window(Paint).Winobject(colors).VirtualButton(BLUE)

    Window(Paint).Close

  • 8/13/2019 Yash - QTP_Automation

    44/106

    Check PointsCheck Point is a verification point that compares the current value of thespecified property with the expected value for that property.

    We can Insert checkpoint

    1.From Menu:-Insert Checkpoint Standard Checkpoint

    2.From Keyword view

    3.From the Active Screen

    There are 9 types of check points are available in QTP.They are-

    1) Standard Check Point

    2) Text/ Text Area Check Point

    3) Bitmap Check point

    4) Database Check Point

    5) Table Check Point6) Page Check Point

    7) XML Check Point

    8) Image Check Point

    9) Accessibility Check Point

  • 8/13/2019 Yash - QTP_Automation

    45/106

    Types and Their Use Standard Checkpoint

    Bitmap Checkpoint

    Text Checkpoint

    Checks the property value ofthe object in an applicationor Webpage. It checksbuttons,Radiobuttons,Comboboxes etc

    Checks the value of animage in the application.

    Checks whether the textstring is displayed in the

    appropriate place in yourapplication or on a Webpage

  • 8/13/2019 Yash - QTP_Automation

    46/106

    Database Checkpoint

    XML Checkpoint

    Checks the contents of a

    database accessed by theapplication

    Checks the data content ofXML documents in the

    application.

  • 8/13/2019 Yash - QTP_Automation

    47/106

    Checkpoint Types

  • 8/13/2019 Yash - QTP_Automation

    48/106

    When to Use Checkpoints Before creating checkpoints on web objects we have to select

    web-test option in ADD-IN Manager.

    If the objects developed in HTML we can use Standard Checkpoint.

    If the Objects developed in XML we can use XML Check point.

  • 8/13/2019 Yash - QTP_Automation

    49/106

    How Checkpoints Work - Playback

    Execute checkpoint

    Object: Button

    Logical Name : OK

    Property: Enabled

    Value: True

    Actual =expect

    ed ?

    Test Results

    PASS

    Script Expected Result

  • 8/13/2019 Yash - QTP_Automation

    50/106

    Objects that QuickTest can VerifyWINDOWS WEB

    Window Browser

    Edit Field Text Area

    Drop down list Text Link

    Menu command Images

    Radio Button Image Link

    Checkbox Edit Field

    Windows Object Drop down list

    Status Bar Checkbox

    Text Area Radio Button

    Tables/ Grids

    Web Element

  • 8/13/2019 Yash - QTP_Automation

    51/106

    Insert Checkpoint A checkpoint can be added

    after a test is created.

    Use the Active Screen toselect the field on whichthe checkpoint will beadded.

    Right-click on theappropriate field andchoose Insert StandardCheckpoint.

  • 8/13/2019 Yash - QTP_Automation

    52/106

    How to Add a Checkpoint

    Donotautomaticallyselectthepre-

    definedlistofpropertiestocheck.

    Scrolldownthepropertylisttofind

    theproperty(orproperties)thatbestmeetsthetestrequirement.

  • 8/13/2019 Yash - QTP_Automation

    53/106

    Table Checkpoint

  • 8/13/2019 Yash - QTP_Automation

    54/106

    Database Checkpoint

    Choose Insert > Checkpoint > Database Checkpoint. TheDatabase Query Wizard opens.

  • 8/13/2019 Yash - QTP_Automation

    55/106

    Database Checkpoint cont

  • 8/13/2019 Yash - QTP_Automation

    56/106

  • 8/13/2019 Yash - QTP_Automation

    57/106

    Inserting a Checkpoint During Recording

  • 8/13/2019 Yash - QTP_Automation

    58/106

  • 8/13/2019 Yash - QTP_Automation

    59/106

    Identifying a Failed Checkpoint

  • 8/13/2019 Yash - QTP_Automation

    60/106

    Output Values

    Output Value is used to retrieve the current value of any object in the application

    and stores for further processing

    Insert

    Output Value

    Select the type of output value.

    Right click the object in the Active screen and select the type of output value to be

    added

  • 8/13/2019 Yash - QTP_Automation

    61/106

  • 8/13/2019 Yash - QTP_Automation

    62/106

    How to use Output Value

    Select the

    output to be

    considered

    Select the

    Property

  • 8/13/2019 Yash - QTP_Automation

    63/106

  • 8/13/2019 Yash - QTP_Automation

    64/106

    ParametersObjectives

    Describe and use multiple parameter types.

    Drive data in multiple iterations.

    Analyze errors during iterations.

    Parameterize a checkpoint.

    Types of Parameterization

    Datatable

    Environment variables

    Random numbers Action Parameters

  • 8/13/2019 Yash - QTP_Automation

    65/106

    Data Driven TestTesting the same application with multiple sets of data.

    Input Parameters For Data Driven Tests

    A data-driven test is one that runs a set of user actions with multiple input values. Datadriving allows one script to test application functionality with many sets of data.

    Automated data driven testing frees you to perform more tests, thus increasing testcoverage. Speed, repeatability, free resources to do other kinds of quality control

    How to use parameterization:

    Example:Before parameterization

    Dialog(Login).Activate

    Dialog(Login).WinEdit(name).Set Axis

    Dialog(Login).WinEdit(Password).SetSecureaxisitt

    DialogLogin.Close

    After Parameterization

    Dialog(Login).Activate

    Dialog(Login).WinEdit(Login name).Set DataTable(name, dtglobalsheet)

    Dialog(Login).WinEdit(Password). Set DataTable (password, dtglobalsheet)

    DialogLogin.Close

  • 8/13/2019 Yash - QTP_Automation

    66/106

    A Test with Multiple Actions

    Actions can be divided into logicalsections, like the main sections of atransaction, or by specific businessprocesses.

    When you create a new test, itcontains one action. By dividingyour tests into multiple actions, youcan design more modular andefficient tests.

  • 8/13/2019 Yash - QTP_Automation

    67/106

    Actions

    Action is nothing but a logical portion to entire script file based on the

    requirement. Each and every action should have meaningful result.

    Types of Actions:

    1) Regular (By default)

    2) Reusable

    Tests that contain reusable actions can be used:

    1) Locally

    2) Externally

    How to work with Actions:

    1) Call to copy of Action

    2) Call to Existing Action

  • 8/13/2019 Yash - QTP_Automation

    68/106

    Insert Call to a New Action

    You can add a new action during or

    after recording.

    Select Insert ? New Action from the

    QuickTest main menu. The Insert New

    Action window appears.

    Or use the lego icon on the toolbar

    to insert new action.

  • 8/13/2019 Yash - QTP_Automation

    69/106

    Using Parameterized Data

    Test data can be passed from one testto another test using the value of aninput parameter.

    This creates a data flow betweenbusiness processes.

    The value passed from one businessprocess to another will come from theData Table.

    Be aware of any data dependencies

    that occur within the businessprocess.

  • 8/13/2019 Yash - QTP_Automation

    70/106

    Copied, Existing or New Action

    After reusable actions are created, they

    can be called into a Main Calling

    test in three ways:

    Call to New Action

    Call to Copy of Action

    Call to Existing Action

  • 8/13/2019 Yash - QTP_Automation

    71/106

    Set Actions as Reusable

    Create a reusable action from theAction properties dialog.

    Check the checkbox and click OK. Amessage will appear stating adescription of a reusable action.

  • 8/13/2019 Yash - QTP_Automation

    72/106

  • 8/13/2019 Yash - QTP_Automation

    73/106

    Using Data Sheet

  • 8/13/2019 Yash - QTP_Automation

    74/106

    Setting the Parameter Value

  • 8/13/2019 Yash - QTP_Automation

    75/106

    Test Results Iterations

  • 8/13/2019 Yash - QTP_Automation

    76/106

    Exception Handling

    It enables Quick test to detect and handle when unexpectederror occurred during execution time.

    Types of Exception Handling:

    1) Popup Exception Handling

    2) Object State Exception Handling

    3) Test Run Exception Handling

    4) Application Crash

  • 8/13/2019 Yash - QTP_Automation

    77/106

    Recovery Scenarios

    To instruct Quick test to recover from unexpected events and errors that occurin the testing environment during the run session.

    A Recovery scenario consists of

    a) Trigger Event

    b) Recovery Operation

    c) Post Recovery Run Option

  • 8/13/2019 Yash - QTP_Automation

    78/106

    Recovery Scenario Wizard

    We can create the recovery scenario using recovery scenario wizard.

    Recovery scenario wizard consists of

    a) Define the trigger event that interrupts the run session

    b) Specifying the recovery operations required to continuec) Choosing a post recovery test run operation

    d) Specifying a name and description for the recovery scenario

    e) Specifying whether to associate the recovery scenario to the current test and / or to

    all new tests.

  • 8/13/2019 Yash - QTP_Automation

    79/106

    Recovery Scenario Wizard

  • 8/13/2019 Yash - QTP_Automation

    80/106

    Debugging

    The Pauseoption in the Debug menu is used to temporarily suspend the run. To

    resume running a paused test, click the Runbutton.

    The StepInto(F11) option in the Debug menu is used to run the current line of the

    test. If the current line of the active test or component calls another action or a

    function, the called action/function is displayed in the QuickTest window, and the test

    or component pauses at the first line of the called action/function. Step Out Choose Debug > Step Out or click the Step Outbutton, or press

    SHIFT+F11 only after using Step Into to enter a action or a user-defined function.

    Step Out runs to the end of the called action or user-defined function, then returns to

    the calling action and pauses the run session.

  • 8/13/2019 Yash - QTP_Automation

    81/106

    Breakpoint

    The Insert\Remove Breakpoint(F9) option in the Debug menu is used to

    stop a test run at a pre-determined place in a test.

    To set a breakpoint:

    Step 1 Click a step or a line in the test or component where you wantthe run to stop.

    Step 2 Choose Debug > Insert/Remove Breakpoint, press F9, or click

    the Insert/Remove Breakpointbutton. The breakpoint symbol

    is displayed in the left margin of the Keyword View and ExpertView.

  • 8/13/2019 Yash - QTP_Automation

    82/106

    Debug Viewer

    The DebugVieweroption in the View menu is used to view, set, or modify the

    current value of objects or variables in the test,when a test stops at a breakpoint.

    To open the Debug Viewer pane:

    1 Run a test or component with one or more breakpoints.

    2 When it pauses at a breakpoint, choose View > Debug Viewer or click the Debug

    Viewerbutton.

  • 8/13/2019 Yash - QTP_Automation

    83/106

    Debug Viewer Watch Expressions Tab: Use the Watch Expressions tab to view the current

    value of any variable or VBScript object that you enter in the Watch Expressionstable. Paste or type the name of the object or variable into the Name column andpress ENTER to view the current value in the Value column.

    Variables Tab :Use the Variables tab to view the current value of all variables, inthe current action or selected subroutine, identified up to the point where the testor component stopped

    Command Tab :Use the Command tab to execute a line of script in order to setor modify the current value of a variable or VBScript object in your test orcomponent.

  • 8/13/2019 Yash - QTP_Automation

    84/106

    Regular Expressions

    It enables quick test to identify test string with varying value (varying

    means changing)

    Regular Expressionscan be used in the following areas:1) Check Points

    2) In parameterization

    3) Data Driven test

    4) Actions

    5) Exception Handling.etc

  • 8/13/2019 Yash - QTP_Automation

    85/106

  • 8/13/2019 Yash - QTP_Automation

    86/106

    Some Regular ExpressionsExpression Char Description

    Period . Matches any single character

    Asterisk * Matches zero to any number of occurrences of the preceding character

    Plus + Matches one to any number of occurrences of the preceding character

    Brackets [A-Z][a-z] Matches a range of characters

    [0-9] Matches a range of numbers

    \w Matches any alphanumeric character including underscore

    \W Matches any non-alphanumeric character

    Digit \d Matches any digit

    \d{4} Matches exactly four digits

  • 8/13/2019 Yash - QTP_Automation

    87/106

    Descriptive Programming

    Without using the object repository test engineer can develop automation

    test in this particular accept, we need to use a technique called as

    descriptive programming.

    Script:Dialog(test:=Login).Activate

    Dialog(text;=Login).wineidt(attached text:= Login name). SetAxisitt

    Dialog(text:=Login).wineidt(attached text:= Password). Set 88888

    Dialog(text:=Login).Close

  • 8/13/2019 Yash - QTP_Automation

    88/106

    Environmental variables

    It is a special type of variable which is use to expose the data related toenvironment.

    Environment Variables

    Built In user defined

    Internal External

  • 8/13/2019 Yash - QTP_Automation

    89/106

    VBScript

  • 8/13/2019 Yash - QTP_Automation

    90/106

    Outline Introduction

    Operators

    Data Type and Control Structures

    Arrays

    Database Connection

  • 8/13/2019 Yash - QTP_Automation

    91/106

    IntroductionVBScript

    Subset of Microsoft Visual Basic

    Specific to Internet Explorer

    JavaScript has replaced VBScript as standard

    Most commonly used alongside ASP

    Active Server Pages

  • 8/13/2019 Yash - QTP_Automation

    92/106

    OperatorTypes of operators

    Arithmetic

    Logical

    Concatenation

    Comparison

    Relational

  • 8/13/2019 Yash - QTP_Automation

    93/106

    Operators.. Addition +

    Multiplication *

    Subtraction -

    Division (integer) /

    Division (floating-point) \

    Negation -

  • 8/13/2019 Yash - QTP_Automation

    94/106

  • 8/13/2019 Yash - QTP_Automation

    95/106

    Data TypesSubtype Range/Description

    Boolean True or False

    Byte Integer in the range 0 to 255

    Currency 922337203685477.5808 to 922337203685477.5807

    Date/Time 1 January 100 to 31 December 9999 / 0:00:00 to 23:59:59.

    Double 1.79769313486232E308 to4.94065645841247E324 (negative)

    4.94065645841247E324 to 1.79769313486232E308 (positive)

    Empty Uninitialized. This value is 0 for numeric types (e.g., double), False for

    booleans and the empty string (i.e., "") for strings.

    Integer 32768 to 32767

    Long 2147483648 to 2147483647

    Object Any object type.

    Single 3.402823E38 to1.401298E45 (negative)

    1.401298E45 to 3.402823E38 (positive)

    String 0 to ~2000000000 characters.

  • 8/13/2019 Yash - QTP_Automation

    96/106

    Control Structures..Looping

    If Then.. End if

    If Then ..Elseif ..End if

    WhileWendand Do WhileLoop

    DoUntil Loopand DoLoop Until

    Repeat until loop-continuation condition is true

    For .. Next

    Condition cannot be modified mid-loop

    Optional Stepkeyword

    Select Case ..Case .. End Case

  • 8/13/2019 Yash - QTP_Automation

    97/106

    VBScript IF Then Else End If

    If Then

    ElseIf < Condition> Then 'Optional

    Else

    End IF

  • 8/13/2019 Yash - QTP_Automation

    98/106

    Loops

    For i = 0 to n step 1

    Statement

    Next

    Do while

    Statement

    Loop

    Do until

    StatementLoop

  • 8/13/2019 Yash - QTP_Automation

    99/106

    Select CaseSelect Case

    Case

    Book of statement

    Case

    Book of statement

    Case Else

    Book of statement

    End Case

  • 8/13/2019 Yash - QTP_Automation

    100/106

    User interaction

    Displays dialog that accepts input

    intValue = InputBox( "Enter an integer", "Input Box", , 1000, 1000 )

    Displays message dialog ,Customizable buttons and iconCall MsgBox( "VBScript is fun!", , "Results" )

  • 8/13/2019 Yash - QTP_Automation

    101/106

    Arrays Related data items of same type

    Fixed size or dynamic

    Made up of individual elements

    Accessed via array name, parentheses and index number

    Start at position zero

  • 8/13/2019 Yash - QTP_Automation

    102/106

    Arrays Example Declaring array with three elements

    Dimnumbers( 2)

    Assigning values to each element

    numbers(0) = 77

    numbers(1) = 68

    numbers(2) = 55

  • 8/13/2019 Yash - QTP_Automation

    103/106

    VBScript Simple File I/O Use the FileSyenstem Object

    For opening ,Reading writing and appending etc a file

    Example:-

    Dim fso,tfSet fso = CreateObject("Scripting.FileSystemObject")

    Set tf = fso.CreateTextFile(C:\TestFile",True)

    Write a Line

    tf.writeline(Testing,1,2,3.")

    tf.close

  • 8/13/2019 Yash - QTP_Automation

    104/106

    ADODB connectionUsing ADODB connection we can connect to DBset

    DBobj=createobject("ADODB.connection")DBobj.open("DSN=")

    set rc=createobject("ADODB.recordset")set rc=DBobj.execute("Select * from orders")

    If rc.eoftruevalue=rc.fields(0)

    End if

  • 8/13/2019 Yash - QTP_Automation

    105/106

    Q&A

  • 8/13/2019 Yash - QTP_Automation

    106/106

    THANK YOU

    Contact Email

    [email protected]