29
Automation Testing- QTP Rajesh Charles Batch No: Date: jan-12-2014

Automation Testing- QTP Rajesh Charles Batch No: Date: jan-12-2014

Embed Size (px)

Citation preview

Automation Testing- QTPRajesh Charles

Batch No:Date: jan-12-2014

Agenda (Complete Course)IntroductionTesting MethodologiesManual TestingPractical WorkshopAutomation TestingPractical WorkshopPerformance TestingPractical WorkshopSQL for Beginners Quality CenterUNIX for BeginnersInterview Practice and Mock Interview

Agenda (Today’s Class)What is Automation Difference between Manual testing and

Automation TestingWhat is Codding Language (VB Scripting)Introduction to QTPPractical Workshop

Software testing – Automation TestingAutomated software testing is a process in which software tools execute pre-scripted tests on a software application before it is released into production.

Pre-scripted

Difference between Automation and Manual TestingManual Testing Automation Testing

1 Time consuming and tedious: Since test cases are executed by human resources so it is very slow and tedious.

Fast Automation runs test cases significantly faster than human resources.

2 Huge investment in human resources: As test cases need to be executed manually so more testers are required in manual testing.

Less investment in human resources: Test cases are executed by using automation tool so less tester are required in automation testing

3 Less reliable: Manual testing is less reliable as tests may not be performed with precision each time because of human errors.

More reliable: Automation tests perform precisely same operation each time they are run.

4 Non-programmable: No programming can be done to write sophisticated tests which fetch hidden information.

Programmable: Testers can program sophisticated tests to bring out hidden information

What is Codding Language – VB ScriptVBScript, modeled on Visual Basic, is an active scripting language developed by Microsoft VBScript is a light programming language that uses the Component Object Model to access elements of the environment within which it is running.

Component Object Model

COM or 'Component Object Model' is a method by which an application exposes its functionalities to other applications & programming languages using a set of methods and functions.

Lets Execute a VB script

VB Script

Integer: Whole numbers are all natural numbers including 0 e.g. 0, 1, 2, 3, 4… Integers include all whole numbers

Rational Number: Rational number but not an integer. All rational numbers belong to the real numbers

String: Strings, which are widely used in VB programming, are a sequence of characters

Decimal: Decimal Format is a concrete subclass of Number Format that formats decimal numbers

Variable: In programming, a variable is a value that can change, depending on conditions or on information passed to the program.

Eg; a=100 a=300Where “a” is the variable

What is Codding Language – VB ScriptWhat is VB? Why VB in QTPVariables and ConstantsMsgbox, Inputbox, vbCRLFRunning ScriptsConcatenation operatorManaging long StringsRun from Step and Run to StepFor and While Loops

VB Script - PROCEDURES

Procedure is a set of statements that perform a specific task

VB script of 2 types of Procedures

1. Function Procedures2. Sub Procedures

Function Procedures

A series of statement enclosed within Function and End FunctionCan perform an action and return a valueCan take arguments that are passed to it by a function callWithout arguments, Functions must include an empty set of parentheses ()Returns a value by assigning a value to its nameFunction Procedures in VB script of 2 Types

1.User Defined Functions2.In Built Functions

VB Script – User Defined FunctionSyntax for Function : To write a Function

Function functionname (parameters, if any)

Your code here ……

End Function

Lets do an example

Syntax for Function : To call a Function

Call functionname1. Use Call only when we don’t want the return value of the

function2. When Call is used the arguments should be put in

parenthesesfunctionname1.if the return value is going to be stored in a variable then

argument should be parentheses2.If return value is not stored then argument should not be in

parentheses

OR

VB Script – User Defined Function A Function without parameter (no input)

A Function with one parameter (input to a fn)

A Function to add 2 numbers with parameters and Print the result

inside the Function

Change the above Function to capture the return value outside the

Function and Display

Modify the grade program using Function

VB Script – Advantages of Function Code Reusability

Easier to debug

Easy to Use

Recursive call is possible

Easy to manage and change

Reduces the number of line of code in the program

VB Script –Function Exercises

1. Write a function without any parameter. Put a message box in it

which should display your name. Call the function

2. Write a function to multiply 3 numbers. Do not pass the numbers in

the function call. Declare and initialize the variables with numbers

within the function. Write the msgbox to display the result within

the function.

3. Write a function to divide 2 numbers. Pass the numbers in the

function call. Write the msgbox to display the result within the

function

4. Write a function to subtract 2 numbers. Pass the numbers in the

function call. Capture the results of the function returns outside the

function. Display the results outside the function

5. Put the above function in a function library. Pass the numbers from

the test and get the results back into the test.

VB Script – Array Function Array – To create an array

IsArray – Tells whether a variable is an array

Lbound – returns lower bound of an array

Ubound – returns upper bound of an array

Split – Splits or breaks a string into an array base on a delimiter

Join – Joins an array into a string using a delimiter

VB Script – Exist Property

Exits Property : Check whether the object currently exits in the open

application

Syntax: object.Exist(Timeout)

If a timeout value is specified, QTP waits until it finds the object or

until the timeout is reached.

If the value 0 is specified, the property returns the True or False

value immediately

If no value is specified, the value specified in the Test Settings dialog

box for the object synchronization timeout is used for test. The default

is 20 seconds

File Settings Run Object Synchronization Timeout

QTP - Synchronization

There will be situations where the application does not respond with

the same speed of the test. For example

For a progress bar to reach 100%

For a button to become enabled

For a window or pop-window to open

These anticipated timing problems may cause the scripts to return

inaccurate results. These problems can be handled by synchronizing

the test

Synchronization makes QTP wait until the application is ready for the

next step

QTP - Synchronization

1. Wait Statement

2. Inserting a Synchronization point (WaitProperty):

Insert Synchronization point (enabled only while recording) Can

even be written in the Expert View

Using Exist property

3. When working with tests, we can increase the default timeout

setting (20secs) for a test to instruct QTP to allow more time for

objects to appear

File Setting Run Object Synchronization Timeout

QTP – Data Driven testing

1. Data-driven testing is a framework where test data, expected

result, actual result, status etc is put in and read from outside of

the test script

2. Source for Data can be Database, Excel Files, DataTable, Notepad

files, XML files etc

3. Reading of the data files and rest of the code and logic is written in

the test script

4. Test scripts are built in such a way that they should work for

different sets of data without any changes.

QTP – Data Driven testing

QTP – Data Driven testing – Data Table A QTP Test consists of Actions

By default a test contains one Action (Action1)

A new test in QTP by default has one Global sheet and one local

sheet (of Action 1) in the DataTable

Every new Action added to the test will come with a local sheet of it

s own

The name of the Action will be the name of its local sheet

More sheets to a test can be added programmatically

Global, Local and all other sheets can be accessed by any Action

(Data in any action can be used in any other actions)

By default, one row is enabled in the Global and Local sheets

More rows get enabled as data is entered into the respective sheets

View DataTable

QTP – Data Driven testing – Data Table Every test by default runs for all rows enabled in the Global sheet

This mean that number of rows enabled in the Global sheet will be

the number of times the test runs

To run the test for less iterations, settings have to be changed in the

Test Settings

File Setting Run

Every action by default runs for one iteration

This means that even if we have 3 rows of data in the Action (3 rows

enabled) the Action by default will still run only once

If we want to run the Action more than once or for all rows enabled

in the sheet then setting have to be changed in Action Call

Properties.

QTP – Data Driven testing – Data Table A simple login and logout of 3 users each with a different user id

and password and check if the login is successful, How does it work

if the data is in Action sheet and then in Global Sheet

Login Create 3 orders logout

Login Create Oder Logout. Create 3 orders

In any application create 3 accounts. Put the data in an excel,

import the data into QTP and export the result back to excel

QTP – CHECKPOINTS A checkpoint is a verification point that compares the expected

value for specified properties with the current or actual value for

those properties

This enables us to identify whether the application is functiona

QTP – Descriptive Programming A way of creating scripts in QTP without the need for an OR

QTP – Descriptive Programming

QTP – Descriptive Programming The same process is followed in the DP approach too.. But the only

difference is that there is no OR

Because we don’t us OR in the Descriptive Programming approach,

we have to provide all the information needed by the QTP to identify

an object in the test statement.

We will have to follow a particular syntax while creating scripts

using DP approach

Scripts cannot be recorded if DP has to be used

Test in DP approach can be written in 2 ways

1.Using Properties Collection object or Description object

2.Using String Representation

QTP – Descriptive Programming Identify the objects needed for a test step

Create a description object (properties collection object ) for all the

object needed

Then get the properties (mandatory and assistive, if needed and

ordinal identifiers if needed identification of these objects from Tools

object Identification

Use Object spy to get the values for these properties

Then provide all the properties and their values including Object

identifier needed for QTP to identify the objects to the Properties

Collection Object

Use the properties collection object to create the test statement or

test step

Note: Each description object had 3 properties “Name”, “Value” and

“Regular Expression”.