Академический Документы
Профессиональный Документы
Культура Документы
Automation Framework
Pankaj Bhatte
Cognizant Technology Solution
Pune, India
To start with, the creators of the automation tools marketed their products as the
make-a-wish-come-true software. Just launch our tool, click on record, navigate through
the application, stop recording and you’ve a script. This glossy image of automation
created a wrong impression about the overall test-automation discipline. Whenever it
comes to resource allocation or time slicing, automation is thought as a matter of couple
of clicks. The unfortunate consequence of this is generation of legacy scripts which are
not interpretable by third person, heavily dependent on the state of application as it was
while recording, thus pretty difficult to maintain. The first generation of scripters spent
quite a lot of their time redoing the same scripts for every new build – they kept on
reinventing the wheel. The scripts were necessarily independent of each other without
any code sharing. As a necessary next step in evolution, came the next generation of
smart-scripters. (Note here that scripter is slightly different than a tester. A scripter is a
tester with good development skills.) These smart-scripters attempted to solve this
problem of unnecessary repetitions by consolidating common functionality - like login -
into a separate script. Although this saved their efforts to some extent, there were plenty
of issues waiting to be addressed. UI widgets still needed special functionality. Things
like checking whether the search returned any results, whether an option is available in
dropdown box, were still repeated. These smart-scripters applied their development
experience here to come up with some generic functions like a function to get number of
rows in a table, check existence of a value in a dropdown box. These functions were a
handy repository and added reusability to the scripts.
Need is always the driving force and as they say - it is the ‘Mother of Invention’.
The script-development methodology proposed in this paper is the outcome of several
needs of the industry. In today’s typical regression testing scenario, requests for
automation scripts come in an ad hoc manner. In the total development life cycle,
significantly less resources and time is given to writing scripts for regression testing.
There is a strong need for some ‘Rapid Script Development’ methodology. I propose this
methodology which will not only help making quick scripts but also ensure good script-
mortality in long run and reduce chances of having to write an all new script by scraping
the old one. The suggested methodology termed as ‘The Automation Framework’ is an
attempt to satisfy the extreme needs of the industry at the same time adding value to the
overall discipline of test-automation.
2. What is The Framework - Conceptual Overview
We use the functions to ensure reusability. The next step is to organize these functions
into separate libraries, which help in keeping the functions more managed and
organized. We try to classify the functions into distinct categories. The way this
classification is done leads us to the concept of tiers. We don’t stop after pulling off a
common piece of code
and putting it into a
function. We actually go
a step further and try to
make it still more
granular. First we break
up the script into what we
call navigational steps.
Steps like login to an
application and perform a
search are examples of
navigational steps. For
each step there is a
function in a library called
Navigation Library. We
then try to break up
every function in the
Navigation library into
smaller steps. For example, login can be broken up into three steps: enter username,
enter password and click log in button. It’s now that we step one level down in
abstraction and reach an object level. In above example we will make two functions:
‘enter text in an edit box’ and ‘click a push button’. As one can see these functions are at
a different level of abstraction and hence are placed in a separate library in a separate
tier. This tier is called GUIObjectUtility. These object functions in turn make use of APIs
provided by the tool, which are very much tool-specific. These APIs thus form the fourth
and the lowermost tier of the Framework. This is how the concept of tiers comes into
play. These four tiers - The script (topmost tier), Navigation (second tier) and GUI object
utility (third tier) and tool-specific APIs (fourth tier) - are the basic building blocks of the
Framework and form the basic skeleton. These represent the primary libraries. Some
other libraries take care of other miscellaneous activities like handling test data, GUI
maps, working with database (if the scripts involve database validations) and working
with terminal emulators etc. All these and other libraries are categorized as the
secondary libraries.
Step 8: Create a Library for managing the Dynamic GUI Maps (Tier 4)
One of the important components of a WinRunner script is - the GUI Map. The functions
in the GUIObjectUtility Library will not work properly unless the required objects are
loaded into the
GUI map. The
approach that
we are going to
follow here is
called ‘Dynamic
GUI maps’. The
word dynamic
signifies that we
do not maintain
any pre-recorded
GUI maps.
Instead what is
done is, before
any operation on
an object, that
object is loaded
into the GUI
Map. After
the operation
is done we
remove its
entry from
GUI map,
keeping the
map clean.
To
accomplish
this create-
use-and-
destroy
method we
introduce the
4th tier called
As one can easily notice, the first script took considerably more time and efforts than
normal. But one should also see this as not just writing a script but also building up a
function repository. Let’s see what happens when we create the second script.
As can be seen, the second script took considerably less time compared to the first
one with hardly any recording. The whole process now becomes simple and matured.
For developing subsequent scripts we only need to repeat these four steps. In most of
the cases almost all the functions are already present in the repository. Reusability is the
basis of the Framework and one realizes it’s benefit better, when more and more scripts
are developed. Soon there comes a threshold point called the ‘object saturation’. This
signifies that all possible GUI Objects are taken care of and there is less than one
percent chance that one might need to do step 3 and 4 (extending Tier 3 and 4). This is
quite expected, as normally there are limited types of objects that need to be tackled.
Say for example in a web-based application there are only a few objects like buttons,
edit boxes, links, radio buttons, combo boxes, checkboxes etc. Sooner or later we are
bound to reach a point when we have coded for all these objects. This might happen
after 10 scripts for some application and 25 scripts for some other. It depends heavily on
type, size and complexity of the application and the choice of Test Cases for scripting.
Such a threshold comes quite late for the Navigation Library because of the fact that
the Navigation deals with business logic of the application, which can be far more
complicated and wide spread. Thus the Navigation keeps on growing as the script
development progresses. So we break up the Navigation into multiple library files based
on different areas of application. This helps us to keep function per file figure down, and
makes it more manageable. For the other Tiers normally one library file suffices.
2. Readability
It provides different layers of abstraction for the reader and allows him to concentrate on
different aspects at different levels. It becomes very easy for him to map script to the
Test Case. Even the lower tier functions give a better organized and hence more
readable view of the script. This helps new members of the team to understand the
scripts faster, making the scripts easier to maintain. For people who are not conversant
with the scripting tool, the Tier 1 gives a less complicated and reader-friendly abstraction
of the script.
3. Smart Exception-handling
All the Test Cases are based on some assumptions and they take into consideration the
possibility of some exceptions. There can be some information/warning popup built into
an application, which shows up only if some combination of events happens. There can
be some non-compliant data in the database, which may cause application rules to be
broken. Similar problems can be caused by test data failures. For all such issues, the
Framework provides a unique place for exception handling. Since there are no
repetitions, one has to handle such exceptions at one place only. Because the same
code is used everywhere, this exception handling is reflected in all the scripts. For
example, let’s say that there is a ‘Wrong password’ popup shown during login, in case
the password is incorrect. Normally, It will be difficult to handle this popup in every script
as all the scripts essentially do login. Whereas in the Framework we have one login
function in the Navigation that’s used by all the scripts. Taking care of this popup in login
function makes all the scripts safe for this popup.
5. Generic Concept
Concept of the Framework is quite generic and is not tied to any particular tool,
technology, platform, architecture or application. It can easily be applied to diverse
environments and various tools. This helps in transitions and also eliminates need to be
a tool-expert to follow the concepts.
Value Propositions
1. Reusability
As illustrated in
detail in previous
chapters the
Framework works
on a principle of
reusability.
As we keep on
developing new
scripts the
Framework keeps
growing stronger
and the newer script
takes lesser time
than previous. The
matrix diagram
illustrates this
concept clearly as how the need for making newer functions goes down on different tiers
as the number of developed scripts increases. This saves cost in long term, as against
the traditional automation project wherein one has to keep investing almost the same
amount of time in scripting for every new script developed.
2. Maintainability
This is one of the biggest factors that come into consideration when the business makes
a decision regarding whether or not they should invest money in developing scripts.
Automation has developed a bad reputation among many non-QA people because of the
high mortality and less flexibility of the scripts. Come new build and half the scripts stop
working, is not good news for anybody spending big money for automation scripting.
There are several reasons for this, like heavy repetitions, unprecedented dependency on
application data, unavailability of scripters who can fix the broken scripts etc. A small
Now that we have seen various benefits of using the Framework, it will be wise to
see the other side of the coin as well. Let us try to understand what are the potential
risks involved in use of the Framework and what can be done to mitigate those.
2. Resource Contention
Second major problem arises from improper resource management and poor automation
planning. Because the scripts share same libraries, there is a possibility that more than
one person is working on the same piece of code at the same time. This is a typical
configuration management issue. Because we have the libraries playing such a vital role
in the automation engine, it is recommended that one uses some configuration
management tool and avoid using ad hoc methods like shared network drives. There
should be timely backups and all the updates should strictly follow check-out-update-
check-in procedure.
Let us spend some attention on different ways we can use to reduce the risks and
make the best use of the Framework.
2. Scripting standards
Every development exercise necessarily has some coding standards. Since we are
making an effort to take scripting into a new era where it is no way inferior to
The most important benefit of implementing the Framework for a web-based application
is what we call as the ‘early saturation of GUIObjectUtility’, because the web pages have
limited type of objects and any object rarely has more than one possible operation. In
Rational Robot, though there is a way of getting the HTML source, it doesn’t provide
direct access to many important properties and text of HTML objects. So I introduced a
fourth tier called ‘irRational’ which actually did the job of pulling the HTML source from
the page, loading it into an XML, and then accessing individual properties of each object
using XML DOM. Many of the otherwise impossible tasks were easily accomplished by
the use of this ‘irRational’ tier. I also implemented a Java parser that was used to
generate Test Cases from the comments in the script (Tier 1).
For a non-web application working with GUI Objects is not that simple. This is where a
thoroughly developed GUIObjectUtility comes handy. It avoids reinvention of wheel by
unifying all the object operations on the third tier and allows us to concentrate on
application logic and business processes on higher tiers. Even if Java plug-in is
available, some objects might give some problems. Tier irRational is a good place to
write user-created functions for such objects. A good example is a Java Tree. I used
XML to organize the tree data and access different branches. I also did comprehensive
configuration management using a web-based tool PVCS.