Sunteți pe pagina 1din 6

Building a user interface test automation

framework
Izzat Alsmadi and Kenneth Magel
Department of Computer Science
North Dakota State University
Fargo, ND 58105
{ izzat.alsmadi, kenneth.magel}@ndsu.edu

Abstract

This article suggests a fully test automation tool with the least amount of time
and decisions required from testers. Using an automated tool should not be
offset by testers spending a good amount of time for setup and guidance.
The proposed framework for user interface test automation uses the information
stored in the application assembly to build the tested model. The GUI model is
parsed from the application under test at run time. The GUI model is built as an
XML tree. Test cases are then generated from the XML tree using different
proposed algorithms. Some techniques for test case prioritization, critical path
testing, execution and verification are suggested. The goal is to do all those
activities dynamically as part of a GUI test automation framework.

General Terms since they don’t know how much time it will require
Software testing, user interface testing and test upfront for setup. They also don’t know how much of
automation. test automation tasks can be fully or partially
automated. We all agree that complete coverage in
Keywords test automation is impossible as we also agree that
Software test automation, test case generation, Test complete coverage in testing is impossible too.
execution, GUI testing, GUI modeling, and No matter what software methodology a company
verification. follows, software testing is going to play a major role
in terms of project success or resource allocation.
Automated test refers to testing by a computer (no
1. Introduction human tester). We choose the option of automating
Software testing is an important stage in software the GUI testing when tests are repeated several times
projects. It is one of the most expensive stages that [1]. Software test automation tasks include selecting
usually stops after using the available resources (and and generating the test cases, building the test oracle
not completed). Test automation takes more time in (test cases with expected results), executing, re-
the initial stages. Eventually, this is expected to executing, reporting and validating the results.
reduce the cost of testing through reducing the GUIs manage controls. Controls are reusable objects
required time and resources. GUI is increasingly with which users can interact. The term "control" is
taking a larger portion of the overall program’s size used as a generic term for any graphical object or
as newer programs are more interactive with the user widget that an application may produce. Controls
inputs. and GUI testing is taking a major rule in the have common elements that should be considered
whole project’s validation. before writing a program that interacts with a GUI
GUI test automation is a major challenge for test [2].
automation activities. Most of the current GUI test • Controls are categorized according to Window
automation tools are partially automated and require classes. Each control belongs to a window class
the involvement of users or testers in several stages. (making it possible to search them by class).
Test automation tools are still complex and • Controls have an organizational hierarchy; every
expensive. They don’t fully replace testers. They can GUI has at least one root control, and every control
be usually used to re-execute those repeated tasks. may have child controls. Controls and forms make a
Companies consider taking the decision to buy, or tree. We can generate a valid test case by selecting
not, a GUI test automation tool as a tough decision several controls that are children of each other.

1
• Controls have different ways to be located or to compete with. However, GUI test automation
identified at run time. They can be identified by their didn’t reach a mature level were those tools can be
names, parents, unique location or by the window implemented in all scenarios with no problems. User
handle associated to them at run time. Interfaces evolves rapidly with more rich and new
We present a GUI testing framework that does not components. The automation processes in general use
require the involvement of testers throughout the artificial intelligence algorithms to simulate user
different stages. The tests do not need to be revisited activities. The richness and complexity of this space
during any change in the GUI structure. Since the make it possible for new research ideas to compete
application uses reflection to get the actual model at with long time existed test automation tools in the
run time, those changes are included in the current industry.
test. There are several research papers about GUI testing
Generating test cases can happen from requirements, using the data model, [3] [4] [5] [7] [8] [9] [10]. The
design or the actual GUI implementation. Although it overall goals and approach for this work is very
is expected that those three should be consistent and similar to their goals. The GUI testing framework
related, yet they have different levels of abstraction. described, as a GUI test automation structure, is
Requirements and design are usually of a high level generic and should be applied to any testing or GUI
of abstraction to generate from them the test cases. testing model. Since research projects in general have
On the other hand the task of generating test cases limited resources, each paper discusses a specific
from the GUI implementation model is delayed until area of GUI test automation. Without having all
GUI is implemented, which is usually occurred in the components, it is very hard to use such ideas in the
late implementation. We should not have any industry. There is a need for using universal
problems in delaying GUI testing giving the fact that standards for the output formats in all testing
a tool will automate the generation and execution activities. If each tool is producing several
processes. intermediate outputs (generated test cases, recorded
A tool is built in C# that uses reflection to serialize scripts, log files, etc), it will be impossible to use
the GUI control components. Certain control those tools or ideas in other research projects. Some
properties are selected to be serialized. These papers follow a complex procedure in test case
properties are relevant to the user interface testing. generation and do not consider any state reductions.
The application then uses the XML file that is created Assuming that changing any property in any GUI
to build the GUI tree or the event flow graph. Test object changes the GUI state is an assumption that
cases are then generated using the GUI XML file. generated a very large number of possible states for
Generating the test cases takes into consideration the even small applications. State reduction techniques
tree structure to select the test cases that cover unique are considered here to improve the effectiveness of
branches. the track. We intended to follow the same GUI
In test execution and verification, test cases are testing framework for our future work and expect the
executed on the application and compared with the overall results to be more practical and easier to
original test suite. The advantages of the object apply on actual projects.
oriented approach over the widely used The second category[13][6] is related to semi test
capture/replay back one, is in the fact that the model automation using some capture/reply tools like
is generated at run time which makes it represents the WinRunner, QuickTest pro, Segui silk, QARun,
current state of the GUI model. In record/play back Rational Robot, JFCUnit, Abbot and Pounder to
cases, we have to retest the application in case of any creates unit tests for the AUT. Capture/reply tools
change in the functionalities or the GUI of the have been existed and used for years. This may make
program. Once utilized, this object oriented approach them currently more reliable and practical as they
is expected to be less expensive as it does not require have been tested and improved through several
users to manually test the application or make generations and improvements. There are several
decision for pre- and post-conditions. problems and issues in using record/play back tools
[11]. The need to reapply all test cases when the GUI
2. Related work changes, the complexity in editing the scripts code,
and the lack of error handlings are some examples of
There are several GUI test automation tools available those issues. The reuse of test oracles is not very
in the market. Some of the larger vendors for such useful in the case of using a capture/replay tool [12].
tools includes: IBM Rational, Mercury, and Segue.
We expect future software projects to be more GUI
Trying to build a GUI test automation tool is like
complicated that may make the test automation data
trying to make a new operating system in such that
model more practical. Many researches and
the available resources for the existed ones are hard

2
improvements need to be done for the suggested data <Visible>True</Visible>
model to be more practical and usable. <Enabled>True</Enabled>
<ShortCut>None</ShortCut>
3. Goals and approaches </MenuItem>
Figure1: a screen shot from a generated XML file.
Our approach uses two constraints: The tool should
develop all test automation activities without or with
The above information about the controls and their
the least user involvement. The second constraint is
properties are extracted directly from the assembly.
that those dynamically generated test case should
We added two more properties; control level and
provide a value for test adequacy and should
control unit for each control. Those properties are
represent actual test case scenarios.
used along with the parent property to locate each
Since the test cases will be dynamically generated
control during test generation, selection and
with no need for a user to define pre- or post-
execution.
conditions, algorithms are developed for test case
The user has the ability to select certain controls from
generation.
the tree and gives them more than the typical equally
One important aspect of GUI’s that helps in state
distributed weight. This will have an effect on test
reduction is the fact that the GUI is hierarchical by
case selection algorithms. For example, a control that
nature. For example, in MS Notepad, to reach the
is selected manually by the user will be selected
event “Print”, the event “File” should be executed
whenever it is possible or valid to do so.
first.
Rather than defining the GUI state change as a
The GUI is analyzed and its hierarchical tree of
change in any control or control property [2], which
controls is extracted using reflection. The decision to
produces a large amount of possible test cases, we
use the XML file as a saving location for the GUI
define the GUI state as the state that is represented by
model is in the fact that XML is a universal format
the generated XML file from that GUI. If any of the
and it supports hierarchy. This hierarchy can be
parent-child relations in the GUI is changed, or any
extracted easily from the XML file. We used the
property of those parsed controls is changed, then
information about the parent of each control in the
that is considered a GUI state change.
assembly to build the GUI tree. Figure1 is a screen
Some abstraction is used removing those properties
shot from the XML output file extracted from a
that less relevant or important to the GUI state to
simple Notepad application.
reduce the large number of possible states. The
manually selected properties are: the control name,
<Root>GUI-Forms</Root>
parent name, text, locationX (horizontal location),
<Root>Form1</Root>
locationY (vertical location), text, or caption,
<Parent-Form>Form1</Parent-Form>
forecolor, backcolor, enabled, visible, control unit
<Name>Form1</Name>
and control level.
<Control-Level>0</Control-Level>
In the process of developing test generation
<TextBox>
techniques, several test generation algorithms are
<Parent-Form>Form1</Parent-Form>
developed. All algorithms check for a valid selection
<Name>textBox1</Name>
of a tree edge. For example, using Notepad AUT, if
<Control-Level>1</Control-Level>
the current control is “File”, then a test algorithm
<ControlUnit>0</ControlUnit>
may select randomly a valid next control from the
<LocationX>0</LocationX>
children of the File control ( e.g. Save, SaveAs,
<LocationY>24</LocationY>
Open, Exit, Close, Print). In another algorithm, we
<Forecolor>Color [DarkBlue]</Forecolor>
processed the selected test scenarios to ensure that no
<BackColor>Color [Linen]</BackColor>
test scenario will be selected twice in a test suite.
<Enabled>True</Enabled>
Figure2 is a sample output generated from one of the
<Visible>False</Visible>
test generation algorithms. In the algorithm, each test
</TextBox>
case starts from the root or the main entry “Notepad
<MenuItem>
Main”, and then selects two or more controls
<Name>System.Windows.Forms.MenuItem,
randomly from the tree. The algorithm verifies that
Items.Count: 4, Text: File</Name>
the current test case is not existed in the already
<Control-Level>1</Control-Level>
generated test cases.
<ControlUnit>0</ControlUnit>
<Parent>System.Windows.Forms.MainMenu,
1,NOTEPADMAIN,SAVE,SAVEFILEBUTTON1,,,
Items.Count: 3</Parent>
2,NOTEPADMAIN,EDIT,FIND,TABCONTROL1,T
<Text>File</Text>
ABFIND,

3
3,NOTEPADMAIN,VIEW,STATUS BAR,,, File new Mouse Up 10/3/2007 11:51:23 AM
New txtbody Menu Click 10/3/2007 11:51:23 AM
4,NOTEPADMAIN,FIND,TABCONTROL1,TABR
New txtbody Mouse Down 10/3/2007 11:51:23 AM
EPLACE,REPLACETABTXTREPLACE, New txtbody Mouse Up 10/3/2007 11:51:23 AM
5,NOTEPADMAIN,FIND,TABCONTROL1,TABR TxtBody Mouse Move 10/3/2007 11:51:23 AM
EPLACE,REPLACETABBTNREPLACE, TxtBody Key Down 10/3/2007 11:51:23 AM
TxtBody Key Up 10/3/2007 11:51:23 AM
6,NOTEPADMAIN,FIND,TABCONTROL1,TABR
(Test) is written in the document 10/3/2007 11:51:23 AM
EPLACE,REPLACETABLABEL2, (Test) is written in the document 10/3/2007 11:51:24 AM
7,NOTEPADMAIN,EDIT,CUT,,, SaveFilebutton1 Mouse Move 10/3/2007 11:51:24 AM
8,NOTEPADMAIN,EDIT,FIND,TABCONTROL1,T SaveFilebutton1 Mouse Button Down 10/3/2007 11:51:24 AM
SaveFilebutton1 Mouse Button Up 10/3/2007 11:51:24 AM
ABREPLACE,
File SAVE AS Menu Click 10/3/2007 11:51:24 AM
9,NOTEPADMAIN,OPEN,OPENFILECOMBOBO File SAVE AS Mouse Down 10/3/2007 11:51:24 AM
X4,,, File SAVE AS Mouse Up 10/3/2007 11:51:24 AM
Figure2: A sample from a test case generation file. SaveFilebutton1 Mouse Move 10/3/2007 11:51:24 AM
SaveFilebutton1 Mouse Button Down 10/3/2007 11:51:24 AM
SaveFilebutton1 Mouse Button Up 10/3/2007 11:51:24 AM
To evaluate test generation efficiency in the Figure 4 Log file output of a sample test case.
generated test cases, the total number of arcs visited
in the generated test cases is calculated to the total Since the test execution process is subjected to
number of arcs or edges in the AUT. File-Save, Edit- several environment factors, the verification process
Copy, Format-Font are examples of arcs or edges. An is divided into three levels.
algorithm is developed to count the total number of 1. In the first level the tool checks that every
edges in the AUT by using the parent info for each control in the test suite is successfully executed. This
control. (This is a simple approach of calculating test step is also divided into two parts. The first part is
efficiency. More rigorous efficiency measuring checking that all controls executed are existed in the
techniques are planned in future work). Of those test suite. This is to verify that the execution process
tested applications, about 95% of the application itself does not cause any extra errors. The second part
paths can be tested using 200-300 test cases. that ensures all controls in the test suites are executed
tests the execution and its results. In the
For test verification, a log file is created to track the implementation of this level, some controls from the
events that are executed in the tool during the test scenarios were not executed. This is maybe the
execution process. In a simple example, figure 3 case of some dynamic execution or time
shown below, two test cases are generated that write synchronization issues where some controls are not
a text in Notepad and save it to a file. Those test available the time they are expected.
cases are generated using the tool. 2. In the second level the tool checks that the
number of controls matches between the two suites.
1,NOTEPADMAIN,FILE,NEW,TXTBODY,, 3. In the third level, the tool checks that the events
2,NOTEPADMAIN,FILE,SAVE are in the same sequence in both suites.
AS,SAVEFILEBUTTON1,,, The verification process is automated by comparing
Figure 3: a sample of generated test cases. the test cases’ file with the log file. Time stamp is
important to verify the correct sequence of events.
The first test case opens a new document and writes The controls in the test case suites are written to a
to it. As part of the default input values, we set for sorted list and the execution sequence is also written
each control a default value to be inserted by the tool to another sorted lists. To verify the results of the test
through execution. A textbox writes the word “test” execution, the two lists are compared with each other.
or the number “0” whenever it is successfully called. Upon testing several applications, a small percent of
A menu item is clicked, using its parent, whenever it controls generated in the test cases and not executed.
is successfully called. For example, if Save is called Timing synchronization causes some controls to be
as a control, File-Save as an event is triggered. We unavailable or invisible within their execution time.
should have tables for valid and invalid inputs for Regular users “wait” for a new menu to be opened.
each GUI control. The second test case opens the This time varies depending on the application, the
save file dialogue and clicks the OK or accept button computer and the environment. Time synchronization
(Savefilebutton1), to save the document. Here is the and some other dynamic issues are part of the future
corresponding log file output for the above test cases. research goals.
One approach for the GUI test oracle is to have event
Control Event Date Time templates. For each test scenario listed, expected
File new Menu Click 10/3/2007 11:51:23 AM
File new Mouse Down 10/3/2007 11:51:23 AM results are written in a way that can be automatically

4
verified. This requires some level of abstraction controls in the categories with a proportion to their
where similar events are abstract into one event (like weight or occurrence.
the saving process). This proposal does not mean This algorithm is considered as a hybrid technique
exhaustively testing all probable events. By selecting that uses some of the capture/play-back processes. In
critical events for automation and abstracting similar a capture/ play-back tool, the same user session that
events we will get a valuable state reduction that is captured in the manual testing is executed. In this
makes the number of GUI states more practical in approach the controls’ weights are extracted from the
terms of testing. manual testing to guide test case generation and
Some algorithms are developed to calculate critical execution.
paths automatically. Those algorithms are:
1. Critical path using node weight. In this approach, 4. Conclusion and future work
each control has a metric weight that represents the
Developing a user interface test automation tool faces
count of all its children. For example if the children
several challenges. Some of those challenges are:
of File are: Save, SaveAs, Close, Exit, Open, Page
Serializing the GUI widgets, test results’ verification,
Setup, and Print, then its metric weight will be 7
time synchronization issues, handling dialog boxes,
(another alternative is to sum all the decedents). For
testing data dependent systems, and building error
each generated scenario, the weight of that scenario is
logging and recovery procedures.
calculated as the sum of all the weights of its
Some techniques, in test case generation, execution
individual selected controls.
and verification, are explained in principles in this
2. Critical path level reduction. In this approach, a
article. Test case generation from user sessions is
test scenario is randomly selected. The selected
explored that represent real usage of the application
scenario includes controls from the different levels.
and focuses on the application areas where they can
Starting from the lowest level control, we exclude
be heavily used by users. A logging procedure is
from selection all those controls that share the same
implemented to compare the executed suite with the
parent with the selected control. This reduction
generated one. A formal verification procedure is
shouldn’t exceed half of the tree depth.
presented that compare and verifies the output of the
For example if the depth of the tree is four levels, we
execution process with its input. Another track of
should exclude controls from levels three and four.
verification is suggested. This track requires building
We assume that each test scenario should start from
templates for events. For each event pre conditions,
the main entry point and that three controls is the
post conditions and expected results are included.
least required for a test scenario (like Notepad – file –
More elaborations and verifications are required to
exit). We select five consecutive test scenarios using
prove the effectiveness of the suggested approaches.
the same reduction process described above.
Automation of the first few test cases is expensive;
3. The previously described algorithms for critical
beyond that they become much cheaper to develop
paths’ selection depend on statistics pulled from the
and execute.
implementation model. As an alternative, we can
Test automation can only be successful when we
analyze several user captured sessions (e.g. from
keep in mind that testing in general, and particularly
testers or users in beta testing) to automatically
automated testing, is easily made obsolete by some
weight the GUI controls. User session data is the set
changes in the application and environment.
of user actions performed on the AUT from entering
In GUI, it is difficult to reach a high level of test
the application until leaving it.
adequacy in generating test cases that cover all
The session logs all the controls that are executed in
possible combinations. GUI state reduction is needed
the different scenarios. A simple count or percentage
to make testing all or most possible states feasible.
is given to each control depending on how many
In this approach, there is state reduction from
times it is listed in those scenarios. The test scenarios
selecting specific properties to parse. Those
should include all primary and major use cases for
properties are more relevant and critical than the rest
the tested application. The controls’ weights
for the testing process. Total properties of less than
(calculated from user sessions) can drive the test case
10 are selected. The idea of test automation is not to
generation and execution. Theoretically all controls
automate everything; we automate to save time and
should get the same weight in the generated test suite.
effort.
However, in real scenarios this may not be true.
The other issue that causes state reduction is
We may cluster the controls according to their usage
considering the hierarchy. In flat state diagrams, we
from user sessions into three levels; heavily used,
assume that any state is reached from another state
medium and low. Depending on the availability of
once certain preconditions are achieved. In GUI
the resources to testing, we may choose one or two
terms it means that any control is accessible from any
categories and generate test cases that cover those

5
other one. This is not true in GUI states, as usually evolving software. IEEE Transactions on Software
controls are only accessible through their parent Engineering, 31(10):884-896, 2005.
controls. 5. A. M. Memom, I Banerejee, and A. Nagarajan. GUI
We can also get GUI states reduction by abstracting Ripping: Reverse Engineering Of Graphical User Interfaces
For Testing. In Proceedings of the 10th Working
the processes. For example, the saving process has Conference on Reverse Engineering ( WCRE’03), 1095-
several intermediate processes (file-save-as, file 1350/03. 2003.
name, type… ok), but what is important is the end 6. A. K. Ames and H Jie. Critical Paths for GUI
state where there are certain results if the process is Regression Testing. University of California, Santa Cruz.
successful (e.g. a file with certain content is saved to http://www.cse.ucsc.edu/~sasha/ proj/ gui_testing.pdf.
a certain location) and other results if it is not. 2004.
We don’t automate testing everything. We automate 7. A. M. Memon. Developing Testing Techniques for
testing those frequently repeated tasks. We don’t Event-driven Pervasive Computing Applications.
automate those tests that require user validation or Department of Computer Science. University of Maryland.
8. A. M. Memon. GUI testing: Pitfall and Process.
those tests that require special dynamic or time Software Technologies. August 2002. Pages 87-88.
synchronization consideration (such as connecting to 9. A. M Memon. A Comprehensive Framework For
a database or verifying the overall acceptance of a Testing Graphical User Interfaces. Ph.D. thesis,
GUI). Department of Computer Science, University of Pittsburgh,
July 2001.
5. References 10. A. M. Memon, and M. Soffa. Regression Testing of
GUIs. In Proceedings of ESEC/FSE’03. Sep. 2003.
1. Yury Makedonov. Managers guide to GUI test Saket Godase. An introduction to software automation.
automation. Software test and performance conference. http://www.qthreads.com/articles/testing/an_introduction_t
2005. http://www.softwaretestconsulting.com/ o_software_test_automation.html. 2005.
Presentations_slides/Manager_sGuide_GUI_TestAutomati 12. Brian Marick. When should a test be automated.
on_11wh.pdf. http://www.testing.com/writings/automate.pdf. (Presented
2. George Nistorica. Automated GUI testing. at Quality Week '98.).
http://www.perl.com/pub/a/2005/08/11/win32guitest.html. 13. L. White and H. Almezen. Generating test cases from
2005. GUI responsibilities using complete interaction sequences.
3. Q. Xie. Developing Cost-Effective Model-Based In Proceedings of the International Symposium on
Techniques for GUI Testing. In Proceedings of The Software Reliability Engineering, pages 110-121, Oct
International Conference of Software Engineering 2006 2000.
(ICSE’06). 2006. 14. A. Mitchell and J. Power. An approach to quantifying
4. A. M. Memon and Q. Xie . Studying the fault the run-time behavior of Java GUI applications.
detection effectiveness of GUI test cases for rapidly

S-ar putea să vă placă și