Software Testing Quality Assurance Lab
Software Testing Quality Assurance Lab
Published by
Director
Institute of Distance and Open learning ,
University of Mumbai,Vidyanagari, Mumbai - 400 098.
Module I
1. Testing Basics 1
2. Transaction Flow Testing And Data Flow Testing 26
ModuleII
3. Introduction To Selenium 48
4. Introduction To Selenium 80
ModuleIII
5. Experiment 1 97
ModuleIV
6. Test Ng 122
Module V
7. Automation Framework Basics 135
Module VI
8. Quality Assurance 148
*****
SYLLABUS
*****
MODULE I
1
TESTING BASICS
Unit Structure
1.0 Study of Review
1.1 Flow Graphs and Path Testing
1.1.1 Flowgraphs and Path Testing
1.1.2 Basics of Path Testing
1.1.3 Control Flow Graphs Vs Flowcharts
1.1.4 Notational Evoultion
1.1.5 Linked List Representation
1.1.6 Linked List Representation of Flow Graph
1.2 Unit Testing
1.3 Integration Testing
1.4 System Testing
1. Process Block:
A process block is a sequence of program statements uninterrupted by
either decisions or junctions.
It is a sequence of statements such that if any one of statement of the
block is executed, then all statement thereof are executed.
Formally, a process block is a piece of straight line code of one
statement or hundreds of statements.
A process has one entry and one exit. It can consists of a single
statement or instruction, a sequence of statements or instructions, a
single entry/exit subroutine, a macro or function call, or a sequence of
these.
3
Software Testing & Quality 2. Decisions:
Assurance Lab
A decision is a program point at which the control flow can diverge.
Machine language conditional branch and conditional skip
instructions are examples of decisions.
Most of the decisions are two-way but some are three way branches in
control flow.
3. Case Statements:
A case statement is a multi-way branch or decisions.
Examples of case statement are a jump table in assembly language,
and the PASCAL case statement.
From the point of view of test design, there are no differences
between Decisions and Case Statements
4. Junctions:
A junction is a point in the program where the control flow can
merge.
Examples of junctions are: the target of a jump or skip instruction in
ALP, a label that is a target of GOTO.
The act of drawing a control flow graph is a useful tool that can help
us clarify the control flow and data flow issues.
We don't need to know the specifics of the decisions, just the fact that
there is a branch.
The specific target label names aren't important-just the fact that they
exist. So we can replace them by simple numbers.
5
Software Testing & Quality
Assurance Lab
66
Testing Basics
88
The translation from a flowgraph element to a statement and vice versa is Testing Basics
not always unique. (See Figure 1.8)
9
Software Testing & Quality The length of path measured by the number of links in it and not by the
Assurance Lab number of the instructions or statements executed along that path.
The name of a path is the name of the nodes along the path.
10
10
Testing Basics
The hidden loop around label 100 is not revealed by tests based on
prescription 3 alone because no test forces the execution of statement 100
and the following GOTO statement. Furthermore, label 100 is not flagged
by the compiler as an unreferenced label and the subsequent GOTO does
not refer to an undefined label.
A Static Analysis (that is, an analysis based on examining the source code
or structure) cannot determine whether a piece of code is or is not
reachable. There could be subroutine calls with parameters that are
subroutine labels, or in the above example there could be a GOTO that
targeted label 100 but could never achieve a value that would send the
program to that label.
Only a Dynamic Analysis (that is, an analysis based on the code's
behavior while running - which is to say, to all intents and purposes,
testing) can determine whether code is reachable or not and therefore
distinguish between the ideal structure we think we have and the actual,
buggy structure.
11
Software Testing & Quality 2. Statement Testing (P1):
Assurance Lab
Execute all statements in the program at least once under some test. If
we do enough tests to achieve this, we are said to have achieved 100%
statement coverage.
An alternate equivalent characterization is to say that we have
achieved 100% node coverage. We denote this by C1.
This is the weakest criterion in the family: testing less than this for
new software is unconscionable (unprincipled or can not be accepted)
and should be criminalized.
3. Branch Testing (P2):
Execute enough tests to assure that every branch alternative has been
exercised at least once under some test.
If we do enough tests to achieve this prescription, then we have
achieved 100% branch coverage.
An alternative characterization is to say that we have achieved 100%
link coverage.
For structured software, branch testing and therefore branch coverage
strictly includes statement coverage.
We denote branch coverage by C2.
12
12
Path Selection Example: Testing Basics
13
Software Testing & Quality LOOPS
Assurance Lab
7. After you have traced a a covering path set on the master sheet and
filled in the table for every path, check the following:
1. Does every decision have a YES and a NO in its column? (C2)
2. Has every case of all case statements been marked? (C2)
3. Is every three - way branch (less, equal, greater) covered? (C2)
4. Is every link (process) covered at least once? (C1)
14
14 7. The maximum number of iterations.
8. Attempt one more than the maximum number of iterations. What Testing Basics
prevents the loop-control variable from having this value? What will
happen with this value if it is forced?
CASE 2: Single loop, Non-zero minimum, No excluded values:
9. Try one less than the expected minimum. What happens if the loop
control variable's value is less than the minimum? What prevents the
value from being less than the minimum?
10. The minimum number of iterations.
11. One more than the minimum number of iterations.
12. Once, unless covered by a previous test.
13. Twice, unless covered by a previous test.
14. A typical value.
15. One less than the maximum value.
16. The maximum number of iterations.
17. Attempt one more than the maximum number of iterations.
CASE 3: Single loops with excluded values:
Treat single loops with excluded values as two sets of tests consisting
of loops without excluded values, such as case 1 and 2 above.
Example, the total range of the loop control variable was 1 to 20, but
that values 7, 8, 9, 10 were excluded. The two sets of tests are 1-6 and
11-20.
The test cases to attempt would be 0, 1, 2, 4, 6, 7 for the first range
and 10, 11, 15, 19, 20, 21 for the second range.
Kinds of Loops:
There are only three kinds of loops with respect to path testing:
Nested Loops:
The number of tests to be performed on nested loops will be the
exponent of the tests performed on single loops.
As we cannot always afford to test all combinations of nested loops'
iterations values. Here's a tactic used to discard some of these values:
1. Start at the inner most loop. Set all the outer loops to their minimum
values.
2. Test the minimum, minimum+1, typical, maximum-1 , and maximum
for the innermost loop, while holding the outer loops at their
minimum iteration parameter values. Expand the tests as required for
out of range and excluded values.
15
Software Testing & Quality 3. If you've done the outmost loop, GOTO step 5, else move out one
Assurance Lab loop and set it up as in step 2 with all other loops set to typical values.
4. Continue outward in this manner until all loops have been covered.
5. Do all the cases for all loops in the nest simultaneously.
Concatenated Loops:
Concatenated loops fall between single and nested loops with respect
to test cases. Two loops are concatenated if it's possible to reach one
after exiting the other while still on a path from entrance to exit.
If the loops cannot be on the same path, then they are not
concatenated and can be treated as individual loops.
Horrible Loops:
A horrible loop is a combination of nested loops, the use of code that
jumps into and out of loops, intersecting loops, hidden loops, and
cross connected loops.
Makes iteration value selection for test cases an awesome and ugly
task, which is another reason such structures should be avoided.
16
16 Figure 1.10: Example of Loop types
Loop Testing TIme: Testing Basics
Any kind of loop can lead to long testing time, especially if all the
extreme value cases are to attempted (Max-1, Max, Max+1).
This situation is obviously worse for nested and dependent
concatenated loops.
Consider nested loops in which testing the combination of extreme
values lead to long test times. Several options to deal with:
Prove that the combined extreme cases are hypothetically possible,
they are not possible in the real world
Put in limits or checks that prevent the combined extreme cases. Then
you have to test the software that implements such safety measures.
Path Predicate:
A predicate associated with a path is called a Path Predicate. For example,
"x is greater than zero", "x+y>=90", "w is either negative or equal to 10 is
true" is a sequence of predicates whose truth values will cause the routine
to take a specific path.
Multiway Branches:
The path taken through a multiway branch such as a computed
GOTO's, case statement, or jump tables cannot be directly expressed
in TRUE/FALSE terms.
Although, it is possible to describe such alternatives by using multi
valued logic, an expedient (practical approach) is to express multiway
branches as an equivalent set of if..then..else statements.
For example a three way case statement can be written as: If case=1
DO A1 ELSE (IF Case=2 DO A2 ELSE DO A3 ENDIF)ENDIF.
Inputs:
In testing, the word input is not restricted to direct inputs, such as
variables in a subroutine call, but includes all data objects referenced
by the routine whose values are fixed prior to entering it.
For example, inputs in a calling sequence, objects in a data structure,
values left in registers, or any combination of object types.
17
Software Testing & Quality The input for a particular test is mapped as a one dimensional array
Assurance Lab called as an Input Vector.
Predicate Interpretation:
The simplest predicate depends only on input variables.
For example if x1,x2 are inputs, the predicate might be x1+x2>=7,
given the values of x1 and x2 the direction taken through the decision
is based on the predicate is determined at input time and does not
depend on processing.
Another example, assume a predicate x1+y>=0 that along a path prior
to reaching this predicate we had the assignement statement y=x2+7.
Although our predicate depends on processing, we can substitute the
symbolic expression for y to obtain an equivalent predicate
x1+x2+7>=0.
The act of symbolic substitution of operations along the path in order
to express the predicate solely in terms of the input vector is called
predicate interpretation.
Some times the interpretation may depend on the path; for example,
INPUT X
ON X GOTO A, B, C, ...
A: Z := 7 @ GOTO HEM
B: Z := -7 @ GOTO HEM
C: Z := 0 @ GOTO HEM
.........
HEM: DO SOMETHING
.........
HEN: IF Y + Z > 0 GOTO ELL ELSE GOTO EMM
The predicate interpretation at HEN depends on the path we took through
the first multiway branch. It yields for the three cases respectively, if
Y+7>0, Y-7>0, Y>0.
The path predicates are the specific form of the predicates of the
decisions along the selected path after interpretation.
Example:
A: X5 > 0 E: X6 < 0
B: X1 + 3X2 + 17 >= 0 B: X1 + 3X2 + 17 >= 0
C: X3 = 17
D: X4 - X1 >= 14X2
C: X3 = 17
D: X4 - X1 >= 14X2 19
Software Testing & Quality Boolean algebra notation to denote the boolean expression:
Assurance Lab
ABCD+EBCD=(A+E)BCD
Predicate Coverage:
Testing Blindness:
Testing Blindness is a pathological (harmful) situation in which the
desired path is achieved for the wrong reason.
There are three types of Testing Blindness:
1. Assignment Blindness:
Assignment blindness occurs when the buggy predicate appears to
work correctly because the specific value chosen for an assignment
statement works with both the correct and incorrect predicate.
For Example:
Correct Buggy
X=7 X=7
........ ........
if Y > 0 then ... if X+Y > 0 then ...
If the test case sets Y=1 the desired path is taken in either case, but
there is still a bug.
2. Equality Blindness:
Equality blindness occurs when the path selected by a prior predicate
results in a value that works both for the correct and buggy predicate.
For Example:
20
20
Correct Buggy Testing Basics
if Y = 2 then if Y = 2 then
........ ........
if X+Y > 3 then ... if X > 1 then ...
The first predicate if y=2 forces the rest of the path, so that for any
positive value of x. the path taken at the second predicate will be the same
for the correct and buggy version.
3. Self Blindness:
Self blindness occurs when the buggy predicate is a multiple of the
correct predicate and as a result is indistinguishable along that path.
For Example:
Correct Buggy
X=A X=A
........ ........
if X-1 > 0 then ... if X+A-2 > 0 then ...
Path Sensitizing:
Review: Achievable and Unachievable Paths:
For any path in that set, interpret the predicates along the path as
needed to express them in terms of the input vector. In general
individual predicates are compound or may become compound as a
result of interpretation.
ADFGHIJKL+AEFGHIJKL+BCDFGHIJKL+BCEFGHIJ KL
Each product term denotes a set of inequalities that if solved will yield
an input vector that will drive the routine along the designated path.
21
Software Testing & Quality Solve any one of the inequality sets for the chosen path and you have
Assurance Lab found a set of input values for the path.
If you can’t find a solution to any of the sets of inequalities, the path
is un achievable.
If coverage has not been achieved extend the cases to those that
involve dependent predicates.
Path Instrumentation:
Path Instrumentation:
Co-incidental Correctness:
22
22
Testing Basics
24
24
Testing Basics
*****
25
2
TRANSACTION FLOW TESTING AND
DATA FLOW TESTING
Unit Structure
2.0 Objectives
2.1 Transaction Flows
2.2 Transaction Flow Graphs
2.3 Transaction Flow Testing Techniques
2.4 Basics of Data Flow Testing
2.5 Static Vs Dynamic Anomaly Detection
2.6 Data Flow Model
2.7 Strategies of Data Flow Testing
2.8 Unit Testing
2.9 Integration Testing
2.10 System Testing
This unit gives an indepth overview of two forms of functional or system
testing namely Transaction Flow Testing and Data Flow Testing.
2.0 OBJECTIVES
At the end of this unit, the student will be able to:
Understand the concept of transaction flow testing and data flow
testing.
Visualize the transaction flow and data flow in a software system.
Understand the need and appreciate the usage of the two testing
methods.
Identify the complications in a transaction flow testing method and
anomalies in data flow testing.
Interpret the data flow anomaly state graphs and control flow grpahs
and represent the state of the data objetcs.
Understand the limitations of Static analysis in data flow testing.
Compare and analyze various strategies of data flow testing.
26
2.1 TRANSACTION FLOWS Transaction Flow Testing
and Data Flow Testing
Introduction:
A transaction is a unit of work seen from a system user's point of
view.
A transaction consists of a sequence of operations, some of which are
performed by a system, persons or devices that are outside of the
system.
Transaction begin with Birth-that is they are created as a result of
some external act.
At the conclusion of the transaction's processing, the transaction is no
longer in the system.
Example of a transaction: A transaction for an online information
retrieval system might consist of the following steps or tasks:
Accept input (tentative birth)
Validate input (birth)
Transmit acknowledgement to requester
Do input processing
Search file
Request directions from user
Accept input
Validate input
Process request
Update file
Transmit output
Record transaction in log and clean up (death)
Complications:
In simple cases, the transactions have a unique identity from the time
they're created to the time they're completed.
In many systems the transactions can give birth to others, and
transactions can also merge.
28
28
Births: Transaction Flow Testing
and Data Flow Testing
There are three different possible interpretations of the decision symbol,
or nodes with two or more out links. It can be a Decision, Biosis or a
Mitosis.
1. Decision: Here the transaction will take one alternative or the other
alternative but not both. (See Figure 1.2 (a))
2. Biosis: Here the incoming transaction gives birth to a new transaction,
and both transaction continue on their separate paths, and the parent
retains it identity. (See Figure 2.2 (b))
3. Mitosis: Here the parent transaction is destroyed and two new
transactions are created.(See Figure 2.2 (c))
Path Selection:
Select a set of covering paths (c1+c2) using the analogous criteria you
used for structural path testing.
30
30
Select a covering set of paths based on functionally sensible Transaction Flow Testing
transactions as you would for control flow graphs. and Data Flow Testing
Try to find the most tortuous, longest, strangest path from the entry to
the exit of the transaction flow.
Path Sensitization:
Most of the normal paths are very easy to sensitize-80% - 95%
transaction flow coverage (c1+c2) is usually easy to achieve.
The remaining small percentage is often very difficult.
Sensitization is the act of defining the transaction. If there are
sensitization problems on the easy paths, then bet on either a bug in
transaction flows or a design bug.
Path Instrumentation:
Instrumentation plays a bigger role in transaction flow testing than in
unit path testing.
The information of the path taken for a given transaction must be kept
with that transaction and can be recorded by a central transaction
dispatcher or by the individual processing modules.
In some systems, such traces are provided by the operating systems or
a running log.
31
Software Testing & Quality Von Neumann Machine Architecture:
Assurance Lab
Most computers today are von-neumann machines.
This architecture features interchangeable storage of instructions and
data in the same memory units.
The Von Neumann machine Architecture executes one instruction at
a time in the following, micro instruction sequence:
1. Fetch instruction from memory
2. Interpret instruction
3. Fetch operands
4. Process or Execute
5. Store result
6. Increment program counter
7. GOTO 1
Bug Assumption:
The bug assumption for data-flow testing strategies is that control
flow is generally correct and that something has gone wrong with the
software so that data objects are not available when they should be, or
silly things are being done to data objects.
Also, if there is a control-flow problem, we expect it to have
symptoms that can be detected by data-flow analysis.
Although we'll be doing data-flow testing, we won't be using data
flowgraphs as such. Rather, we'll use an ordinary control flowgraph
annotated to show what happens to the data objects of interest at the
moment.
32
32
Transaction Flow Testing
and Data Flow Testing
1. Defined (d):
An object is defined explicitly when it appears in a data declaration.
Or implicitly when it appears on the left hand side of the assignment.
It is also to be used to mean that a file has been opened.
33
Software Testing & Quality A dynamically allocated object has been allocated.
Assurance Lab
Something is pushed on to the stack.
A record written.
3. Usage (u):
When its contents are no longer known with certitude (with aboslute
certainity / perfectness).
Release of dynamically allocated objects back to the availability pool.
Return of records.
The old top of the stack after it is popped.
An assignment statement can kill and redefine immediately. For
example, if A had been previously defined and we do a new
assignment such as A : = 17, we have killed A's previous value and
redefined A
A variable is used for computation (c) when it appears on the right
hand side of an assignment statement.
A file record is read or written.
It is used in a Predicate (p) when it appears directly in a predicate.
34
34
5. kk: harmless but probably buggy. Did you want to be sure it was Transaction Flow Testing
really killed? and Data Flow Testing
36
36
This graph has three normal and three anomalous states and he considers Transaction Flow Testing
the kk sequence not to be anomalous. The difference between this state and Data Flow Testing
graph and Figure 2.5 is that redemption is possible. A proper action from
any of the three anomalous states returns the variable to a useful working
state.
The point of showing you this alternative anomaly state graph is to
demonstrate that the specifics of an anomaly depends on such things as
language, application, context, or even your frame of mind. In principle,
you must create a new definition of data flow anomaly (e.g., a new state
graph) in each situation. You must at least verify that the anomaly
definition behind the theory or imbedded in a data flow anomaly test tool
is appropriate to your situation.
The control flow graph structure is same for every variable: it is the
weights that change.
39
Software Testing & Quality Let us consider the example:
Assurance Lab
40
40
Transaction Flow Testing
and Data Flow Testing
Terminology:
1. Definition-Clear Path Segment, with respect to variable X, is a
connected sequence of links such that X is (possibly) defined on the
first link and not redefined or killed on any subsequent link of that
path segment. ll paths in Figure 3.9 are definition clear because
variables X and Y are defined only on the first link (1,3) and not
thereafter. In Figure 3.10, we have a more complicated situation. The
following path segments are definition-clear: (1,3,4), (1,3,5),
(5,6,7,4), (7,8,9,6,7), (7,8,9,10), (7,8,10), (7,8,10,11). Subpath
(1,3,4,5) is not definition- clear because the variable is defined on
(1,3) and again on (4,5). For practice, try finding all the definition-
clear subpaths for this routine (i.e., for all variables).
2. Loop-Free Path Segment is a path segment for which every node in
it is visited atmost once. For Example, path (4,5,6,7,8,10) in Figure
3.10 is loop free, but path (10,11,4,5,6,7,8,10,11,12) is not because
nodes 10 and 11 are each visited twice.
41
Software Testing & Quality 3. Simple path segment is a path segment in which at most one node is
Assurance Lab visited twice. For example, in Figure 3.10, (7,4,5,6,7) is a simple path
segment. A simple path segment is either loop-free or if there is a
loop, only one node is involved.
4. A du path from node i to k is a path segment such that if the last link
has a computational use of X, then the path is simple and definition-
clear; if the penultimate (last but one) node is j - that is, the path is
(i,p,q,...,r,s,t,j,k) and link (j,k) has a predicate use - then the path from
i to j is both loop-free and definition-clear.
Strategies:
The structural test strategies discussed below are based on the program's
control flowgraph. They differ in the extent to which predicate uses and/or
computational uses of variables are included in the test set. Various types
of data flow testing strategies in decreasing order of their effectiveness
are:
1. All - du Paths (ADUP): The all-du-paths (ADUP) strategy is the
strongest data-flow testing strategy discussed here. It requires that
every du path from every definition of every variable to every use of
that definition be exercised under some test.
For variable X and Y: In Figure 2.9, because variables X and Y are used
only on link (1,3), any test that starts at the entry satisfies this criterion (for
variables X and Y, but not for all variables as required by the strategy).
For variable Z: The situation for variable Z (Figure 3.10) is more
complicated because the variable is redefined in many places. For the
definition on link (1,3) we must exercise paths that include subpaths
(1,3,4) and (1,3,5). The definition on link (4,5) is covered by any path that
includes (5,6), such as subpath (1,3,4,5,6, ...). The (5,6) definition requires
paths that include subpaths (5,6,7,4) and (5,6,7,8).
For variable V: Variable V (Figure 2.11) is defined only once on link (1,
3). Because V has a predicate use at node 12 and the subsequent path to
the end must be forced for both directions at node 12, the all-du-paths
strategy for this variable requires that we exercise all loop-free entry/exit
paths and at least one path that includes the loop caused by (11,4). Note
that we must test paths that include both subpaths (3,4,5) and (3,5) even
though neither of these has V definitions. They must be included because
they provide alternate du paths to the V use on link (5,6). Although (7,4) is
not used in the test set for variable V, it will be included in the test set that
covers the predicate uses of array variable V() and U.
The all-du-paths strategy is a strong criterion, but it does not take as many
tests as it might seem at first because any one test simultaneously satisfies
the criterion for several definitions and uses of several different variables.
42
42
1. All Uses Startegy (AU): Transaction Flow Testing
and Data Flow Testing
The all uses strategy is that at least one definition clear path from every
definition of every variable to every use of that definition be exercised
under some test. Just as we reduced our ambitions by stepping down from
all paths (P) to branch coverage (C2), say, we can reduce the number of
test cases by asking that the test set should include at least one path
segment from every definition to every use that can be reached by that
definition.
For variable V: In Figure 2.11, ADUP requires that we include subpaths
(3,4,5) and (3,5) in some test because subsequent uses of V, such as on
link (5,6), can be reached by either alternative. In AU either (3,4,5) or
(3,5) can be used to start paths, but we don't have to use both. Similarly,
we can skip the (8,10) link if we've included the (8,9,10) subpath. Note the
hole. We must include (8,9,10) in some test cases because that's the only
way to reach the c use at link (9,10) - but suppose our bug for variable V is
on link (8,10) after all? Find a covering set of paths under AU for Figure
3.11.
For variable Z:
In Figure 3.10, for APU+C we can select paths that all take the upper link
(12,13) and therefore we do not cover the c-use of Z: but that's okay
according to the strategy's definition because every definition is covered.
Links (1,3), (4,5), (5,6), and (7,8) must be included because they contain
definitions for variable Z. Links (3,4), (3,5), (8,9), (8,10), (9,6), and (9,10)
must be included because they contain predicate uses of Z. Find a
covering set of test cases under APU+C for all variables in this example -
it only takes two tests.
For variable V:
In Figure 3.11, APU+C is achieved for V by (1, 3, 5, 6, 7, 8, 10, 11, 4, 5,
6, 7, 8, 10, 11, 12[upper], 13, 2) and (1,3,5,6,7,8,10,11,12[lower], 13,2).
Note that the c-us e at (9, 10) need not be included under the APU+C
criterion.
The above examples imply that APU+C is stronger than branch coverage
but ACU+P may be weaker than, or incomparable to, branch coverage.
The all definitions strategy asks only every definition of every variable be
covered by atleast one use of that variable, be that use a computational use
or apredicate use.
For variable Z:
It is intuitively obvious that ACU should be weaker than ACU+P and that
APU should be weaker than APU+C.
44
44
Transaction Flow Testing
and Data Flow Testing
45
Software Testing & Quality Debugging can be modeled as an iterative procedure in which slices
Assurance Lab are further refined by dicing, where the dicing information is obtained
from ad hoc tests aimed primarily at eliminating possibilities.
Debugging ends when the dice has been reduced to the one faulty
statement.
Dynamic slicing is a refinement of static slicing in which only
statements on achievable paths to the statement in question are
included.
46
46
Unit Testing Techniques: Transaction Flow Testing
and Data Flow Testing
Black Box Testing: Using which the user interface, input and output
are tested.
White Box Testing: used to test each one of those functions
behaviour is tested.
Gray Box Testing: Used to execute tests, risks and assessment
methods.
Integration Strategies:
Big-Bang Integration
Top Down Integration
Bottom Up Integration
Hybrid Integration
*****
47
MODULE II
3
INTRODUCTION TO SELENIUM
Unit Structure
3.0 Objectives
3.1 Introduction
3.2 Challenges with Manual Testing
3.3 Invention of Selenium
3.4 What is Selenium?
3.5 Importance of Selenium tools
3.6 Selenium Tools
3.6.1 Selenium Integrated Development Environment (IDE)
3.6.2 Selenium Remote Control (RC)
3.6.3 Selenium WebDriver
3.6.4 Selenium Grid
3.7 Advantages of Selenium Testing
3.8 Limitations of Selenium Testing
3.9 What is Selenium IDE?
3.10 Advancements with New Selenium IDE
3.11 Working Principle of Selenium IDE
3.12 Selenium latest version
3.13 Installation of Selenium IDE
3.14 Demo Test
3.15 Questions
3.16 References
3.0 OBJECTIVES
In Selenium Develop test cases to detect bugs and errors.
Automation framework design and implementation according to
project layout.
Improvement and automated test practices.
Participate in communicating best practices in projects.
In Project to define test strategies and test manuals for tracking and
fixing software issues.
Describe the characteristics of Automation Testing & its methods.
48
3.1 INTRODUCTION Introduction to Selenium
49
Software Testing & Quality Considering all the drawbacks, a desperate need to automate the testing
Assurance Lab process was in demand. Now, let us understand the advent of Selenium
before looking into what Selenium is.
50
50
4. Selenium is platform-independent, meaning it can deploy on Introduction to Selenium
Windows, Linux, and Macintosh
5. Selenium can be integrated with tools like JUnit and TestNG for test
management.
51
Software Testing & Quality
Assurance Lab
53
Software Testing & Quality The architecture of Selenium WebDriver is simple and easy to
Assurance Lab understand:
2) Playing Back:
The recorded script can now be executed to ensure that the browser is
working accordingly. Now, the user can monitor the stability and success
rate.
3) Saving:
The recorded script is saved with a “.side” extension for future runs and
regressions.
56
56
3.12 SELENIUM LATEST VERSION Introduction to Selenium
57
Software Testing & Quality 2.4 New Selenium 4 IDE (Chrome & Firefox):
Assurance Lab
Selenium IDE is a record and playback tool is now available with more
advanced capabilities and features.
New plug-in: The new version plugin will allow you to run Selenium on
any browser vendor and can declare our own locator strategy.
New CLI runner: The new CLI runner is completely based on node.js
instead of old HTML-based runner and will have capabilities like
WebDriver Playback and Parallel Execution to support for parallel
execution and provide reports like passed and failed tests. The new
Selenium IDE runner is completely based on WebDriver.
Once installed, the Selenium IDE icon appears on the top right corner of
the browser. When clicked, a Welcome message appears.
59
Software Testing & Quality
Assurance Lab
A Simple Demo:
Step 1: Launch your Firefox menu and open the Selenium IDE plugin.
Step 2: Select “Record a test in a new project.” Provide the name for your
test.
Step 3: Provide a link to the Facebook webpage. The IDE starts recording
by navigating to this web page. To continue, click on, OK.
60
60
Introduction to Selenium
Step 4: Once the website opens, type “username1” in the username field
and a dummy password for the password field.
Step 5: Click on “Log In.”
Step 6: Now, we verify the title of our application. To do that, Right
click>>Selenium IDE>>Assert title. As soon as this is done, a test step
would be appended in the IDE editor.
Now you can go back to the IDE editor and click on the Stop icon on the
top right corner. With this, we’ve successfully recorded our test case.
Once the recording is stopped, the editor will look something like this:
61
Software Testing & Quality
Assurance Lab
1) Playing Back:
Now that the recording is done, we can play it back to verify if the script
executes correctly and the browser behaves accordingly. To do this, we
can click on the play icon on the menu bar.
2) Saving:
Once the test script is successfully executed, you can then save it.
62
62
Once clicked, you can browse the location and save it in an appropriate Introduction to Selenium
folder. The project is stored with a “.side” extension — this can be used
for future runs and regressions.
3) Selenium Commands:
4) storeTitle():
Assertions: Verifies the current state of the application along with an
expected state. There are different types of assertions:
1. Assert command makes sure that the test execution is terminated in
case of failure
2. Verify command ensures script execution even if the verification has
failed
3. WaitFor command waits for a specific condition to be met before
executing the next test step
63
Software Testing & Quality
Assurance Lab
This login function is tested multiple times for different usernames and
passwords. To do this, we create a UserID and password.
Click on the commands and add a variable to it rather than hardcoded
values.
Now, create another test case and call it “InvalidCredential.” In this test
case, we assign values to the username and password variables. Once
assigned, we call the original test “LoginTest.”
64
64
Use the store command and pass the values “user1” and “pwd1” for the Introduction to Selenium
variables username and password, respectively. The Run command runs
the target test case (i.e., LoginTest).
5) Debugging in IDE:
The Selenium IDE facilitates the debugging of test scripts. This enables
the user to provide breakpoints where the execution of the test script halts,
thus letting the user inspect the browser’s state.
1. Step execution: From the test script, you can run every step in
succession, controlling the execution of each step. To do this, follow the
steps below.
3. The command executes and pauses before proceeding to the next one.
65
Software Testing & Quality
Assurance Lab
Step execution is useful when the test cases are written are long. You
could start checking for errors at any step. This will reveal where the test
might be failing.
2. Breakpoints: To add breakpoints, click on the digit corresponding to
the command you’d like to apply a breakpoint on. Once run, the debugger
will execute all the steps before the breakpoint stops the execution.
66
66
3. Enter the debugger by using the “Play to this point” option: Introduction to Selenium
Another easy way to debug is by using the option as mentioned above.
Right-click on the command you’d wish to stop at>>Click on “Play to this
point.”
The target value here is missing a letter causing an error. The script fails,
trying to find an incorrect ID.
67
Software Testing & Quality Following are the Eight Basic Components:
Assurance Lab
Everything Selenium does is send the browser commands to do something
or send requests for information. Most of what you’ll do with Selenium is
a combination of these basic commands:
1. Start the session:
For more details on starting a session read our documentation on opening
and closing a browser
WebDriver driver = new ChromeDriver();
2. Take action on browser:
In this example we are navigating to a web page.
driver.get("https://selenium.dev");
3. Request browser information:
There are a bunch of types of information about the browser you can
request, including window handles, browser size / position, cookies, alerts,
etc.
driver.getTitle(); // => "Google"
4. Establish Waiting Strategy:
Synchronizing the code with the current state of the browser is one of the
biggest challenges with Selenium, and doing it well is an advanced topic.
Essentially you want to make sure that the element is on the page before
you attempt to locate it and the element is in an interactable state before
you attempt to interact with it.
An implicit wait is rarely the best solution, but it’s the easiest to
demonstrate here, so we’ll use it as a placeholder.
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
5. Find an element:
The majority of commands in most Selenium sessions are element related,
and you can’t interact with one without first finding an element
WebElement searchBox = driver.findElement(By.name("q"));
WebElement searchButton = driver.findElement(By.name("btnK"));
6. Take action on element:
There are only a handful of actions to take on an element, but you will use
them frequently.
searchBox.sendKeys("Selenium");
searchButton.click();
68
68
7. Request element information: Introduction to Selenium
driver.get("https://google.com");
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
searchBox.sendKeys("Selenium");
searchButton.click();
searchBox = driver.findElement(By.name("q"));
searchBox.getAttribute("value"); // => "Selenium"
69
Software Testing & Quality driver.quit();
Assurance Lab
}
}
WebDriver Code:
Below is the actual WebDriver code for the logic presented by the
scenario above
package newproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//comment the above line and uncomment below line to use Chrome
//import org.openqa.selenium.chrome.ChromeDriver;
public class Sample {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe")
;
WebDriver driver = new FirefoxDriver();
//comment the above 2 lines and uncomment below 2 lines to
use Chrome
//System.setProperty("webdriver.chrome.driver","G:\\chromedriver.
exe");
//WebDriver driver = new ChromeDriver();
We will create our test case step by step to give you a complete
understanding of each component in detail.
Step1: Launch Eclipse IDE and open project "Demo_Test" which we have
created in the previous section (Configure Selenium WebDriver) of this
Tutorial. We will write our first Selenium test script in the "First.class" file
72
72 under the "Demo_Test" test suite.
Introduction to Selenium
73
Software Testing & Quality The downloaded file would be in zipped format. Unpack the contents in a
Assurance Lab convenient directory.
Note: Selenium developers have defined properties for each browser that
needs the location of the respective executable files to be parsed in order
to invoke a browser. For example, the property defined for Chrome
browser - webdriver.chrome.driver, needs the path of its executable file -
D:\ChromeDriver\chromedriver.exe in order to launch chrome browser.
Step4: We would need a unique identification for the web elements like
Google Search text box and Search button in order to automate them
through our test script. These unique identifications are configured along
with some Commands/Syntax to form Locators. Locators help us to locate
and identify a particular web element in context of a web application.
The method for finding a unique identification element involves
inspection of HTML codes.
● Right click on the Google search text box and select Inspect Element.
74
74
Introduction to Selenium
● Given below is the Java syntax for locating elements through "id" in
Selenium WebDriver.
● Here is the complete code for locating Google Search text box in our
test script.
1. driver.findElement(By.id ("lst-ib"))
● Now, right click on the Google Search button and select Inspect
Element.
75
Software Testing & Quality ● It will launch a window containing all the specific codes involved in
Assurance Lab
the development of the Google Search button.
● Given below is the Java syntax for locating elements through "name"
in Selenium WebDriver.
● Here is the complete code for locating Google Search button in our
test script.
1. driver.findElement(By.name ("btnK"))
76
76
// Launch website Introduction to Selenium
driver.navigate().to("http://www.google.com/");
Step6: Right click on the Eclipse code and select Run As > Java
Application.
77
Software Testing & Quality Step7: The output of above test script would be displayed in Google
Assurance Lab Chrome browser.
● Launch Website:
To launch a new website, we use navigate().to() method in WebDriver.
driver.navigate().to("http://www.google.com/");
● Click on an element:
In WebDriver, user interactions are performed through the use of Locators
which we would discuss in later sessions of this tutorial. For now, the
following instance of code is used to locate and parse values in a specific
web element.
driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");
78
78
3.15 QUESTIONS Introduction to Selenium
3.16 REFERENCES
1) Software Testing Foundations, 4th Edition: A Study Guide for the
Certified Tester Exam (Rocky Nook Computing) Fourth
Edition,Andreas Spillner, Tilo Linz and Hans Schaefer.
2) Selenium WebDriver, Pearson, Rajeev Gupta, ISBN 9789332526297.
3) Selenium WebDriver Practical Guide - Automated Testing for Web
4) Applications Kindle Edition ,SatyaAvasarala ,ISBN-13: 978-
1782168850
5) https://www.guru99.com/selenium-tutorial.html
6) https://www.toolsqa.com/selenium-tutorial/
7) https://www.techlistic.com/p/selenium-tutorials.html
*****
79
4
INTRODUCTION TO SELENIUM
Unit Structure
4.1 Advancements with the New IDE
4.2 Selenium WebDriver First Script.
4.3 Questions.
4.4 References
80
This login function is tested multiple times for different usernames and Introduction to Selenium
passwords. To do this, we create a UserID and password.
Click on the commands and add a variable to it rather than hardcoded
values.
Now, create another test case and call it “InvalidCredential.” In this test
case, we assign values to the username and password variables. Once
assigned, we call the original test “LoginTest.”
Use the store command and pass the values “user1” and “pwd1” for the
variables username and password, respectively. The Run command runs
the target test case (i.e., LoginTest).
Now run the current test case.
81
Software Testing & Quality 5) Debugging in IDE:
Assurance Lab
The Selenium IDE facilitates the debugging of test scripts. This enables
the user to provide breakpoints where the execution of the test script halts,
thus letting the user inspect the browser’s state.
Step execution is useful when the test cases are written are long. You
could start checking for errors at any step. This will reveal where the test
might be failing.
82
82
2. Breakpoints: To add breakpoints, click on the digit corresponding to Introduction to Selenium
the command you’d like to apply a breakpoint on. Once run, the
debugger will execute all the steps before the breakpoint stops the
execution.
83
Software Testing & Quality
Assurance Lab
The target value here is missing a letter causing an error. The script fails,
trying to find an incorrect ID.
Synchronizing the code with the current state of the browser is one of the
biggest challenges with Selenium, and doing it well is an advanced topic.
Essentially you want to make sure that the element is on the page before
you attempt to locate it and the element is in an interactable state before
you attempt to interact with it.
An implicit wait is rarely the best solution, but it’s the easiest to
demonstrate here, so we’ll use it as a placeholder.
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
5. Find an element:
The majority of commands in most Selenium sessions are element related,
and you can’t interact with one without first finding an element
WebElement searchBox = driver.findElement(By.name("q"));
WebElement searchButton = driver.findElement(By.name("btnK"));
driver.get("https://google.com");
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
searchBox.sendKeys("Selenium");
searchButton.click();
searchBox = driver.findElement(By.name("q"));
searchBox.getAttribute("value"); // => "Selenium"
driver.quit();
}
}
WebDriver Code:
Below is the actual WebDriver code for the logic presented by the
scenario above
package newproject;
import org.openqa.selenium.WebDriver;
86
86
import org.openqa.selenium.firefox.FirefoxDriver; Introduction to Selenium
//comment the above line and uncomment below line to use Chrome
//import org.openqa.selenium.chrome.ChromeDriver;
public class Sample {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe")
;
WebDriver driver = new FirefoxDriver();
//comment the above 2 lines and uncomment below 2 lines to
use Chrome
//System.setProperty("webdriver.chrome.driver","G:\\chromedriver.
exe");
//WebDriver driver = new ChromeDriver();
Importing Packages
For convenience, we saved the Base URL and the expected title as
variables.
88
88
2) Get the Actual Page Title: Introduction to Selenium
The WebDriver class has the getTitle() method that is always used to
obtain the page title of the currently loaded page.
We will create our test case step by step to give you a complete
understanding of each component in detail.
Step 1:
Launch Eclipse IDE and open project "Demo_Test" which we have
created in the previous section (Configure Selenium WebDriver) of this
Tutorial. We will write our first Selenium test script in the "First.class" file
under the "Demo_Test" test suite.
89
Software Testing & Quality
Assurance Lab
Step 2:
Open URL:
https://sites.google.com/a/chromium.org/chromedriver/downloads in your
browser.
Step 3:
Click on the "ChromeDriver 2.41" link. It will redirect you to the directory
of ChromeDriver executables files. Download as per the operating system
you are currently on.
90
90
Introduction to Selenium
Note: Selenium developers have defined properties for each browser that
needs the location of the respective executable files to be parsed in order
to invoke a browser. For example, the property defined for Chrome
browser - webdriver.chrome.driver, needs the path of its executable file -
D:\ChromeDriver\chromedriver.exe in order to launch chrome browser.
Step 4:
We would need a unique identification for the web elements like Google
Search text box and Search button in order to automate them through our
test script. These unique identifications are configured along with some
Commands/Syntax to form Locators. Locators help us to locate and
identify a particular web element in context of a web application.
The method for finding a unique identification element involves
inspection of HTML codes.
Right click on the Google search text box and select Inspect Element.
91
Software Testing & Quality It will launch a window containing all the specific codes involved in
Assurance Lab
the development of the test box.
Given below is the Java syntax for locating elements through "id" in
Selenium WebDriver.
Here is the complete code for locating Google Search text box in our
test script.
1. driver.findElement(By.id ("lst-ib"))
Now, right click on the Google Search button and select Inspect
Element.
92
92
It will launch a window containing all the specific codes involved in Introduction to Selenium
the development of the Google Search button.
Given below is the Java syntax for locating elements through "name"
in Selenium WebDriver.
Here is the complete code for locating Google Search button in our
test script.
1. driver.findElement(By.name ("btnK"))
Step 5:
Now it is time to code. We have embedded comments for each block of
code to explain the steps clearly.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
// Launch website
driver.navigate().to("http://www.google.com/");
Step 6:
Right click on the Eclipse code and select Run As > Java Application.
94
94
Introduction to Selenium
Step 7:
The output of above test script would be displayed in Google Chrome
browser.
Launch Website:
To launch a new website, we use navigate().to() method in WebDriver.
driver.navigate().to("http://www.google.com/");
Click on an element:
In WebDriver, user interactions are performed through the use of Locators
which we would discuss in later sessions of this tutorial. For now, the
following instance of code is used to locate and parse values in a specific
web element.
driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");
*****
96
96
MODULE III
5
EXPERIMENT
Unit Structure
5.1 Aim
5.2 Objective
5.3 Pre-Requisite
EXPERIMENT 1
5.1 AIM
Implementing Web Drivers on Multiple Browser i.e chrome
5.2 OBJECTIVE
Web-based applications are totally different from Windows applications.
A web application can be opened in any browser by the end user. For
example, some people prefer to open https://twitter.com in Firefox
browser, while other’s can be using Chrome browser or IE.
In the diagram below you can observe that in IE, the login box of Twitter
is not showing curve at all corners, but we are able to see it in Chrome
browser.
So we need to ensure that the web application will work as expected in all
popular browsers so that more people can access it and use it.
This motive can be fulfilled with Cross Browser Testing of the product.
97
Software Testing & Quality
Assurance Lab
5.3 PRE-REQUISITE (FOR ALL EXPERIMENTS)
Selenium WebDriver installation process is completed in four basic
steps:
1. Download and Install Java 8 or higher version.
2. Download and configure Eclipse or any Java IDE of your choice.
3. Download Selenium WebDriver Java Client
4. Configure Selenium WebDriver
Steps to run your Selenium Test Scripts on Chrome Browser:
Let us consider a test case in which we will try to automate the following
scenarios in Google Chrome browser.
Launch Chrome browser.
Maximize the browser.
Open URL: www.google.com
Scroll down through the web page
Click on "Core Java" link from the Java Technology section.
We will create our third test case in the test suite (Demo_Test).
Step 1:
Right click on the "src" folder and create a new Class File from New >
Class.
Give your Class name as "Third" and click on "Finish" button.
98
98
Experiment
Step 2:
Open
URL: https://sites.google.com/a/chromium.org/chromedriver/downloads
in your browser.
Step 3:
Click on the "ChromeDriver 2.41" link. It will redirect you to the directory
of ChromeDriver executables files. Download as per the operating system
you are working currently on.
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chrom
edriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver=new ChromeDriver()
Step5. Now it is time to code. We have embedded comments for each
block of code to explain the steps clearly.(Third.java)
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chrom
edriver.exe");
// Launch Website
driver.navigate().to("http://www.news.yahoo.com/");
Step 5:
Right click on the Eclipse code and select Run As > Java Application.
Step 6:
The output of above test script would be displayed in Chrome browser.
101
Software Testing & Quality EXPERIMENT 2
Assurance Lab
AIM
Implementing handling multiple frames
OBJECTIVE
We can handle frames in Selenium webdriver. A frame is identified with
<frame> tag in the html document. A frame is used to insert an HTML
document inside another HTML document.
Syntax:
driver.switchTo().frame(1), we shall switch to the frame with index 1.
● switchTo().frame(name): The frame id or name is passed as an
argument to switch to.
Syntax:
driver.switchTo().frame("fname"), we shall switch to the frame with name
fname.
● switchTo.frame(webelement n): The frame web element is passed as
an argument to switch to.
Syntax:
driver.switchTo().frame(n), we shall switch to the frame with webelement
n.
● switchTo().defaultContent(): To switch back to the main page from
the frame.
Syntax:
driver.switchTo().defaultContent()
102
102
Example: Experiment
Code Implementation.
Step 1: Type following code in Eclipse:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class Framehandling{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://the-internet.herokuapp.com/frames";
driver.get(url);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
// identify element
driver.findElement(By.linkText("Nested Frames")).click();
// switch to frame with frame name and identify inside element
driver.switchTo().frame("frame-bottom");
WebElement l = driver.findElement(By.cssSelector("body"));
System.out.println("Bottom frame text: " +l.getText());
// switch to main page
driver.switchTo().defaultContent();
driver.quit();
}
}
Step 2: run the code(Same as Experiment 1) and output will show as
follows:
Output:
103
Software Testing & Quality EXPERIMENT 3
Assurance Lab
AIM
Implementing Selenium WebDriver - Browser Commands
OBJECTIVE
In this experiment we will learn how to implement Browser Commands
using Selenium WebDriver
DESCRIPTION
Let us consider a sample test script in which will cover most of the
Browser Commands provided by WebDriver.
104
104
Experiment
Step 3:
Let's get to the coding ground.
To automate our test scenarios, first you need to know "How to
invoke/launch web browsers in WebDriver?"
To invoke Google Chrome browser, we need to download the
ChromeDriver.exe file and set the system property to the path of your
ChromeDriver.exe file. We have already discussed this in earlier sessions
of this tutorial. You can also refer to "Running test on Chrome Browser"
to learn how to download and set System property for Chrome driver.
if (actualUrl.equals("https://www.google.co.in/")){
System.out.println("Verification Successful - The correct Url is opened.");
106
106
} Experiment
else{
//Closing browser
driver.close();
}
}
To run the test script on Eclipse window, right click on the screen and
click
107
Software Testing & Quality
Assurance Lab
EXPERIMENT 4
AIM
Implementing Selenium WebDriver - find element command ,Locator
(id, css selector, Xpath), Input Box ,Buttons, Submit Buttons
OBJECTIVE
In this experiment we will learn how to implement - find element
command ,Locator (id, css selector, Xpath), Input Box ,Buttons,
Submit Buttons using Selenium WebDriver
DESCRIPTION
We will see how to access these different form elements using Selenium
Web Driver with Java. Selenium encapsulates every form element as an
object of WebElement. It provides API to find the elements and take
action on them like entering text into text boxes, clicking the buttons, etc.
We will see the methods that are available to access each form element.
Complete Code:
Here is the complete working code
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
108
108
Experiment
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
driver.get(baseUrl);
email.sendKeys("[email protected]");
password.sendKeys("abcdefghlkjl");
System.out.println("Text Field Set");
driver.findElement(By.name("passwd")).sendKeys("abcdefghlkjl");
driver.findElement(By.id("SubmitLogin")).submit();
//driver.close();
}
}
To run the above code on Eclipse window, right click on the screen and
click
EXPERIMENT 5
AIM
Demonstrate different types of alerts
OBJECTIVE
In this experiment we will learn how to implement - different types of
alerts using Selenium WebDriver
DESCRIPTION
An Alert in Selenium is a small message box which appears on screen to
give the user some information or notification. It notifies the user with
some specific information or error, asks for permission to perform certain
tasks and it also provides warning messages as well.
110
110
Alert interface provides the below few methods which are widely used in Experiment
Selenium Webdriver.
1) void dismiss() // To click on the ‘Cancel’ button of the alert.
driver.switchTo().alert().dismiss();
2) void accept() // To click on the ‘OK’ button of the alert.
driver.switchTo().alert().accept();
3) String getText() // To capture the alert message.
driver.switchTo().alert().getText();
4) void sendKeys(String stringToSend) // To send some data to alert
box.
driver.switchTo().alert().sendKeys("Text");
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.ex
e");
WebDriver driver = new ChromeDriver();
driver.get("http://demo.guru99.com/test/delete_customer.php");
111
Software Testing & Quality driver.findElement(By.name("cusid")).sendKeys("53920");
Assurance Lab
driver.findElement(By.name("submit")).submit();
// Switching to Alert
Alert alert = driver.switchTo().alert();
// Accepting alert
alert.accept();
}
}
To run the above code on Eclipse window, right click on the screen and
click
Output:
When you execute the above code, it launches the site. Try to delete
Customer ID by handling confirmation alert that displays on the screen,
and thereby deleting customer id from the application.
EXPERIMENT 6
AIM
Demonstrate CheckBox and Radio Button in Selenium WebDriver
OBJECTIVE
In this experiment we will learn how to implement - CheckBox and
112
112 Radio Button using Selenium WebDriver
DESCRIPTION Experiment
Complete Code:
Here is the complete working code
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
driver.get("http://demo.guru99.com/test/radio.html");
radio2.click();
113
Software Testing & Quality System.out.println("Radio Button Option 2 Selected");
Assurance Lab
// Selecting CheckBox
WebElement option1 = driver.findElement(By.id("vfb-6-0"));
} else {
System.out.println("Checkbox is Toggled Off");
WebElement chkFBPersist =
driver.findElement(By.id("persist_box"));
chkFBPersist.click ();
System.out.println("Facebook Persists Checkbox Status is -
"+chkFBPersist.isSelected());
}
//driver.close();
}
}
114
114
To run the above code on Eclipse window, right click on the screen and Experiment
click
EXPERIMENT 7
AIM
Demonstrate synchronization in selenium(Implicit wait)
OBJECTIVE
To synchronize between script execution and application, we need to wait
after performing appropriate actions in this experiment we achieve
synchronization using implicit wait
DESCRIPTION
The main function of implicit Wait is to tell the web driver to wait for
some time before throwing a "No Such Element Exception". Its default
setting is knocked at zero. Once the time is set, the driver automatically
will wait for the amount of time defined by you before throwing the
above-given exception.
To understand how implicit wait works, let's consider an following
code:
package JavaTpoint;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ImplicitWait{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:Selenium-java-
javaTpointchromedriver_win32chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
115
Software Testing & Quality driver.manage().timeouts().pageLoadTimeout(40,
Assurance Lab
TimeUnit.SECONDS); // pageload timeout
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// Implicit Wait for 20 seconds
driver.get("https://login.google.com/");
driver.findElement(By.xpath("//input[@id='login-
username']")).sendKeys("JavaTpoint.com"); //Finding element and
sending values
Thread.sleep(1000);
driver.findElement(By.xpath("//input[@id='login-signin']")).click();
//Clicking on the next button if element is located
}
}
To run the above code on Eclipse window, right click on the screen and
click
EXPERIMENT 8
AIM
Demonstrate: Select Value from DropDown using Selenium
Webdriver
OBJECTIVE
The Select Class in Selenium is a method used to implement the HTML
SELECT tag. The html select tag provides helper methods to select and
deselect the elements. The Select class is an ordinary class so New
keyword is used to create its object and it specifies the web element
location.
DESCRIPTION
Our use-case would follow the steps below:
Launch the browser.
Open "https://demoqa.com/select-menu".
116
116
Select the Old Style Select Menu using the element id. Experiment
Using the methods of Select class as discussed above, the code would
look like below:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
//Maximizing window
driver.manage().window().maximize();
driver.quit();
}
}
On executing the code, you will notice that the dropdown selections are
made as per the select method used, and the console window would print
the options as shown below(Execution results for handling Dropdown in
Selenium To run the above code on Eclipse window, right click on the
screen and click
118
118
Experiment
EXPERIMENT 9
AIM
Demonstrate action classes using Selenium Webdriver(Mouse Events)
OBJECTIVE
ction Class in Selenium is a built-in feature provided by the selenium for
handling keyboard and mouse events. It includes various operations such
as multiple events clicking by control key, drag and drop events and many
more. These operations from the action class are performed using the
advanced user interaction API in Selenium Webdriver
DESCRIPTION
Below is the whole WebDriver code to check the background color of the
<TR> element before and after the mouse-over.
package newproject;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
119
Software Testing & Quality
Assurance Lab
public class PG7 {
driver.get(baseUrl);
WebElement link_Home =
driver.findElement(By.linkText("Home"));
WebElement td_Home = driver
.findElement(By
.xpath("//html/body/div"
+ "/table/tbody/tr/td"
+ "/table/tbody/tr/td"
+ "/table/tbody/tr/td"
+ "/table/tbody/tr"));
*****
121
MODULE IV
6
TESTNG
Unit Structure
6.0 Objectives
6.1 What is testNG? 1
6.2 TestNG Installation and Configuration in Eclipse 2
6.3 Download the TestNG jar file 6
6.4 How to Set Up a TestNG Test Project in Eclipse? 6
6.5 How to write a TestNG Test? 9
6.5.1 Download Selenium Jar Files for TestNG 9
6.5.2 How to Create a TestNG Class in Eclipse 9
6.6 Coding Our First Test Case in TestNG 11
6.7 How to View TestNG Reports? 13
6.8 References 13
6.0 OBJECTIVES
Using TestNG, you can generate a proper report, and you can easily come
to know how many test cases are passed, failed, and skipped. You can
execute the failed test cases separately.
122
TestNG provides you full control over the test cases and the execution TestNG
of the test cases. Due to this reason, TestNG is also known as a testing
framework.
If you want to run a test case A before that as a pre-request you need
to run multiple test cases before you begin a test case A. You can set
and map with the help of TestNG so that pre-request test cases run
first and then only it will trigger a test case A. In such way, you can
control the test cases.
For example:
Suppose, you have five test cases, one method is written for each test
case (Assume that the program is written using the main method
without using testNG). When you run this program first, three
methods are executed successfully, and the fourth method is failed.
Then correct the errors present in the fourth method, now you want to
run only fourth method because first three methods are anyway
executed successfully. This is not possible without using TestNG.
Step 1:
Go to the official website of the TestNG. Click on the link given below:
https://testng.org/doc/
123
Software Testing & Quality
Assurance Lab
Step 2:
Click on the Eclipse appearing on the menu bar. After clicking on the
Eclipse, the screen appears as shown below:
Step 3:
Click on the Installation appearing on the top of the Table of Contents, and
then click on the "install the plug-in". On clicking on the link "install the
plug in", the screen appears as shown below:
124
124
Step 4: TestNG
Open the Eclipse. Click on the Help appearing on the menu bar and then
click on the Install New Software.
Step 5: Copy the URL https://beust.com/eclipse. Once you paste the URL,
then press the Enter. However, in your case, you will see Pending for few
seconds, thereafter you will see that TestNG plug-in has been loaded.
125
Software Testing & Quality Step 6:
Assurance Lab
Click on the TestNG checkbox.
Step 7:
In the below screen, three dependencies of TestNG are shown. Now click
on the Next.
126
126
Step 8: TestNG
127
Software Testing & Quality Give it a name of your choice.
Assurance Lab
128
128
Finally, click Finish to finish adding the TestNg Library in the project. TestNG
By this, we have added the TestNG Library to the project. As the next
step, we need to make sure that we add the Selenium to the project before
moving on to code the first test case.
Extract the zip file and remember the location where you extracted as we
require the location in the further steps.
Firstly, press Ctrl+N, then select “TestNG Class” under the TestNG
category and click Next.
Or
129
Software Testing & Quality
Assurance Lab
After that, the source folder name will automatically populate in the text
field. But if it doesn't, like my system, you can browse your way through
the src folder by clicking on the Browse button.
130
130
TestNG
Note: To know more about the TestNG Annotations, please refer to What
Are TestNG Annotations?
It will display the TestNG.java test file, which is partially created for you.
The test case file will contain a default method, f(), along with
beforeMethod() and afterMethod() that we checked in the previous step.
Finally, we are all set now by creating our first test class in TestNG. We
can now proceed to write the first TestNG test case.
@BeforeMethod
public void beforeMethod() {
System.out.println("Starting Test On Chrome Browser");
}
@AfterMethod
public void afterMethod() {
driver.close();
System.out.println("Finished Test On Chrome Browser");
}
}
132
132
Right-click on the test case script and execute the test. After that, select TestNG
Run As > TestNG Test.
It will run your tests successfully. We will analyze how those annotations
worked in our annotations tutorial. Please note a few points concerning the
above-written test case.
The primary method is not necessary for a TestNG file.
Moreover, the methods in the TestNG file need not be static in their
behavior.
In addition to the above, @Test annotations tell the underlying
methods is a test method.
Moreover, @BeforeMethod denotes that the underlying method
should run before the test method.
Similarly, @AfterMethod indicates that the underlying method should
run after the test method.
133
Software Testing & Quality
Assurance Lab
6.7 HOW TO VIEW TESTNG REPORTS?
TestNG generates the reports as soon as the tests run. TestNG results are
available under two sections:
Console
TestNG Reports
The bottom half of the screen shows both of the options.
Scrolling down in the console tab will bring the results of the tests to you.
But this is not interesting although it delivers the final aim. Additionally,
for a more in-depth view of the tests, we can switch to the TestNG reports
section located just beside the consol.
6.8 REFERENCES
*****
134
134
MODULE IV
7
AUTOMATION FRAMEWORK BASICS
Unit Structure
7.0 Objectives
7.1 Introduction to Framework
7.1.1 What is Test Automation Framework?
7.1.2 Need for Test Automation Framework
7.1.3 Purpose of Test Automation Framework
7.2 Test Automation Framework Types
7.2.1 Linear Automation Framework
7.2.2 Modular-based Testing Framework
7.2.3 Library Architecture Testing Framework
7.2.4 Data driven Framework
7.2.5 Keyword Driven Framework
7.2.6 Hybrid Test Automation Framework
7.3 Installation of TestNg in Eclipse
7.4 References
7.5 Website References
7.0 OBJECTIVES
After going through this unit, you will be able to:
Understand the basic concepts in Software Testing
Understand the essential characteristics, requirements and usage of
Automation Tool like Selenium Web Driver.
Understand TestNg and Automation Framework basics
Understand the basic concepts of quality assurance in software.
135
Software Testing & Quality is discovered, it is reported to the developers so that the errors can be
Assurance Lab corrected. The process is repeated until a defect-free product is obtained.
Manual testing takes a long time. Managing the testing process is also
challenging because it necessitates planning, bug tracking, and reliability
analysis. Automation testing, on the other hand, uses testing tools to
automate routine testing operations, making the development process
faster, cheaper, and more efficient.
While automation testing is still in its early stages, businesses are looking
to standardise their testing setup in order to successfully automate their
legacy, desktop, web, and mobile apps with a single tool. This is where
you‟ll find the test automation framework. It assists them in standardising
all of their test automation assets, regardless of the tools they use.
138
138
Advantages of a linear framework: Automation Framework
Basics
● Because there is no need to write custom code, test automation
expertise is not required.
● Because test scripts can be easily recorded in a short amount of time,
this is one of the quickest ways to generate them.
● Because the scripts are laid out sequentially, the test workflow is
easier to understand for any party involved in testing.
● This is also the quickest way to get started with automated testing,
especially if you‟re using a new tool. Most automated testing tools
today include record-and-playback capabilities, so you won‟t need to
plan ahead of time with this framework.
Disadvantages:
● The scripts created with this framework are not reusable. Because the
data is hardcoded into the test script, the test cases cannot be re-run
with different sets and must be modified if the data changes.
● Maintenance is regarded as inconvenient because any changes to the
application necessitate extensive rework. As the scope of testing
expands, this model is not particularly scalable.
Disadvantages:
● The script still has test data hard coded in it. As a result, any changes
to the data will necessitate changes to the scripts.
140
140
● Technical expertise is required to write and analyse the test scripts‟ Automation Framework
common functions. Basics
Disadvantages:
● To properly use this framework design, you‟ll need a highly
experienced tester who is fluent in multiple programming languages.
They will have to identify and format the external data sources, as
well as write code (create functions) that will seamlessly connect the
tests to those external data sources.
● It takes a significant amount of time to set up a data-driven
framework. 141
Software Testing & Quality 7.2.5 Keyword-Driven Framework:
Assurance Lab
Each function of the application under test is laid out in a table with a
series of instructions in sequential order for each test that needs to be run
in a keyword-driven framework. A keyword-driven framework separates
test data and script logic in the same way that a data-driven framework
does, but this approach goes a step further.
Keywords are also stored in an external data table (hence the name) in this
approach, making them independent of the automated testing tool used to
execute the tests. Keywords are sections of a script that represent the
various actions taken to test an application‟s graphical user interface
(GUI). These can be labelled simply as „click‟ or „login,‟ or more
complexly as „clicklink,‟ or „verifylink.‟
Keywords are stored in the table in a step-by-step fashion, each with an
associated object, or the part of the UI that the action is being performed
on. A shared object repository is required to map the objects to their
associated actions for this approach to work properly.
142
142
Advantages of Keyword-Driven Frameworks: Automation Framework
Basics
● A basic understanding of scripting is required.
Disadvantages:
Every application is unique, and the techniques used to test them should
be as well. As more teams adopt an agile paradigm, it is critical to have a
flexible framework for automated testing. Hybrid architecture is more
easily adaptable to provide the best test results.
143
Software Testing & Quality
Assurance Lab
7.3 INSTALLATION OF TESTNG IN ECLIPSE
Simply open your eclipse and then follow these steps.
1. Click on help and then go to eclipse market place
144
144
3. Select the packages that you want to Install. Automation Framework
Basics
145
Software Testing & Quality
Assurance Lab
7.4 REFERENCES
1. Software Testing Foundations, 4th Edition: A Study Guide for the
Certified Tester Exam (Rocky Nook Computing) Fourth
Edition,Andreas Spillner, Tilo Linz and Hans Schaefer.
146
146
7.5 WEBSITE REFERENCES Automation Framework
Basics
1. https://www.toolsqa.com/selenium-tutorial
2. https://www.guru99.com/selenium-tutorial.html
3. https://www.techlistic.com/p/selenium-tutorials.html
*****
147
MODULE V
8
QUALITY ASSURANCE
Unit Structure
8.1 Practical 1- Testing Terminologies and definition
8.2 Practical 2- Functional Testing using Boundary Value Analysis
8.2.1 Practical 2a
8.2.2 Practical 2b
8.2.3 Practical 2c
8.2.4 Practical 2d
8.3 Practical 3- Functional Testing using Equivalence Partitioning
8.3.1 Practical 3a
8.3.2 Practical 3b
8.4 Practical 4- Functional Testing using Decision Table
8.4.1 Practical 4a
8.4.2 Practical 4b
8.5 Practical 5- Functional Testing using Cause Effect Graph
8.5.1 Practical 5a
8.6 Practical 6- Program graph and DD graph to compute Cyclomatic
Complexity of Program
8.6.1 Practical 6a
8.7 Practical 7- Selection, Minimization and Prioritization of Test cases
for Regression Testing
8.7.1 Practical 7a
8.7.2 Practical 7b
8.7.3 Practical 7c
8.7.4 Practical 7d
8.8 Practical 8- Validation Testing
8.8.1 Practical 8a
8.8.2 Practical 8b
8.9 Practical 9- Adhoc Testing
8.9.1 Practical 9a
Test Cases:
Test Case is a manual approach of software testing. It is a step-by-step
procedure that is used to test an application. You develop test cases to
define the things that you must validate to ensure that the system is
working correctly and is built with a high level of quality.
Test Suite:
A test suite is a collection of test cases that are grouped for test execution
purposes.
Test Script:
Test Script is an automatic approach of software testing. Test Scripts are a
line-by-line description containing the information about the system
transactions that should be performed to validate the application or system
under test. Test script should list out each step that should be taken with
the expected results.
Test Scenarios:
A Test Scenario is a statement describing the functionality of the
application to be tested. It is used for end-to-end testing of a feature and is
generally derived from the use cases. It is a sequence of activities
performed in a system, such as logging in, signing up a customer, ordering
products, and printing an invoice. You can combine test cases to form a
scenario especially at higher test levels.
Testing Strategy:
Test Strategy is a set of guidelines that explain the test design and
determine how testing needs to be done.
Manual testing:
In Manual testing, testers will write test cases and test the software
manually. This form of testing involves a human performing all the test
steps, recording the outcome, and analyzing the results. Manual testing
can be quite challenging because it often involves repeating the same set
of steps many times.
Automation testing:
In Automation testing, the tester will write code and execute it to check
the workflow of the application. Automated testing describes any form of
testing where a computer runs the tests rather than a human. Typically,
this means automated UI testing. The aim is to get the computer to
replicate the test steps that a human tester would perform.
149
Software Testing & Quality Quality:
Assurance Lab
Quality software is reasonably bug or defect free, delivered on time and
within budget, meets requirements and/or expectations, and is
maintainable.
Test Plan:
A Test Plan can be defined as a document that defines the scope,
objective, and approach to test the software application. The Test Plan is a
term and a deliverable. It is a document that lists all the activities in a
quality assurance project, schedules them, defines the scope, roles and
responsibilities, assesses risk, entry and exit criteria, determine test
objective etc.
Test policy:
A document that describes how an organization runs its testing processes
at a high level. It may contain a description of test levels according to the
chosen life cycle model, roles and responsibilities, required/expected
documents, etc.
Functional Testing:
Functional testing is a type of software testing in which the system is
tested against the functional requirements and specifications. Functional
testing ensures that the requirements or specifications are properly
satisfied by the application. This type of testing is particularly concerned
with the result of processing. It focuses on simulation of actual system
usage but does not develop any system structure assumptions.
Defect:
A flaw detected in a component or system that can cause the component or
system to fail to perform its required function. A defect, if encountered
during execution, may cause a failure of the component or system.
150
150
Error: Quality Assurance
Validation Testing:
Validation Testing ensures that the product actually meets the client's
needs. It can also be defined as to demonstrate that the product fulfills its
intended use when deployed on appropriate environment. It provides
answer to the question-― Are we building the right product?‖
This is carried out through activities like unit testing, integration testing,
system testing and user acceptance testing.
Regression Testing:
Regression Testing is defined as a type of software testing to confirm that
a recent program or code change has not adversely affected existing
features. Regression Testing is nothing but a full or partial selection of
already executed test cases which are re-executed to ensure existing
functionalities work fine. Every time a functionality changes in a software
regression testing is carried out to check if the changes made in one part of
the software has not affected the other.
Ad hoc testing:
Testing carried out informally without test cases or other written test
instructions. Also termed as monkey testing.
Bug:
A slang term for fault, defect, or error. Originally used to describe actual
insects causing malfunctions in mechanical devices that predate
computers. The International Software Testing Qualifications Board
(ISTQB) glossary explains that ―a human being can make an error
(mistake), which produces a defect (fault, bug) in the program code, or in
a document. If a defect in code is executed, the system may fail to do what
it should do (or do something it shouldn‘t), causing a failure. Defects in
software, systems or documents may result in failures, but not all defects
do so.‖ See also debugging.
The valid inputs for testing purposes are 21, 22, 64 and 65.
Output: Invalid
Output: Valid
Output: Valid
Output: Valid
Output: Valid
Output: Invalid
153
Software Testing & Quality The boundary value test cases are given below:
Assurance Lab
154
154
8.3 PRACTICAL 3- FUNCTIONAL TESTING USING Quality Assurance
EQUIVALENCE PARTITIONING
A large number of test cases are generated for any program. It is neither
feasible nor desirable to execute all such test cases. We want to select a
few test cases and still wish to achieve a reasonable level of coverage.
Many test cases do not test any new thing and they just execute the same
lines of source code again and again. We may divide input domain into
various categories with some relationship and expect that every test case
from a category exhibits the same behaviour. If categories are well
selected, we may assume that if one representative test case works
correctly, others may also give the same results. This assumption allows
us to select exactly one test case from each category and if there are four
categories, four test cases may be selected. Each category is called an
equivalence class and this type of testing is known as equivalence class
testing.
In case if a particular field accepts numbers only between 6 to 10 the
following is the equivalence partitioning for the same:
155
Software Testing & Quality Partition 3: balance >1000
Assurance Lab
Valid Input- >1000
Test Case
B002 50 3% Interest
Solution:
156
156
The test cases are given below: Quality Assurance
Condition Stubs:
All the conditions are represented in this upper left section of the decision
table. These conditions are used to determine a particular action or set of
actions.
157
Software Testing & Quality Action Stubs:
Assurance Lab
All possible actions are listed in this lower left portion of the decision
table.
Condition Entries:
In the condition entries portion of the decision table, we have a number of
columns, and each column represents a rule. Values entered in this upper
right portion of the table are known as inputs. Four Portions 1. Condition
Stubs 2. Condition Entries 3. Action Stubs 4.
Action Entries:
Each entry in the action entries portion has some associated action or set
of actions in this lower right portion of the table. These values are known
as outputs and are dependent upon the functionality of the program
Business Rules:
1. On entering correct combination of ID & Password, user should be
able to login successfully.
2. User is not allowed to login when any or both of the ID & Password
are incorrect /blank. In such cases, it should show ‗Invalid
Credentials‘ message.
We created the following combinations of Conditions, Actions and the
respective rules in the decision table.
158
158
All test cases are not valid and significant some we need to optimise the Quality Assurance
test cases
Rules 1, 2, 3, 4, and 5 cover the same action Item ―Invalid Credentials‖
with options Blank and Invalid. Hence, we can consider any one of these
test cases TC01 OR TC02 OR TC03 OR TC04 OR TC05
1. Rules 6,7, and 8 cover the same action Item ―Invalid Credentials‖
with options Valid and Invalid. Hence, we can consider any of these
test cases TC06 OR TC07 OR TC08
2. Rule 9 covers the action item ―Login Successfully‖ with all valid
options. Hence, we should consider the test case TC09.
159
Software Testing & Quality
Assurance Lab
160
160
Constraint Symbols in Cause Effect Graph: Quality Assurance
161
Software Testing & Quality Test Cases:
Assurance Lab
Hence, V(G) = 4 Three regions (1, 2 and 3) are inside and 4th is the
outside region of the graph
164
164
(iii) V(G) = + 1 = 3 + 1 = 4 There are three predicate nodes namely node Quality Assurance
a, node c and node d.
(iv) These four independent paths are given as:
Path 1 : ace
Path 2 : ade
Path 3 : adce
Path 4 : acbe
165
Software Testing & Quality
Assurance Lab
Program Graph:
166
166
Quality Assurance
Solution:
(i) V(G) = e – n + 2P = 16 – 14 + 2 = 4
(ii) V (G) = Number of Regions = 4
(iii) V (G) = + 1 = 3 (N2, N3, N8) + 1 = 4
Consider the following two tests (only inputs specified) used for testing
ZC.
A simple examination of the two tests reveals that test t1 is not valid for
ZC‘ as it does not list the required country field. Test t2 is valid as we
have made no change to ZtoA.
Thus we need to either discard t1 and replace it by a new test for the
modified ZtoC, or simply modify t1 appropriately. We prefer to modify
and hence our validated regression test suite for ZC‘ is
Note that testing ZC‘ requires additional tests to test the ZtoT service.
However, we need only the two tests listed above for regression testing.
To keep this example short, we have listed only a few tests for ZC. In
practice one would develop a much
larger suite of tests for ZC which will then be the source of regression tests
for ZC‘.
169
Software Testing & Quality
Assurance Lab
170
170
Now suppose that the Withdraw module has been modified to implement a Quality Assurance
change in withdrawal policy, e.g. ―No more than $300 can be withdrawn
on any single day.‖ We now have the modified SATM‘ to be tested for the
new functionality as well as to check if none of the existing functionality
has broken. What tests should be rerun? Assuming that no other module of
SATM has been modified, one might propose that tests t1 and t2 need not
be rerun. This is a risky proposition unless some formal technique is used
to prove that indeed the changes made to the Withdraw module cannot
affect the behavior of the remaining modules. Let us assume that the
testers are convinced that the changes in SATM will not affect any module
other than Withdraw. Does this mean that we can run only t3 as a
regression test ? The answer is in the negative. Recall our assumption that
testing of SATM begins with an account balance of 0 for the user with
ID=1. Under this assumption, when run as the first test, t3 will likely fail
because the expected output will not match the output generated by
SATM‘ (see Exercise 11.1). The argument above leads us to conclude that
we need to run test t3 after having run t2. Running t2 ensures that SATM‘
is brought to the state in which we expect test t3 to be successful. Note
that the finite state machine shown in Figure 11.3 ignores the values of
internal variables and data bases used by SATM and SATM‘. During
regression as well as many other types of testing, test sequencing is often
necessary to bring the application to a state where the values of internal
variables, and contents of the data bases used, correspond to the intention
at the time of designing the tests. It is advisable that such intentions (or
assumptions) be documented along with each test.
We want to use the existing test suite for regression testing. How should
we select an appropriate number of test cases for a failure? The range is
from ―one test case‖ to ―all test cases‖. A ‗regression test cases‘ selection
technique may help us to do this selection process. The effectiveness of
the selection technique may decide the selection of the most appropriate
test cases from the test suite. Many techniques have been developed for
procedural and object oriented programming languages. Testing
professionals are, however, reluctant to omit any test case from a test suite
that might expose a fault in the modified program. We consider a program
given in Figure below along with its modified version where the
modification is in line 6 (replacing operator ‗*‘ by ‗-‗). A test suite is also
given in Table given below.
171
Software Testing & Quality
Assurance Lab
Test Cases:
In this case, the modified line is line number 6 where ‗a*b‘ is replaced by
‗a-b‘. All four test cases of the test suite execute this modified line 6. We
may decide to execute all four tests for the modified program. If we do so,
test case 2 with inputs a = 1 and b = 1 will experience a ‗divide by zero‘
problem, whereas others will not. However, we may like to reduce the
number of test cases for the modified program. We may select all test
cases which are executing the modified line. Here, line number 6 is
modified. All four test cases are executing the modified line (line number
6) and hence are selected. There is no reduction in terms of the number of
test cases. If we see the execution history, we find that test case 1 and test
case 2 have the same execution history. Similarly, test case 3 and test case
4 have the same execution history. We choose any one test case of the
same execution history to avoid repetition. For execution history 1 (i.e. 1,
2, 3, 4, 5, 6, 7, 8, 10, 11), if we select test case 1, the program will execute
well, but if we select test case 2, the program will experience ‗divide by
zero‘ problem. If several test cases execute a particular modified line, and
all of these test cases reach a particular affected source code segment,
minimization methods require selection of only one such test case, unless
they select the others for coverage elsewhere. Therefore, either test case 1
or test case 2 may have to be selected. If we select test case 1, we miss the
opportunity to detect the fault that test case 2 detects. Minimization
techniques may omit some test cases that might expose fault(s) in the
modified program. Hence, we should be very careful in the process of
minimization of test cases and always try to use safe regression test
selection technique (if at all it is possible). A safe regression test selection
technique should select all test cases that can expose faults in the modified
program
172
172
8.7.4 Practical 7 d: Test Case Prioritization in Regression Testing Quality Assurance
Many times, on account of time constraints it is difficult to test all the test
cases again so we may prioritize the test cases so that you may first
execute the top most priority test cases and then the others to ensure
important test cases are not missed upon.
Test Number of
Scenario ID Reference Test Scenario Description Test Cases
(TS_001) Verify the working of
Application
Register Register Account 27
URL
Functionality functionality
(TS_002)
Application
Login Verify the working of 23
URL
Functionality Login functionality
(TS_003)
Application
Logout Verify the working of 11
URL
Functionality Logout functionality
(TS_004) Verify the working of
Application
Forgot Forgot Password 25
URL
Passsword functionality
(TS_005)
Application
Search Verify the working of 22
URL
Functionality Search functionality
(TS_006) Verify the working of
Application
Product Product Compare 24
URL
Compare functionality
(TS_007) Verify the Product Display
Application
Product Page functionality for the 37
URL
Display Page different types of Products
(TS_008) Application Verify the working of 'Add
09
Add to Cart URL to Cart' functionality
(TS_009) Application Verify the working of
21
Wish List URL 'Wish List' functionality
(TS_017) Verify the working of My
Application
Order Orders > 'Order History' 12
URL
History functionality
(TS_018) Verify the working of My
Application
Order Orders > 'Order 8
URL
Information Information' functionality
(TS_019) Verify the working of My
Application
Product Orders > 'Product Returns' 11
URL
Returns functionality
173
Software Testing & Quality Verify the working of My
Assurance Lab (TS_020) Application
Orders > 'Downloads' 13
Downloads URL
functionality
(TS_021) Verify the working of My
Application
Reward Orders > 'Reward Points' 10
URL
Points functionality
Verify the working of My
(TS_022) Application
Orders > 'Returned 17
Returns Page URL
Requests' functionality
Verify the working of My
(TS_023) Application
Orders > 'Your 11
Transactions URL
Transactions' functionality
Each of the test scenarios have some test cases for example the first one
Registration Functionality has 27 test cases. So we need to prioritize them.
Lets consider the Test scenario Registration Functionality test cases for
minimization:
Will consider three priority P1, P2 and P3 where P1 has High Importance,
P2 is Moderately Important and P3 importance is low.
Act
Test Test ual Com
Case Test Case Pre- Test Expected Res Prio Res ment
ID Scenario Title requisites Test Steps Data Result (ER) ult rity ult s
The first test case is set as Priority P1 as it covers all mandatory field
without which registration cannot happen. The second and third test case
has the priority P2 as it is important but not mandatory the error on
account of that can be tolerable.
The fourth and fifth test case is given priority P3 as its most coverage
already happens in the first two test cases.
176
176
4. Mandatory Data Inputs Some inputs are compulsory for the execution Quality Assurance
of a program. These mandatory fields should be identified and
validity checks be written accordingly. In the login form, both inputs
(login Id and password) are mandatory. Some fields (data inputs) may
not be mandatory like telephone number in a student registration
form. We should provide validity checks to verify that mandatory
fields are entered by the user.
5. Domain Specific Checks Some validity checks should be written on
the basis of the expected functionality. In the URS, no two semesters
should have a common paper. The roll number should be used as a
Creating Test Cases from Requirements and Use Cases 317 login Id.
A student cannot select more than the required number of elective
papers in a semester. These domain specific issues should be written
as validity checks in order to verify their correctness.
177
Software Testing & Quality Test Cases:
Assurance Lab
178
178
Validity Checks for Change Password Form: Quality Assurance
179
Software Testing & Quality Area Code Blank or three-digit number
Assurance Lab
Prefix Three-digit number, not beginning with 0 or 1
Suffix Four-digit number
Password Six-character alphanumeric
Commands "Check status", "Deposit", "Withdrawal"
*****
180
180