Improving Random GUI Testing with Image-Based Widget Detection
Total Page:16
File Type:pdf, Size:1020Kb
This is a repository copy of Improving random GUI testing with image-based widget detection. White Rose Research Online URL for this paper: http://eprints.whiterose.ac.uk/145601/ Version: Accepted Version Proceedings Paper: White, T., Fraser, G. and Brown, G. orcid.org/0000-0001-8565-5476 (2019) Improving random GUI testing with image-based widget detection. In: ISSTA 2019 Proceedings of the 28th ACM SIGSOFT International Symposium on Software Testing and Analysis. ISSTA 2019 - 28th ACM SIGSOFT International Symposium on Software Testing and Analysis, 15-19 Jul 2019, Beijing, China. ACM Digital Library , pp. 307-317. ISBN 9781450362245 https://doi.org/10.1145/3293882.3330551 © 2019 ACM. This is an author-produced version of a paper subsequently published by the ACM Digital Library. Uploaded in accordance with the publisher's self-archiving policy. Reuse Items deposited in White Rose Research Online are protected by copyright, with all rights reserved unless indicated otherwise. They may be downloaded and/or printed for private study, or other acts as permitted by national copyright laws. The publisher or other rights holders may allow further reproduction and re-use of the full text version. This is indicated by the licence information on the White Rose Research Online record for the item. Takedown If you consider content in White Rose Research Online to be in breach of UK law, please notify us by emailing [email protected] including the URL of the record and the reason for the withdrawal request. [email protected] https://eprints.whiterose.ac.uk/ Improving Random GUI Testing with Image-Based Widget Detection Thomas D. White Gordon Fraser Guy J. Brown [email protected] [email protected] [email protected] Department of Computer Science, Chair of Software Engineering II, Department of Computer Science, The University of Sheield University of Passau The University of Sheield Sheield, United Kingdom Passau, Germany Sheield, United Kingdom ABSTRACT can be written using many diferent GUI libraries and widget sets, Graphical User Interfaces (GUIs) are one of the most common user each providing a diferent API to access widget information. Al- interfaces, enabling interactions with applications through mouse though this can be circumvented by accessibility APIs, these difer movements and key presses. Tools for automated testing of GUIs between operating systems, and updates to an Operating System exist, however they usually rely on operating system speciic or can remove or replace parts of the API. Furthermore, some appli- framework speciic knowledge in order to interact with the appli- cations may not even be supported by such APIs, such as those cation under test. Because of frequent operating system updates which draw directly to the screen, e.g., web canvasses [1]. These and a large variety of GUI frameworks, such tools are made obso- challenges make it diicult to produce and to maintain testing tools lete by time. For an automated GUI test generation tool, supporting that rely on GUI information. Without knowledge of GUI widgets, many frameworks and operating systems is impractical; new oper- test generation tools have to resort to blindly interacting with ran- ating system updates can remove required information and each dom screen locations. diferent GUI framework uses unique underlying data structures. To relieve GUI testing tools of the dependency on GUI and acces- We propose a technique for improving random GUI testing by au- sibility APIs, in this paper we explore the use of machine learning tomatically identifying GUI widgets in screen shots using machine techniques in order to identify GUI widgets. A machine learning learning techniques. This information provides guidance to GUI model is trained to detect the widget types and positions on the testing tools in environments not currently supported by deriv- screen, and this information is fed to a test generator which can ing GUI widget information from screen shots only. In our exper- then make more informed choices about how to interact with a pro- iments, we found that identifying GUI widgets from screen shots gram under test. However, generating a widget prediction model is and using this information to guide random testing achieved a sig- non-trivial: Diferent GUI libraries and operating systems use dif- niicantly higher branch coverage in 18 of 20 applications, with an ferent visual appearance of widgets. Even worse, GUIs can often be average increase of 42.5% compared to conventional random test- customized with user-deined themse, or assistive techniques such ing. as a high/low contrast graphical mode. In order to overcome this challenge, we randomly generate Java Swing GUIs, which can be KEYWORDS annotated automatically, as training data. The inal machine learn- ing model uses only visual data and can identify widgets in real GUI testing, object detection, black box testing, software engineer- application GUIs without needing additional information from an ing, data generation, convolutional neural networks operating system or API. In detail, the contributions of this paper are as follows: 1 INTRODUCTION • We describe a technique to automatically generate GUIs in A Graphical User Interface (GUI) enables events to be triggered in large quantities, in order to serve as training data for GUI an application through visual entities called widgets (e.g., buttons). widget prediction. Using keyboard and mouse, users interact with the widgets on a • We describe a technique based on deep learning that adapts GUI to ire events in the application. Automated GUI test genera- machine learning object detection algorithms to the prob- tion tools (e.g., AutoBlackTest [10], Sapienz [9], or GUITAR [11]) lem of GUI widget detection. simulate users by interacting with the widgets of a GUI, and they • We propose an improve random GUI testing approach that are increasingly applied by companies to test mobile and desktop relies on no external GUI APIs, and instead selects GUI in- applications. The efectiveness of these GUI test generation tools teractions based on a widget prediction model. depends the information they have available. A naïve GUI test gen- • We empircally investigate the efects of using GUI widget erator simply clicks on random screen positions. However, if a GUI prediction on random GUI testing. test generator knows the locations and types of widgets on the cur- rent application screen, then it can make better informed choices In our experiments, for 18 out of 20 Java open source applica- about where to target interactions with the program under test. tions tested, a random tester guided using predicted widget loca- GUI test generation tools tend to retrieve the information about tions achieved a signiicantly higher branch coverage than a ran- available GUI widgets through the APIs of the GUI library of the dom tester without guidance, with an average coverage increase target application, or the accessibility API of the operating sys- of 42.5%. Although our experiments demonstrate that the use of an tem. However, relying on these APIs has drawbacks: Applications API that provides the true widget details can lead to even higher coverage, such APIs are not always available. In contrast, our wid- With the exception of randomized testing, all the current ap- get prediction library requires nothing but a screenshot of the ap- proaches rely on an automated method of extracting widget infor- plication, and even works across diferent operating systems. mation from a GUI. There exists applications and application sce- narios where widget information cannot be automatically derived, 2 BACKGROUND and image labelling may be able to help with this. Interacting with applications through a GUI involves triggering 3 PREDICTING GUI WIDGETS FOR TEST events in the application with mouse clicks or key presses. Lo et al. [8] deine three types of widgets in a GUI: GENERATION In order to improve random GUI testing, we aim to identify wid- • Static widgets in a GUI are generally labels or tooltips. gets in screen shots using machine learning techniques. A chal- • Action widgets ire internal events in an application when lenge lies in retrieving a suiciently large labelled training dataset interacted with (e.g. buttons). to enable modern object recognition approaches to be applied. We • Data widgets are used to store data (e.g., text ields). produce this data by (1) generating random Java Swing GUIs, and In this paper, we focus on identifying action and data widgets. (2) labelling screenshots of these applications with widget data re- The simplest approach to generating GUI tests is through click- trieved through GUI ripping based on the Java Swing API. The ing on random places in the GUI window [6], hoping to hit wid- trained network can then predict the location and dimensions of gets by chance. This form of testing (“monkey testing”) is efective widgets from screen shots during test generation, and thus inlu- at inding crashes in applications and is cheap to run; no infor- ence where and how the GUI tester interacts with the application. mation is needed (although knowing the position and dimensions of the application on the screen is helpful). Monkey is now also 3.1 Identifying GUI Widgets commonly used to test mobile applications through tools like the Environmental factors such as operating system, user-deined theme, Android Monkeyrunner [5]. or application designer choice efect the appearance of widgets. GUI test generation tools can be made more eicient by provid- Each application can use a unique widget palette. When widget ing them with information about the available widgets and events. information cannot be extracted through use of external tools, e.g., This information can be retrieved using the GUI libraries underly- an accessibility API, then this diversity of widgets presents a prob- ing the widgets used in an application, or through the operating lem for GUI testing tools.