Extending Htmlunit for Test Automatisation of Web Applications Using AJAX
Total Page:16
File Type:pdf, Size:1020Kb
Die approbierte Originalversion dieser Diplom-/Masterarbeit ist an der Hauptbibliothek der Technischen Universität Wien aufgestellt (http://www.ub.tuwien.ac.at). The approved original version of this diploma or master thesis is available at the main library of the Vienna University of Technology (http://www.ub.tuwien.ac.at/englweb/). Extending HtmlUnit for Test Automatisation of Web Applications using AJAX DIPLOMARBEIT zur Erlangung des akademischen Grades Diplom-Ingenieur im Rahmen des Studiums Software Engineering & Internet Computing eingereicht von Andreas Langer Matrikelnummer 0125651 an der Fakultät für Informatik der Technischen Universität Wien Betreuung: Betreuer/Betreuerin: Univ.-Prof. Dipl.-Ing. Dr. techn. Thomas Grechenig Mitwirkung: Dipl.-Ing. Mario Bernhart Wien, 20.04.2009 _______________________ ______________________ (Unterschrift Verfasser/in) (Unterschrift Betreuer/in) Technische Universität Wien A-1040 Wien Karlsplatz 13 Tel. +43/(0)1/58801-0 http://www.tuwien.ac.atH DIPLOMA THESIS Extending HtmlUnit for Test Automatisation of Web Applications using AJAX Submitted for the academic degree of Diplomingenieur (Dipl.-Ing) carried out at the Institute of Computer Aided Automation Research Group for Industrial Software Vienna University of Technology under the guidance of Univ.-Prof. Dipl.-Ing. Dr. techn. Thomas Grechenig and Dipl.-Ing. Mario Bernhart by Andreas Langer Freyenthurmgasse 18/1/6 1140 Wien Vienna, April 20, 2009 Eidesstattliche Erklärung Ich erkläre an Eides statt, dass ich die vorliegende Arbeit selbständig und ohne fremde Hilfe verfasst, andere als die angegebenen Quellen nicht benützt und die den benutz- ten Quellen wörtlich oder inhaltlich entnommenen Stellen als solche kenntlich ge- macht habe. Wien, am ---------------------------------------------- Name Acknowledgements This work has been carried out at the research group for Industrial Software (www.inso.tuwien.ac.at), an informal group hosted by the Institute of Automation at the faculty of Informatics at the Vienna University of Technology. I would like to express my sincere gratitude and appreciation to all those who made this diploma thesis possible. Special thanks are due to my advisors Mario Bernhart and Professor Thomas Grechenig and to the developers of HtmlUnit Daniel Gredler, Stan Silvert and Marc Guillemot. I am deeply indepted to my parents for supporting and motivating me throughout the years of studying and stimulating my interest in technical science. I thank my sisters, friends and colleagues who made the course of my studies a marvellous time to re- member. Abstract Software testing is a part of the software development process. It is a challenging task and testing Web-based applications may be even more difficult, due to the peculiarities of such applications. New technologies in internet applications require adaptations of most test frameworks. A very popular technology which is widely used from many well known internet services is called AJAX. AJAX stands for “Asynchronous JavaScript and XML” and is a combination of many known technologies, which allow asynchro- nous data communication between server and client. In contrast to the standard syn- chronous data communication, which means loading an entire web page after each re- quest, AJAX allows dynamic refreshes of the web page and data exchange of parts of the page. Thus testing of such internet applications is different from testing of “normal” applications because there can be interactions with the server without the need to load a new page. Communication is done in the background and the current page stays the same except of minor changes. This paper gives an overview of the basic principles of automated software tests, espe- cially automated testing of web based applications. Furthermore it shows the influence of AJAX concerning web development and testing of web applications. The main issue of this paper is to extend HtmlUnit for test automation of web applications using AJAX. Based on the used concepts it is possible to extend further test frameworks. HtmlUnit is a test framework for internet applications. It simulates a web browser and provides many functions to check the content of a web page. HtmlUnit doesn’t have a graphical user interface but it is written in the programming language Java. Test cases are written using JUnit tests but like many other test frameworks HtmlUnit has some problems testing AJAX enabled internet applications. keywords: test automation, AJAX, HtmlUnit, web testing Kurzfassung Software Testen ist ein fixer Bestandteil im Software Entwicklungsprozess. Automati- sierte Tests können den Aufwand für das Testen der Software erheblich erleichtern. Speziell im Bereich der Internet Applikationen gibt es eine Reihe weiterer Aspekte die beim Testen beachtet werden müssen. Neue Technologien im Internet verlangen eine Anpassung bei vielen Testumgebungen. Die bekannteste Technologie die zurzeit sehr populär ist und von vielen Internet Diensten verwendet wird heißt AJAX. AJAX steht für „Asynchrounous JavaScript and XML“ und ist eine Kombination vieler bekannter Techniken, die zusammen asynchrone Kommunikation zwischen Client und Server er- laubt. Im Gegensatz zum konventionellen Ansatz, dass immer eine vollständige Seite geladen werden muss, ermöglicht AJAX den Datenaustausch von Teilen einer Webseite oder das dynamische Nachladen von Inhalten. Dadurch verändert sich das Testen von Internet Applikationen erheblich, da eine Interaktion mit dem Server nicht automatisch das Laden einer neuen Seite bedeutet sondern im Hintergrund abläuft und die aktuelle Seite, bis auf parzielle Veränderungen, dieselbe bleibt. Diese Arbeit gibt eine Übersicht über das Automatisierte Testen von Software, im spe- ziellen von Internet basierten Programmen. Des Weiteren werden der Einfluss von AJAX und die damit verbundenen Veränderungen analysiert. Der Kernpunkt dieser Arbeit ist das Erweitern von HtmlUnit, um damit auch Internet Applikationen, die AJAX verwenden, testen zu können. Aufbauend auf diesem Konzept ist es möglich, auch andere, ähnlich gebaute Test Werkzeuge zu erweitern. HtmlUnit ist eine Testumgebung für Internet Applikationen. Es simuliert einen Browser und stellt viele Funktionen zum Überprüfen von Internet Seiten zur Verfügung. HtmlU- nit hat keine Grafische Oberfläche sondern ist komplett in der Programmiersprache Java geschrieben. JUnit Tests bieten umfangreiche Möglichkeiten zum Testen von Applika- tionen, aber HtmlUnit hat, wie viele andere Testumgebungen, Probleme bei Internet Applikationen, die AJAX verwenden. Stichwörter: Testautomatisierung, AJAX, HtmlUnit, Testen von Internet Applikatio- nen I Contents Contents .............................................................................................................. I List of Figures ....................................................................................................IV List of Tables ......................................................................................................V 1 Introduction ................................................................................................. 1 1.1 Problem Description ............................................................................. 1 1.2 Motivation ............................................................................................ 1 1.3 Goals and Objectives ........................................................................... 1 1.4 Organization of this Thesis .................................................................. 1 2 Foundations ................................................................................................ 3 2.1 Software Test Automation .................................................................... 3 2.1.1 Objectives and non-objectives of automated software tests ............. 3 2.1.2 The promise of test automation: ....................................................... 4 2.1.3 Automated Comparison .................................................................... 5 2.1.4 Comparing different types of outcome .............................................. 7 2.1.5 Comparison filters ............................................................................ 9 2.1.6 Sensitive tests versus robust tests ................................................... 9 2.1.7 Scripting techniques ....................................................................... 10 2.1.8 Test maintenance ........................................................................... 15 2.1.9 Metrics ............................................................................................ 17 2.2 State of the Technology ..................................................................... 19 2.2.1 Automated web testing ................................................................... 19 2.2.2 AJAX (Asynchronous JavaScript and XML) ................................... 26 2.3 Selected Open Source Testing Frameworks ..................................... 33 2.3.1 HtmlUnit ......................................................................................... 33 2.3.2 JSFUnit .......................................................................................... 41 3 Requirements for the Framework Extension ............................................. 43 3.1 Criteria for a satisfying controller ....................................................... 43 3.2 Proposals for solution ........................................................................ 43 3.2.1 NicelyResynchronizingAjaxController