Full text
For Jury Evaluation FACULDADE DE ENGENHARIA DA UNIVERSIDADE DO PORTO Test Automation in Web Environment Jorge Miguel Guerra Santos Mestrado Integrado em Engenharia Informática e Computação Supervisor: ProfaAna Paiva Proponent: EngoJoel Campos June 27, 2016
Test Automation in Web Environment Jorge Miguel Guerra Santos Mestrado Integrado em Engenharia Informática e Computação Approved in oral examination by the committee: Chair: External Examiner: Supervisor: June 27, 2016
Abstract In today’s fast moving world, it is a challenge for any company to continuously maintain and improve the quality and efficiency of software systems development. In many software projects, testing is neglected because of time or cost constraints. This leads to a lack of product quality, followed by customer dissatisfaction and ultimately to increased overall quality costs. Additionally, with the increasingly more complex software projects, the number of hours spent on testing increases as well, but without the support of suitable tools, the test efficiency and validity tends to decline. Some software testing tasks, such as extensive low-level interface regression testing, can be laborious and time consuming to do manually. In addition, a manual approach might not always be effective in finding certain classes of defects. Test automation offers a possibility to perform these types of testing effectively. Once automated tests have been developed, they can be run quickly and repeatedly. However, test automation systems usually lack reporting, analysis and meaningful information about project status. The end goal of this research work is to create a prototype that can create and organize test batteries by recording user interaction, reproduce the recorded actions automatically, detect failures during test execution and generate reports, while also setting up the test environment, all in a automatic fashion and develop techniques to create more maintainable test cases. This tool can help bring technical advantage in automated web testing by creating new and more maintainable recorded test cases with minimal user action and allow testers to better evaluate the software project status. i
ii
Acknowledgements First of all, I would like to thank FEUP for serving as a place for personal and interpersonal growth, as a well as for providing all the conditions for me to focus on my personal goals and to meet incredible people. I thank ProfaAna Cristina Ramada Paiva for guiding me throughout this whole research work, making sure that I stayed focused on the main goal and for always managing her time in order to provide me feedback about the work being developed and clarify any doubts that I had. Additionally, I would like to thank Glintt HS and its crew for allowing me to fit right in and provide all the conditions I needed during this research work. I hope the work done throughout my stay will be of value to the company for a long time. More specifically, I thank Joel for always being available for any questions that I had, even in the busiest days, and for letting me have the freedom to experiment with new ideas for the research work, while giving me his feedback. A special shout-out to the Andrés group for being such a tight-knit group of friends. You keep my sanity in check—most of the times—and I thank you for all the moments during our stay at FEUP and I hope that it is just the beginning. A special thanks to Simão for helping me throughout these academic years. I am eternally grateful for the fact that you had the initiative to work with me and for influencing me in a way that I was able to adapt to the new academic life and form a new work ethic that has without a doubt led me this far. Another individual thanks goes to JP. Thanks for being such an upbeat guy and for, in a random day, asking me to study together in FEUP at night. This turned into a tradition that helped me manage my time to be able to do a little bit of everything. I thank my parents for always supporting me through thin and thick but also allowing me the freedom to explore and focus on my interests while always giving me advice. I am thankful for having had the chance to be born to parents as incredible as you and sorry you had to deal with me and my brother. Speaking of which, thank you my brother. You were always at my side throughout my life and I wish it stays that way no matter where our paths go. Thank you, Jorge Miguel Guerra Santos iii
iv
“Only those who have patience to do simple things perfectly ever acquire the skill to do difficult things easily.” James J. Corbett v
LIST OF TABLES xii
Abbreviations UI User Interface GUI Graphical User Interface IDE Integrated Development Environment IT Information Technology CI Continuous Integration C&R Capture & Replay API Application Programming Interface URL Uniform Resource Locator CSS Cascading Style Sheets HTML HyperText Markup Language DOM Document Object Model XML Extensible Markup Language JSON JavaScript Object Notation AJAX Asynchronous JavaScript and XML xiii
Chapter 1 Introduction2 This introductory section provides a brief overview of the problem being address throughout this4 research work by first giving the background at a technical level. It then goes on to present the motivation behind the elaboration of this dissertation and the main goals to achieve with this6 research work. The last section describes the structure of this dissertation by introducing each of its chapters.8 1.1 Context and Background Testing is a vital part of the software development process and as web applications are becoming10 increasingly important in our world it is crucial that they are tested properly and faster. At first, web testing was focused on finding bugs and security issues by going through the source code at a12 low level, testing server and database communication. But as web applications are becoming more and more advanced and dynamic, testing the functionality of the web application UI has become14 more important [LDD14]. The study and software developed throughout this research work will be done with the col-16 laboration of Glintt HS. Glintt HS is the Glintt Group’s company focused in healthcare. Its core business is the development of software solutions to this market segment, where it is at the fore-18 front at a national level. It is present in Brazil, Poland and Angola as well. It has around 300 collaborators and has its headquarters in Porto.20 1.2 Motivation Glintt offers multiple web applications and the tendency is that the number of applications as well22 as the respective features will increase. This naturally implies that the number of hours spent in tests will increase, but without the support of adequate tools, the efficiency and validity of the tests24 will tend to decline. The relevancy of automated tests in this scenario is even greater and with 1
Introduction the creation/use of the correct tools, the investment that may be made in creating them will easily payoff. The use of automated testing of web application is becoming more common. However 2 it is still challenging to test UI functionality automatically. Most web applications are dynamic rather than static, which makes them complex to automatically test since its elements can change, 4 and are often comprised of different components built using different languages and techniques, which can also make automated testing difficult. In addition, test automation system often lack 6 reporting, analysis and meaningful information about project status. 1.3 Goals 8 The purpose of this research work is to study frameworks regarding web automated testing in order to create a prototype that takes into account software testers without experience in Web testing. 10 The prototype’s goal is to use technologies adapted for this purpose, such as automated testing techniques, test reporting, continuous integration, and implement new methods and techniques to 12 allow the following features: 1. Create and organize test batteries through the recording of user actions on the web applica- 14 tion. 2. Increase the robustness of the generated test cases. 16 3. Reproduce automatically the recorded actions. 4. Manage automatically the test environment, detect failures during testing and produce screen- 18 shots and graphical reports of the errors. 1.4 Structure 20 Besides the introduction, this research paper is structured in four more sections. Chapter 2provides an overview of the state of the art of automated Web application testing as well as a automated 22 testing, logging and reporting tools survey. Chapter 3presents a framework comparison of the main components of the prototype and 24 specifies the technologies required for their integration. Additionally, it comprises a theoretical analysis of a set of relevant methods for the developed prototype. 26 Chapter 4describes the prototype’s architecture and implementation by analyzing each component that structures the developed prototype and the methods and techniques implemented. It 28 finishes with a discussion of the results obtained. Finally, chapter 5, concludes the research paper. 30 2
Chapter 2 Automated Web Application Testing2 The purpose of this chapter is to review the literature on automated web application testing. It4 begins by introducing Software Testing as a core activity in the software development process, followed by assessing its techniques that are related to this research work, such as Web Application6 Testing and Test Automation. Their characteristics and associated testing methods are reviewed before proceeding to the analysis of automated software testing metrics. In addition, a tool survey8 is conducted, which gathered automated software testing, logging and reporting tools, followed by the conclusion of the literature review.10 2.1 Software Testing Software testing has been widely used in the industry as a quality assurance technique for the12 components of a software project, including the specification, the design, and source code. As software becomes more important and complex, defects in software can have a significant impact14 to users and vendors. Therefore, the importance of planning, especially planning through testing, is paramount. A company may devote as much as 40% of its time on testing to assure the quality16 of the software produced due to the fact that software testing is such a critical part of the process of developing high-quality software [PRPE13] [LDD14].18 In software testing, a suite of test cases is designed to test the overall functionality of the software, whether it conforms to the specification document or exposes failures in the software20 (e.g., functionality or security failures). However testing is usually the process of finding as many errors as possible and thus improving assurance of the reliability and the quality of the software.22 This is because, in order to demonstrate the nonexistence of errors in software, it would be needed to test all possible permutations for a given set of inputs. However, realistically, it is not possible24 to test all the permutations of a given set of inputs for a given program, even for a trivial one. For any non-trivial software system, such an exhaustive testing approach is essentially technologically26 and economically unfeasible. 3
Automated Web Application Testing The main goals of any testing technique (or test suite) are the demonstration of the presence of errors during a program execution and to discover a new fault or regression fault in a successful 2 test case [LDD14]. 2.2 Web Application Testing 4 Ever since the creation of the World Wide Web, there as been an increased usage of Web applications. A Web application is a system which typically is composed of a database and Web pages, 6 also described as back-end and front-end respectively, with which users interact over a network using a browser. A Web application can be of two types – static, in which the contents of the Web 8 page do not change regardless of user input; and dynamic, in which the contents of the Web page may change depending on user actions [DLP05] [DLF06]. 10 Compared to traditional desktop applications, Web applications are unique, which presents new challenges for their quality assurance and testing [LDD14]. 12 1. Web applications are multilingual. They usually consist of server-side backend and a clientfacing frontend, and these two components are usually implemented in different program- 14 ming languages [DLF06]. Moreover, the frontend is also typically implemented with a myriad markup, presentation and programming languages such as HTML, CSS and JavaScript, 16 which pose additional challenges for fully automated CI practices, as test drivers for different languages need to be integrated into the CI process and managed coherently. 18 2. The operating environment of typical Web applications is much more open than that of a desktop application. Such a wide visibility makes such applications susceptible to vari- 20 ous attacks, such as the distributed denial-of-service (DDOS) attacks. Moreover, the open environment makes it more difficult to predict and simulate realistic workload. Levels of 22 standards compliance and differences in implementation also add to the complexity of delivering coherent user experiences across browsers [DLF06]. 24 3. A desktop application is usually used by a single user at a time, whereas a Web application typically supports multiple users [DLF06]. The effective management of resources (HTTP 26 connections, database connections, files, threads, etc.) is crucial to the security, scalability, usability and functionality of a Web application. The multi-threaded nature of Web applica- 28 tions also makes it more difficult to detect and reproduce resource contention issues. 4. A multitude of Web applications development technologies and frameworks are being pro- 30 posed, actively maintained and fast evolving. such constant evolution requires testing techniques to stay current. 32 The aim of Web application testing consists of executing the application using combination of input and state to reveal failures. A failure is the manifested inability of a system to perform 34 a required function within the specified requirements and it can be attributed to any fault in the 4
Automated Web Application Testing application implementation [DLF06]. In a web application, it is not possible to test faults separately and establish exactly which of them is responsible for each exhibited failure, because the2 application is strictly interwoven to the whole infrastructure (composed of hardware, software and middleware components).4 Since the infrastructure mainly affects the non-functional requirements of a Web application (such as performance, stability, or compatibility), while the application is responsible for the func-6 tional requirements, Web application testing will have to be considered by two different perspectives:8 •Non-functional testing: Comprehends the different types of testing that need to be executed for verifying the conformance of the Web application with the specified non-functional re-10 quirements. The most common testing activities are performance, load, stress, compatibility, usability and accessibility testing.12 •Functional testing: It has the responsibility of uncovering failures of the application that are due to faults in the implementation of the specified functional requirements. Most of the14 methods and approaches used to test functional requirements of traditional software can be used for Web application too. Testing the functionality relies on test models, testing levels,16 test strategies and testing processes. Both are complementary and not mutually exclusive, therefore a Web application must be18 tested from these two perspectives [DLF06]. 2.3 Test Automation20 Test automation of a software consists of using a computer program to execute system or user transactions against an IT system, which is typically achieved by using an automated testing tool.22 Automated testing is typically used in functional regression testing, performance testing, load testing, network testing and security testing. The tools are very useful to speed up the test cycle24 as they can replicate manual testing processes at a much faster rate [TSSC12]. An effective test automation strategy calls for automating tests at three different levels, which are, as show in figure26 2.1, Unit/Component, Acceptance and GUI Tests. Advantages28 Test automation has its benefits, which include the development of tests that can be run faster, that are consistent, and tests can be run over and over again with less overhead. As more automated30 tests are added to the test suite more tests can be run each time thereafter. Manual testing never goes away, but these efforts can now be focused on more rigorous tests [PRPE13].32 •It can Save Time and Money: After each development of the Software product, the test has to be repeated to ensure quality of the software. With automation testing, only the initial34 5
Automated Web Application Testing Figure 2.1: Mike Cohn’s test automation pyramid cost is there after that it runs over and over again at no additional cost, it can be executed as many times as it is needed and they are much faster than manual tests. However, since 2 test automation is an investment, the testing effort may take more time or resources in the current release. 4 •Testing increases confidence in the correction of the software: The steps of the tests repeat each and every time when the source code changes, which maintain the accuracy of 6 a software system throughout the several iterations of its development. •Increase Testing Coverage: Automated software testing process works on thousands of 8 different complex test cases which are not possible with manual testing. This allows more focus on the depth and scope of tests which increases the quality of software. Automa- 10 tion testing also facilitates testers to test the software on multiple computers with different configurations. 12 •Helpful in Testing Complex Web Applications: Automation testing process is helpful for those web applications where millions of users interact together, by creating virtual users to 14 check load capacity of the web application. It can also be used where the application GUI will always be the same and features get changed always due to source code changes. 16 Challenges It is important to point out that test automation actually makes the effort more complex since 18 there’s now another added software development effort. Automated testing does not replace good test planning, writing of test cases or much of the manual testing effort and has its own challenges. 20 6
Automated Web Application Testing •Regression Test Cases Coverage: When software expands after every release, it becomes so wide that it is a challenge to cope up with the regression testing, verify the new changes,2 test the old functionality, tracking of existing defects and logging new ones. •100% Automation: It is a challenging job to automate maximum number of scenarios4 possible, since it is practically impossible to automate each and every test case. •Required Skill Set: Tester has to have some programming knowledge to write the scripts6 and also should show how to use automation tools really well. •Time to write automated tests: When project has tight deadlines, it becomes difficult to8 write automated tests, review them and then execute them. The tester has to be very skilled to perform all this within the given time.10 •Environment set up: To carry out testing of some applications, it is required to set up an environment. They may be some kind of tools which are required or some pre-conditions to12 fulfill, which need to be all set up properly to get the accurate results. Limitations14 As with most forms of automated testing, setting a regression-testing program on autopilot is not a surefire solution, and some conscious oversight and input is generally still needed to ensure16 that tests catch all the bugs they should. When testers have the exact same suite of tests running repeatedly, night after night, the testing process itself can become static. Over time, developers18 may learn how to pass a fixed library of tests, and then their standard array of regression tests can inadvertently end up not testing much of anything at all. If a created regression testing becomes too20 automated, the whole point of doing it can backfire. It can end up guaranteeing a clear softwaredevelopment trajectory for a development team while unwittingly ignoring components of the22 application, letting the end users stumble upon undetected glitches at their own peril. Walking along a single path of least resistance is easier than stopping to sweep the entire application after24 each new step, but it’s worth the effort to take regression testing all the way by frequently scanning a little further afield by complementing automation with some manual tests.26 2.3.1 Automated Web Application Testing Techniques Model based testing28 Model based testing is a software testing technique in which the test cases are derived from a model that describes the functional aspects of the system under test. Its main purpose is to create30 a model of the application. The test cases are derived on the basis of the model constructed and are generated according to either the all-statement or all-path coverage criterion [LDD14]. The32 generated test case suite includes inputs, expected outputs and necessary infrastructure to execute the tests automatically. This technique depends on three key factors; notation used for data model,34 test-generation algorithm and tools that generate supporting infrastructure for the tests. 7
Automated Web Application Testing 14
Chapter 3 Methodology2 As explained in the introduction, it is clear that the testing phase in software systems development4 is increasingly more time consuming but also more important to guarantee product quality. Regarding the creation of tests, as seen in section 2.5, there are tools that can capture and6 playback user actions when interacting with a GUI. These tools allow the fast creation of test cases, but the tests generated with this technique are often brittle, failing in moments due to timing issues.8 The tests often require to capture the same actions to reach different parts of the application, which increase maintenance costs. For example, most web applications require a user to authenticate in10 order to access its services. Through capture & replay tools, each test case would require to repeat the steps required to login in order to reach the component of the application to test the GUI. If12 the application changed in a way that would make one of those test steps fail, it would be required to fix each test case that uses that test step separately.14 In addition, managing the test environment can become a time consuming task, specially when involving recorded test cases, which, as discussed above, can be easily created but often include16 high maintenance costs. To be able to create a prototype that can ease the automated testing process, a study of the tech-18 nologies to aggregate is necessary. A number of requirements were decided upon the prototype, which filtered the technologies that could be used.20 3.1 Requirements 1. Open-source Technologies: The technologies gathered need to be open source because it22 allows to freely experiment with the source code and tinker it in order to change or create new features. Furthermore, the cost of proprietary software could be a issue.24 2. Capture & Replay feature: C&R feature is essential to create a prototype that can record and playback user actions.26 15
Methodology 3. Continuous Integration: CI is required because it allows the prototype to run full end-to- end automation testing in a single automated build process that could be run on-demand or 2 periodically. 4. Test Logging and Reporting: The prototype needs to provide good representation of the 4 tests’ execution output by identifying the step of the test where the failure occurred through the use of a screenshot and its cause. 6 3.2 Technologies Comparison 3.2.1 Automated Web Application Testing Tools 8 There are many web testing application tools available. These tools differ in functionality, features and usability although the core functions are similar, as seen in table 3.1.10 Tool Features Selenium SAHI OS Watir DalekJS Telerik Test Studio Open Source Yes Yes Yes Yes No Capture & Replay Yes Yes Yes No Yes Inbuilt Logs Yes Only proprietary version (SAHI Pro) No No Yes Inbuilt Reports Only with support from other open source software Yes No No Yes Table 3.1: Web Automated Testing Tools Comparison •Telerik Test Studio has a myriad of features, such as a comprehensive yet cost-effective automated testing suite and mobile application support. However, the fact that it is not open 12 source makes it hard to build upon, in order to implement new innovative features. •DalekJS does not have implemented the Capture & Replay feature, which is crucial to this 14 work. Additionally, it is still in development and not recommended to be used for production by its creators. 16 •Watir does not have inbuilt logs, but a log file can be created. The main issue is that there are not a lot of frameworks and tools that complement its lack of features. 18 •SAHI OS does fulfill most of the requirements, as a log file can be created. Despite this, it does not allow users to view the recorded steps in controller, lacks documentation and does 20 not have an active community. 16
Methodology •Selenium’s user action recorder (Selenium IDE) only works in Firefox - but the action playback feature works on the most popular web browsers - and does not have inbuilt reports.2 However, it is extensively documented and the Selenium WebDriver framework forms the basis for many other testing frameworks and tools.4 Although Selenium has its issues, the Selenium WebDriver offers a lot of flexibility. There are a great number of different frameworks and tools that complements its lack of features. It is6 seemingly established when it comes to automated testing of web applications, as shown by the extensive available documentation and active community [CSRM14], which makes it stood out as8 the clear choice. 3.2.2 Continuous Integration Tools10 Regarding Continuous Integration, there are few powerful open source tools available and they vary in their focus despite having similar features, as seen in the following table.12 Tool Features Jenkins Travis CI Buildbot Strider Open Source Yes Yes Yes Yes Integration Integrates with every major tool thanks to plugins Git - Git Platform Cross-platform Hosted, accessed on Github Python Node.js Table 3.2: Continuous Integration Tools Comparison •Jenkins (formerly known as Hudson) is a continuous integration and continuous delivery application. It is relatively easy to install and configure, has a rich plugin ecosystem and is14 extensible enough to allow parts of the tool to be extended or modified to suit every project. •Travis CI is a hosted service used to build and test projects continuously. It is easy to install16 and configure. However, it is not extensible and requires the project to be a Git project hosted in Github.18 •Buildbot is a framework for automating software build, test, and release processes. It is written in Python and based on the Twisted framework. It does not have a GUI, instead it20 works through commands in a terminal or Python scripts. •Strider is an open source Continuous Deployment/Continuous Integration platform that is22 written in Node.js/JavaScript and uses MongoDB as a backing store. It requires programming effort to setup and is customizable through plugins that increase that effort.24 The two main open source CI Tools are Travis CI and Jenkins. On the one hand, both Buildbot and Strider include programming efforts in their setup and have little documentation available.26 17
Methodology Strider in particular, can be customized, but its plugins are used to extend its UI and backing store and do not extend it with other tools. 2 On the other hand, Jenkins and Travis CI have extensive documentation available and active community that helps newcomers and presents issues to the developers. However, Jenkins ended 4 up as the tool chosen to implement the CI features required for this prototype. Even though it is comparatively harder to install and configure than Travis CI, its extensibility is a great boon. It 6 allows for the creation or modification of plugins that grant better user interaction with the test environment’s resources and better readability of the test results and the project status. 8 3.2.3 Additional Technologies Having decided the frameworks for the two main components of the prototype, C&R and CI, the 10 following section will address the technologies chosen to integrate both of the main components. That integration is visually represented in figure 3.1.12 Figure 3.1: Integration between technologies The Selenium’s C&R component, Selenium IDE, uses its own language-independent convention called Selenese. It is used to specify the commands and any other parameters generated from 14 the user’s actions. However, in order for the test case to use the Selenium WebDriver API, it is necessary to export these commands into a object-oriented programming language. The language 16 chosen was C#, along with the unit testing framework NUnit to run the tests. Note that these generated UI tests are integration tests and not unit tests. The tests attempt to verify that elements on 18 the interface behave as expected, instead of following a series of objective logic tests to confirm the business logic. 20 Selenium IDE is a plugin for browsers based on the Mozilla platform. As a result, the development of new functionality for the IDE has to be done through Mozilla plugins. It should be noted 22 that the publishing of developed plugins for the most popular Mozilla browser, Mozilla Firefox, 18
Methodology requires the user to use the Firefox Developer Edition or Firefox Nightly instead of the standard version [Fir].2 In the case of the CI component, the use of a Visual Studio C# NUnit project allows the automation of the test cases’ build process. It searches for errors that occurred during the test4 case’s creation and in its exportation. 3.3 Test Cases6 In GUI Testing, the generation of test cases has to deal with the domain size and with sequences because GUI’s have many operations to test in comparison to Command Line Interface systems.8 A small program can have hundreds of GUI operations and in a large program, the number of operations can easily be an order of magnitude larger. Additionally, some functionality of the GUI10 system may only be fulfilled with a specific sequence of GUI events. As an example, to open a file a user may have to click a "File" button in a toolbar, then select the "Open file..." operation and12 use a dialog box to specify the file. The GUI test cases involve testing UI components and attributes such as:14 •Size, position, width and height of elements. •Error messages that are displayed after an action.16 •Screen in different resolutions. •The presence and availability of fields.18 •Text found on the web page’s title and body. The following sections describe the methods applied to the prototype that address the genera-20 tion of test cases of GUI testing. 3.3.1 Locators22 Due to the fact that web applications are dynamic and are the result of different technologies, it is a challenge to guarantee the robustness and durability of the recorded test cases. A small change24 to the GUI could render a test case invalid. In the standalone Selenium IDE, it is possible to locate elements through their ID,NAME, by26 CSS,XPath or DOM. The two first locators allow Selenium to test a UI element independent of its location on the28 page. So if the page’s structure and organization changes, the test will still pass. However, the use of dynamic ID’s, which change the ID of an element whenever the page generates the element,30 is an issue because the test will not be able to identify the element on different playbacks. The NAME locator does not have this issue, but it is a weaker locator since it is possible to have32 multiple Name attributes with the same value and it is less used than the ID attribute. 19
Methodology One of the main reasons for using the other alternatives is when there is not a suitable ID or NAME attribute for the element to locate. The CSS locator uses CSS selectors for binding 2 style properties to elements in the document, while DOM’s location strategy takes JavaScript that evaluates to an element on the page, which can just be the element’s location. 4 The XPath locator can be absolute or relative. Both support and extend beyond the methods of locating by ID or NAME attributes. However, as absolute XPaths contain the location of all el- 6 ements from the HTML page’s root, they are likely to fail with only the slightest adjustment to the web application. On the other hand, relative XPaths locate the element based on the relationship 8 of the target element and a parent element with an id or name attribute, which are much less likely to change. This opens up new possibilities such as locating the third check-box on the page. 10 Specific locators are required to handle this issues. They must allow the recorder to specify the element in a way that they are correctly identified during all test runs. 12 3.3.2 Recurrent Steps In web applications, it is common to repeat a set of actions to reach a certain point of the applica- 14 tion, such as logging in, see user profile and go to settings. Recording user actions would make several steps repeated across different test cases. In case of 16 a failure on one of those steps, it would be required to fix every one of those test cases separately. To avoid this problem, the development of a specific type of file will allow the tester to record and 18 store sequences of actions that are commonly used to navigate through the GUI. On recording a test case that uses those steps, the user can then referenced them as a command of the test case, as 20 exemplified in the following figure. Figure 3.2: RecurrentSteps case used by multiple test cases 20
Methodology 3.3.3 Implicit waits Waiting is having the automated task execution elapse a certain amount of time before continuing2 with the next step. There are two types of waits in Selenium, Explicit and Implicit waits. An explicit wait is code that is defined by the user himself to wait for a certain condition4 to occur before proceeding further in the code. The worst case of this is through the use of Thread.Sleep(), which sets the condition to an exact period of time to wait. The Selenium Web-6 Driver API, on the other hand, provides methods that wait up to an amount of time. An implicit wait is used to tell WebDriver to poll the DOM of the GUI for a certain amount of8 time when trying to find an element or elements if they are not immediately available. In order to avoid long waiting times or unnatural user actions during test recording, such as10 explicitly specify that a test must hold until an element is present, the generated test case will implicitly wait for page loads and for the presence of elements. For example, while recording a12 test case, if a user clicks on an element that prompts another page, it will record a single click command. Yet, the associated C# test case exported code must first check if the element is present14 in the GUI. After confirming that the element is present, the click is simulated and then it checks if the page is loaded to continue the test.16 This approach is designed to: •Avoid overloading the user by remembering to explicitly add commands to wait for an18 element. •Use the Selenium WebDriver API to implement different implicit timers for different occa-20 sions, such as to wait for input elements or error messages to be visible. 3.4 Test Environment22 The test environment used by the prototype automates its management and supports test execution. It aids the software testing process by providing a stable and usable environment to run the test24 cases. This includes building the test cases, selecting which test cases to run and managing both the test results and screenshots. The decision of which CI tool would be used to integrate in the26 prototype took into account the interaction with the test environment that it provided for the user. As mentioned in section 3.2, the tool chosen was Jenkins which allows the development of custom28 features to its web UI—due to its extensibility through the use of plugins. 3.4.1 Selection of Test Cases30 For the purpose of running tests, it was required to allow the user to select the test cases to run instead of having to always run all the generated tests. To do so requires the development of a32 Jenkins plugin that creates a test selector page integrated in its web UI. 21
Methodology This page will consist of a list that uses a file that stores information regarding the test cases in the test environment, including those that were generated but not executed, and groups them by 2 their test suite. The user will be able to select specific test cases or whole test suites to execute. The test selector page is also used to visualize which tests failed and see their associated 4 screenshot, which is taken moments before the unsuccessful test exits. 3.4.2 Automation 6 Regarding the automation of the test environment’s management, the process will be conducted during the Jenkins build operation. This process is separated in two phases, Build and Post-Build. 8 It is configured in a way that executes a set of developed programs in a series of steps. Figure 3.3: Jenkins Build Process In the build phase, the first step is the automatic compilation of the test cases selected by the 10 user in the Visual Studio C# NUnit project. Following their execution, a file with all the tests’ results will be generated. 12 During the second phase, the generated file with the test results is used to update the file that is integrated with the developed test selector page in the Jenkins interface that updates its list, as 14 mentioned in the previous section. In addition, an e-mail notification is sent to the configured addresses in a list of recipients. This notification is sent only on certain occasions such as when a 16 build fails, becomes unstable or returns to stable. 3.4.3 Test Reports 18 Reporting is an important part of any test execution, as it helps the user understand the result of the test execution, point of failure, and the reasons for failure. Logging, on the other hand, is 20 important to analyze the execution flow or for debugging in case of any failures. The test logging and reporting capabilities of the prototype will consist of Jenkins plugins. 22 This plugins will use the test results file generated during the Jenkins builds to provide some 22
Methodology graphical visualization of the historical test results. Additionally, the Jenkins web UI will be used for viewing test reports, tracking failures, visualizing the test results trend and accessing the test2 logs. 3.5 Conclusions4 The issue of minimize the maintenance costs of automated C&R tests was separated in two main approaches. The first focuses on the creation of test cases by maintaining the advantages of C&R6 generated tests and increasing the tests’ robustness. The prototype does so by implementing specific locator strategies, avoiding timing issues through the use of implicit waits and resorts to a8 new method called RecurrentSteps. The other approach deals with the test environment’s setup, interaction and automated man-10 agement by resorting to continuous integration features. In addition, it works on a way to use a web UI that allows the user to select the test cases to run through the CI tool and provide graphical12 visualization of the tests’ results. Tools to develop both approaches were chosen, as well as complementary technologies to14 integrate the two main components that implement the methods and techniques analyzed in this chapter.16 23
Implementation 4.2 Architecture Before proceeding to a thorough analysis of the prototype’s implementation, it will be necessary 2 to examine its design. The prototype is separated in two main components, Selenium IDE and Jenkins. During this 4 research work, each component had elements developed. Regarding the Selenium IDE, a Mozilla plugin, a file containing the designed commands, a file with extensions to the IDE and the C# 6 NUnit formatters were created. Additionally, whenever a recorded test is exported, the IDE uses the saveTestCaseToProperties program, which is located in the Jenkins workspace. 8 In the case of the Jenkins component, as explained in the subsection 4.1.5, it uses developed programs to manage the test environment. In addition, a modified Test Selector Jenkins plugin is 10 used to facilitate the selection of tests to be run and its integration with the properties file. Figure 4.2: Overview of the developed system What follows is an extensive analysis and description of the components developed for both 12 Selenium IDE and Jenkins. 4.2.1 Selenium IDE 14 Selenium IDE Plugin - Test suite chooser The test suite chooser is a Mozilla plugin that works with the Selenium IDE’s toolbar. It uses an 16 overlay to add an input element to the toolbar. This element stores a XML with a serialized DOM of a tree view of test suites and RecurrentSteps, as observed in figure 4.16. This is thanks to a 18 persist attribute, which maintains the DOM data when the window is closed and restores it when the window is re-opened. 20 As seen in the following model, the function createBaseTreeDOM is used to create a default tree view. It is used by the chooseTestSuite function on the first interaction with the input element 22 to setup the tree view. This last mentioned function is called when clicking on the input element 30
Implementation in the toolbar. It summons a Dialog window containing the test suites’ tree view, which can be interacted with the functions in class chooseTestSuite. This functions include the creation,2 selection and removal of test suites, saving a selected test suite to appear in the Selenium IDE’s UI and supporting functions to handle and validate the data.4 Figure 4.3: Implementation model of the Test suite chooser plugin Selenium extensions Selenium IDE uses two types of extensions, namely, Selenium Core extensions and Selenium IDE6 extensions. The latter is used to implement or modify builders for locators and commands. Figure 4.4: Implementation model of the Command builders 31
Implementation As seen in section 4.4, locators can be added through the add function which takes as parameters the name of the locator builder and the function that is called to build the element locator. This 2 function takes the HTML element as the argument, and returns the element locator. Additionally, it uses the order variable to prioritize locators. Selenium IDE tries each locator’s function in order 4 until it finds one that identifies the correct element or until it reaches the end of the order array. Upon finding one, the locator is built and used. 6 The Selenium Core extensions, also called User extensions, are used to access the Selenium’s functions to modify them according to the prototype’s requirements. Two main Selenium objects 8 were worked with, the Recorder and Format objects, as observed in fig. 4.5. The former specifies the events handled by the Selenium IDE. The addEventHandler and removeEventHandler 10 functions allowed default handlers to be disable and switched to new developed handlers. More information about the changed events can be found in section 4.3.1. The other function, findClick- 12 ableElement, is used by the IDE each time a user left mouse clicks on the web application UI. It checks for clickable element such as input elements, text links and elements with an onclick 14 attribute. The inputTypes array variable contains strings from the HTML type attribute normally found in input elements. For example, it is used by the type event handler, which detects keys 16 pressed by the user. It only checks for input elements that require the user to input information and ignores buttons and similar elements like radio and checkboxes. 18 The Format object is used by the Selenium IDE to save the recorded commands or export them through the use of a formatter. Both functions seen in the Format element in the figure 20 4.5 were modified to save their generated test case files in a pre-determined folder located in the Jenkins contents. In addition, the exportContentAs function adds the test suite specified into 22 the exported test case through the use of the updateNamespace function. After completing the test case’s exportation, the export function also calls addToTestProperties, which executes the 24 saveTestCaseToProperties executable. This executable will be described in the topic that follows. Figure 4.5: Implementation model of the Selenium IDE’s user extension 32
Implementation saveTestCaseToProperties executable This program is located in the Jenkins workspace (See figure 4.1) and it is used whenever a test2 case is exported through the Selenium IDE. It takes two parameters, the test case’s name and its method name. It uses the test case’s name to find the location of the exported file in the Jenkins4 workspace. It then calls the checkCommands function which takes the RecurrentSteps cases’ commands that were referenced. This function uses the addRecurrentSteps function to replace the6 references with the respective commands. A more detailed analysis of this process is described in section 4.3.1, under C# formatters. As seen in fig. 4.6, the program uses a TestProperties class8 to structure the test cases information required to identify it. It is then transformed into a JSON object and added to the JSON array containing all exported tests. This array is located in the10 tests.properties file in the Jenkins workspace. Figure 4.6: Implementation model of the saveTestCaseToProperties executable Formatters12 The developed formatters, C# NUnit and RecurrentSteps formatters, are JavaScript scripts that are used by the Selenium IDE to translate the recorded Selenese commands to c# NUnit code. In14 order to do so, both take advantage of the Selenium WebDriver API (WDAPI class). The Driver and Element classes provide default functions to handle the commands. The former translates16 commands related to the browser. For example, navigate to a web page, find UI elements and close the browser window. The latter handles commands that work with elements found in the18 web application GUI. New event handlers created or existing ones whose handling changed are described in section 4.3.1 under User action events. These functions return a string that contains20 the translated commands in C# code. 33
Implementation Figure 4.7: Implementation model of the C# NUnit Formatters The C# test case files are created following the specification found in the options JSON variable. This is where the developed formatters differ. In the C# NUnit formatter, the variable 2 separates the test case file in three parts which are the header, the test and the footer. •Header: The first part of the file contains all the libraries necessary to run the test and the 4 information required to identify the test case, specifically its test suite and method name. Additionally, it sets up the test by declaring its variables and implementing the setup and 6 teardown functions, whose functionality is described in section 4.1.1. •Test: This part of the file takes the translated commands in C# code and appends them to 8 the test case’s method function which will be run during the test’s execution. •Footer: The last part contains the implementations of functions that handle the translated 10 C# test commands. These functions use the Selenium WebDriver API to strengthen the C# commands with additional steps. These steps include the handling of exceptions that occur 12 during the test’s execution, including taking a screenshot of the GUI. In specific cases, such as the click command, its associated function will first try to perform its task through 14 34
Implementation Selenium WebDriver functions. However, in case of failure, it will then try to achieve the same task through the execution of JavaScript script, as seen in listing B.1 in appendix A.2 On the other hand, the RecurrentSteps formatter produces a file with only the translated commands in C# code.4 The last component that supports the formatters is the SeleniumWebDriverAdaptor Class. It is used to handle the Selenese command’s type and redirect to an according function in the Driver6 variable. The three operations seen in the fig. 4.7,addSelection,mouseDown and select, are associated with the new commands that were created. A description of these commands is conducted8 in section 4.3.1, under User action events. Use Cases10 As seen in figure 4.8, the modified Selenium IDE component of the prototype allows testers to create test cases through the recording of their actions on the interface, to specify a corresponding12 test suite and to handle the generated test case by saving it in Selenese commands or export to C# NUnit.14 Figure 4.8: Use Case diagram of Selenium IDE 4.2.2 Jenkins Tests Selector Plugin16 The developed Jenkins plugin is the result of a modified Tests Selector plugin. This developed version changes the createTest and selectTest function seen in figure 4.9 in order to change the18 Jenkins Tests selector web UI. As mentioned in the last topic, the purpose of this changes is to 35
Implementation allow the user to access the tests’ screenshot from the same interface. Additionally, it alters the appearance of the tests information to indicate if the test was executed successfully or failed in its 2 last execution. The implemented interface can be observed in figure 4.20, in section 4.3.2. Figure 4.9: Implementation model of the tests selector Jenkins plugin transferTestsToBuild executable 4 This program is executed during the first phase of the Jenkins build operation, the Build phase. Its purpose is to move the files from a pre-determined folder, where the exported tests from the 6 Selenium IDE are located, to the pre-built Visual Studio NUnit project folder BuildSeleniumTests. It uses the GetAllFiles class, seen in 4.10, to obtain the path of all test case files with a valid 8 extension and their test suites to create a unique name for the test case file to avoid overwrites. After moving the files, the NUnit project is built and the test are compiled. 10 Figure 4.10: Implementation model of the transferTestsToBuild executable parseTestsProperties executable The main program of the Jenkins build operation. It runs during the Build phase and uses the 12 Visual Studio NUnit project and the tests.properties file from the Jenkins workspace. Its purpose 36
Implementation is to run the user selected test cases from the Jenkins web UI and generate the test results in a XML file.2 There are two courses of action, run all test cases or some of them. In the former’s case, the program executes the NUnit console (function runNUnitTests) who runs from the Visual Studio’s4 assembly. This generates a new test results XML file which overwrites any existing one. If the user chooses to not run all test cases, only the selected ones, the program executes6 the NUnit console on each test case file. Each test’s execution generates a XML file with its results. The purpose of the UpdateTestResultXML class’ main function updateXML is to update8 the main test results XML file by using the newly generated one. This process resorts to the TestXMLComponents class to structure the test’s components, which use the TestXMLComponent10 class to represent each component’s attributes, as seen in figure 4.11. The structure of the XML file is described in section 4.1.3.12 Figure 4.11: Implementation model of the parseTestsProperties executable extractTestResults executable This program is executed in the Post-build phase of the Jenkins Build operation. It takes the14 generated test results XML file to create JSON objects associated with those results. These JSON objects are structured through the TestProperties configuration, which can be observed in figure16 4.12. The program updates the tests.properties’ JSON Array with the created JSON objects con-18 taining the updated test results. Additionally, it uses the Tests Selector Plugin contents to store any screenshots taken during the tests’ execution. The plugin’s associated web UI can then access20 these screenshots and present them to the user, associating them to the respective tests. 37
Implementation Figure 4.12: Implementation model of the extractTestResults executable Use Cases The main functionality of the Jenkins component of the prototype is to automatically build the 2 generated test cases and represent their results to user, in order to grant a better overview of the project status. Additionally, as seen in Fig. 4.13, it allows the user to select which tests to run and 4 see screenshots of the interface captured when the tests failed. Figure 4.13: Use Case diagram of Jenkins 38
Implementation 4.3 Prototype For a full automated software test process two main features were required, Capture & Replay and2 Continuous Integration. The tools chosen to implement these functionality were Selenium IDE and Jenkins, respectively.4 4.3.1 Selenium IDE Regarding the Selenium IDE, its standalone version wasn’t enough to implement the components6 required for the prototype. The added functionality is based on user extensions and plugins created specifically for this research work.8 What follows is a detailed description of the implementation of each Selenium IDE feature developed for the prototype.10 User action events Due to special types of inputs found in Glintt solutions, some IDE functions and events were12 modified and new functionality was added. This was done to better simulate user interaction with those input elements. Additionally, the number of events handled that were turned into commands14 was increased in order to better simulate user actions and increase the tests’ robustness. All of the modified commands do not influence the users interaction with the GUI, but some of the new16 commands do. One of them is the addSelection command, whose actions were described in the table 4.1, which requires additional actions from the user. To ease its usage, this command has18 been made accessible from the context menu, which is available whenever the user right mouse clicks when recording the test, as observed in figure 4.14.20 The other two new commands are select and mouseDown. The first one is used for selecting to run commands found in a RecurrentSteps case. This command requires the user to add the22 specified case’s name in its parameter on the Selenium IDE interface, which can be done at any point. An example of its usage can be seen in figure 4.15, in which, prior to executing the recorded24 actions, the test case will run the commands located in a RecurrentSteps case called login. Regarding the mouseDown command, the moment the user presses the left mouse button, with-26 out needing to release it, an event is launched, which is recorded by the Selenium IDE. However, the event only occurs if pressed on selected input elements, because this command is used to bring28 focus to input elements that summon additional elements. For example, drop-down boxes and developed application inputs with similar behavior, which, when clicked, prompt a list of options.30 Returning to the modified IDE functions, the main changes were related to the handling of events that were generated from user actions that prompt loads, which was modified to take into32 account timing issues. The solution to this issues will be analyzed on the next section. In addition to this changes, the click command had another modification. It will first try to34 simulate its recorded action in the interface through the use of Selenium WebDriver commands. 39
Implementation Figure 4.22: Cause of the failed test presented in the test result interface Test Environment Contents and Management Having examined how the Jenkins interface behaves, the following section addresses how the 2 automation of the test environment management of its resources is accomplished. This section follows on from section 4.1.5, which outlined the test environment contents, lo- 4 cated in the Jenkins workspace. The first step in this process occurs whenever a test case is exported through the Selenium 6 IDE. It calls the saveTestCaseToProperties executable, which gathers information regarding the test case’s name and suite and adds the newly generated test case information to the JSON array 8 in tests.properties file. This file is closely integrated with the Jenkins’ test selector plugin and updates the list of runnable tests available for the user to select. 10 After the user specifies the tests to run and orders the build process to start, the process enters the Build phase, in which the generated test cases are transferred to the pre-built Visual Studio 12 NUnit project BuildSeleniumTests. Once transferred the tests are checked for syntax and dependencies errors. 14 Once the tests are ready, they are run through the NUnit console, which executes in background. Each test summons a browser window and starts replaying the user action recorded on the 16 window’s interface. When the test ends, before moving to the next test, the TestResult.xml file is generated. Additionally, if the test fails, a screenshot is taken and the window safely closes. This 18 screenshot will be available for examination in the Jenkins’ test selector interface. After all test are executed, the process generates the TestResult.xml file and enters the Post- 20 Build phase. In this phase, the test results are extracted from the XML file and the properties file is updated. The results are then published through the use of a simple NUnit test result report 22 46
Implementation Jenkins plugin. The process ends by sending a email to the selected email address whenever the build fails, a test is unstable or returns back to a success status.2 4.4 Discussion Since the focus of this research work was to generate reliable test cases through the capture of user4 actions and to ease the users of the burden of maintaining the generated tests, all in a automated fashion, a theoretical and a technical approach to this issue were conducted.6 4.4.1 Method From a theoretical standpoint, the two main contributions developed are the RecurrentSteps case8 and the automation of the test environment’s management. The RecurrentSteps cases allow the user to select a set of frequently used actions to reach a10 part of the web application. In case a failure occurs on those actions, the user only needs to fix the issue on the RecurrentSteps case file. This saves the user from having to fix each test case that12 replay those actions. This reduces the maintenance cost of the generated test cases as less time is needed to fix similar failures on different tests.14 Regarding the automation of the test environment’s management, the process involved abstracts the user of all Jenkins build operations. It only requires the selection of which tests to16 execute and the updated test results are presented in the Jenkins web UI. Turning now to the technical approach, about the implementation of the developed methods to18 structure the test cases, the purpose was to reduce the maintenance cost of the test cases generated through the use of C&R tools, which are known to be brittle, as mentioned in the literature review.20 To do so, several issues were located and dealt with separately, as analyzed in the previous chapter. •User actions events: The new and modified functionality regarding event handling allow22 a better simulation of the user actions recorded and increases the test case’s robustness. However, some of the new commands require the user to perform additional actions. For24 example, the use of the addSelection command is through the context menu and the select command is through the Selenium IDE interface. Additionally, the incorporation of this26 new commands and modification of the handling of the IDE’s events has, consequently, increased the test cases’ size. This may reduce its readability from a developer standpoint,28 in exchange of more easily maintainable test cases. •Recurrent Steps: The main problem with the implementation of the RecurrentSteps cases is30 its usage through the Selenium IDE. Currently, it requires the user to memorize the contents of the case only through its name, which can be seen in the test suite chooser box integrated32 in the IDE’s interface. In addition, its command(select) can not be added to the test case through recorded user actions in the GUI. However, the benefits discussed earlier in this34 section are implemented and the RecurrentSteps’ management is an automatic process that is integrated with the test environment.36 47
Implementation •Detection of list elements: The standalone selenium IDE would detect an element of a list through a locator that would depend on the position of the element in the list, unless it 2 was through the ID or Name locators. However, the use of an ID or name attribute on the list elements is rare. The developed addSelection command is used to bypass this issue by 4 identifying the element, independently of its position, on the list through the text contained in it. Further work is required to dynamically add types of lists that the command detects. 6 Currently it serves as a proof of concept, as it detects a type of list found on Glintt solutions. It is possible to identify elements in other types of lists, but it requires the user to identify 8 the locator of the list and manually add it to the C# NUnit Formatter’s code. In the case of the implementation of the developed methods related with the Continuous In- 10 tegration component, the extensibility that Jenkins provides was a great boon which was used to tinker with its web UI. It allowed the modification of a test selector page and the use of test report 12 plugins to better represent the test results. Additionally, Jenkins enables the use of its workspace to store the developed programs and test environment’s contents. It allows dynamic access to all 14 its contents from the Jenkins project and the Selenium IDE. However, as a result, it can only work in a specific Jenkins project (its configuration can be analyzed in appendix A.2). This is because 16 the Selenium IDE component does not have access to the name of the Jenkins’ projects, which is required in order to know the project’s workspace PATH for the saveTestToPropreties. Note that 18 all other developed programs only work if executed during the Jenkins build operation. They call Jenkins environment variables which can only be accessed through the Jenkins project. 20 4.4.2 Results The development of the prototype throughout this research work was conducted on a real applica- 22 tion on development in Glintt HS. This helped to validate the prototype since it has shown value to the company, despite that, at the time of writing, it has not been used by the quality assurance 24 team. The testing process in the company is mainly through functional testing on each development 26 patch. With the increasingly more complex software projects, the time spent on testing has increased and if the process continues the same, the test efficiency and validity will tend to decline. 28 The introduction of the develop prototype has shown to ease the creation and execution of test cases with minimal user action. It implements the automation of the generation of test cases and its 30 management. The development of tests can be run faster and can be run over and over again with less overhead. Note that manual testing will not go away, but these efforts can now be focused on 32 more rigorous tests. In addition to the new process of creating test cases, the prototype also deals with the man- 34 agement of the generated contents in an automatic fashion. Through the CI tool Jenkins, the test cases’ code is abstracted from the users, although it can still be accessed but requires programming 36 skills and knowledge of Selenium WebDriver. 48
Implementation The automated Jenkins build operation manages the test cases and their results without user intervention. The user only has to select which tests to execute and the process runs without2 requiring more input. This allows the user to let the selected tests run automatically during a period of time. For example, letting the tests run after leaving work and in the next day see the4 test results. Thanks to the Jenkins web UI, at the end of the operation the test results and console output can be visualized and analyzed.6 Having discussed the advantages of test automation and continuous integration that the prototype grants to the company’s testing process, what follows addresses the results of the more8 technical aspects of the developed prototype that were implemented. Tests that are created through C&R tools are known to be brittle and as a result, they have high10 maintenance costs. The main focus of this research work was to add support for test maintenance on generated tests through these tools to benefit test engineers and quality assurance personnel.12 As discussed in chapter 4, the recorded test cases can be run through the Selenium IDE’s interface. They are cheap to develop in terms of time required but are very expensive to maintain.14 For the purpose of addressing this issue, C# NUnit Formatters were developed to translate the unreliable recorded commands to C# NUnit test cases that allow the use of the Selenium WebDriver16 API. The formatters’ generated code follows the prototype’s design in NUnit which makes them more robust and facilitates the integration with the CI tool. In addition, the Selenium WebDriver18 API allows for better support of dynamic web pages where elements of a page may change without the page itself being reloaded.20 Still in the Selenium IDE’s interface, the user is now able to choose the test suite of the recorded test case in the Selenium UI, thanks to a developed Mozilla plugin that integrates a22 new view. This helps the user categorize the test cases and eases the readability of the test results in the Jenkins web UI. It is also through this view that it is made the separation between a test case24 and a RecurrentSteps case. The latter type of case was developed to reduce the tests’ maintenance costs since these steps can be used by multiple test cases. In case of a failure, it is only necessary26 to fix the issue on one file. 49
Implementation 50
Chapter 5 Conclusions and Future Work2 The final chapter of this dissertation is divided into two parts. The first presents the final remarks4 of this research work in order to summarize the whole process conducted and draws the main conclusions. The last section makes suggestions for improvement and speculates on future directions.6 5.1 Final Remarks A study of the state of the art in automated web testing was conducted to investigate how au-8 tomated testing can be applied to a Web application and what available frameworks and tools could be used to create a prototype that focuses on software testers without experience in Web10 testing. This work’s contribution is related to the developed prototype, which implements methods to increase the tests’ robustness such as implicit waits and new locator strategies, as well as12 a new technique called RecurrentSteps that allows the user to store frequently used commands. The test cases that use these commands can referenced them through the use of a select command14 during the test’s recording. Additionally, the prototype includes a Continuous Integration component—Jenkins—that automates the test environment, abstracting the user of its management. The16 Jenkins web UI was altered in order to allow the user to select which tests to run, visualize screenshots of the GUI in each failed test and analyze graphical test reports. Note that the prototype was18 developed and tested on a real application on development, although, at the time of writing, it has not been used by a quality assurance team. However, the results indicate that the generated tests20 are more maintainable than through standalone C&R tools, as even during a month of changes to the web application, almost all tests continued to behave correctly. Those tests that regressed had22 their causes of failure identified through the Jenkins web UI’s visual reports and screenshots and fixed within the Selenium IDE’s interface by editing the recorded commands. This whole process24 did not required any programming approach and middle steps to configure the test environment, demonstrating how integrated are the C&R and CI components of the prototype.26 51
Conclusions and Future Work 5.2 Future Work In the immediate future, the plan is for the prototype to be integrated in a quality assurance team 2 and its performance analyzed to confirm or confute the results. On the one hand, the Jenkins Build operation will be updated and optimized to allow the user to create different Jenkins projects with 4 their own respective workspace and speed up the tests’ execution process. On the other hand, the issue of interacting with the web application GUI to dynamically find UI elements indepen- 6 dently of its position is an intriguing one which could be usefully explored in further research, in particular, studying visual web testing tools based on image recognition (as an example, Sikuli 8 Script[Sik]). Finally, it is planned for the prototype to integrate manual tests in its test environment, granting the user access to all tests through the Jenkins web UI and manage them in the 10 same tool. 52
References [BKW09] Andreas Bruns, Andreas Kornstadt, and Dennis Wichmann. Web application tests2 with selenium. IEEE Software, 26(5):88–91, 2009. [CSRM14] Laurent Christophe, Reinout Stevens, Coen De Roover, and Wolfgang De Meuter.4 Prevalence and maintenance of automated functional tests for web applications. 2014 IEEE International Conference on Software Maintenance and Evolution, pages 141–6 150, 2014. [DGG09] Elfriede Dustin, Thom Garrett, and Bernie Gauf. Implementing Automated Software8 Testing: How to Save Time and Lower Costs While Raising Quality. Addison-Wesley Professional, 1st edition, 2009.10 [DLF06] Giuseppe A. Di Lucca and Anna Rita Fasolino. Testing web-based applications: The state of the art and future trends. Information and Software Technology, 48(12):1172–12 1186, 12 2006. [DLP05] Giuseppe A. Di Lucca and Massimiliano Di Penta. Integrating static and dynamic14 analysis to improve the comprehension of existing web applications. Proceedings - Seventh IEEE International Symposium on Web Site Evolution, WSE 2005, 2005:87–16 94, 2005. [Fir] Packaging and installation - mozilla | mdn. https://developer.mozilla.18 org/en-US/Add-ons/WebExtensions/Packaging_and_Installation# Installation. Accessed: 07-06-2016.20 [Gol] Sebastian Golasch. Dalekjs - automated cross browser testing with javascript. http: //dalekjs.com/. Accessed: 28-01-2016.22 [HK06] Antawan Holmes and Marc Kellogg. Automating functional tests using selenium. In Proceedings - AGILE Conference, 2006, volume 2006, pages 270–275, 2006.24 [LCRT13] Maurizio Leotta, Diego Clerissi, Filippo Ricca, and Paolo Tonella. Capture-replay vs. programmable web testing: An empirical assessment during test case evolution.26 Proceedings - Working Conference on Reverse Engineering, WCRE, pages 272–281, 2013.28 [LDD14] Yuan-Fang Li, Paramjit K. Das, and David L. Dowe. Two decades of web application testing—a survey of recent advances. Information Systems, 43:20–54, 7 2014.30 [LDLZ13] Li Li, Qiu Dong, Dan Liu, and Leilei Zhu. The application of fuzzing in web software security vulnerabilities test. Proceedings - 2013 International Conference on32 Information Technology and Applications, ITA 2013, pages 130–133, 2013. 53
REFERENCES [Moc] Mocha - the fun, simple, flexible javascript test framework. http://mochajs. org/. Accessed: 10-02-2016. 2 [MTT+11] Alessandro Marchetto, Roberto Tiella, Paolo Tonella, Nadia Alshahwan, and Mark Harman. Crawlability metrics for automated web testing. International Journal on 4 Software Tools for Technology Transfer, 13(2):131–149, 2011. [NBN14] Thanuja Janarthana Naidu, Nor Asyikin Basri, and Saravanan Nagenthram. Sahi vs. 6 selenium: A comparative analysis. In Proceedings of 2014 International Conference on Contemporary Computing and Informatics, IC3I 2014, pages 967–970, 2014. 8 [PRPE13] M. Polo, P. Reales, M. Piattini, and C. Ebert. Test automation. IEEE Software, 30(1):84–89, 2013. 10 [Sah] Sahi | open source automation testing tool. http://sahipro.com/ sahi-open-source/. Accessed: 28-01-2016. 12 [Sel] Selenium documentation. http://www.seleniumhq.org/docs/. Accessed: 27-01-2016. 14 [Sik] Sikuli script. https://lucene.apache.org/core/2_9_4/scoring.html/ /. Accessed: 16-06-2016. 16 [SMA05] Koushik Sen, Darko Marinov, and Gul Agha. Cute : A concolic unit testing engine for c. Program, 30:263–272, 2005. 18 [TSSC12] Suresh Thummalapenta, Saurabh Sinha, Nimit Singhania, and Satish Chandra. Automating test automation. Proceedings - International Conference on Software Engi- 20 neering, pages 881–891, 2012. [Wat] Web application testing in ruby. http://watir.com/. Accessed: 27-01-2016. 22 54
Appendix A Configuration2 A.1 Selenium IDE Configuration 1. Load the commandBuilders and userExtensions JavaScript Scripts in the Selenium IDE’s4 options menu (Figure A.1). 2. Add formatters in the Selenium IDE’s options menu (Figure A.2).6 3. Open the Jenkins Test Chooser Plugin with your chosen Mozilla browser to install it. Figure A.1: Selenium IDE’s general settings 55
Configuration Figure A.7: Jenkins’ Project Node Configuration 62
Appendix B Procedure2 B.1 Translated Selenese commands in NUnit C# What follows are NUnit C# segments of code that are generated through the Selenese commands4 and inserted into the exported test case. Some segments call developed functions that are declared in the test case through the C# NUnit Formatter, while others only consist of existing Selenium6 WebDriver C# commands. 8 1private void Click(By locator) { 2try {10 3IsElementPresent(locator); 4driver.FindElement(locator).Click();12 5} 6catch (WebDriverException) {14 7try { 8((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", driver.16 FindElement(locator)); 9}18 10 } 11 waitForGlinttLoadNotVisible();20 12 return; 13 }22 Listing B.1: Click command in C# 24 1IsElementPresent(By.Id("inputTest")); 2driver.FindElement(By.Id("inputTest")).Clear();26 3checkUncaughtError(); 4IsElementPresent(By.Id("inputTest"));28 5driver.FindElement(By.Id("inputTest")).SendKeys("Teste"); 6waitForGlinttLoadNotVisible();30 Listing B.2: Type command in C# that writes "Teste" in an input with ID "inputTest" 63
Procedure 1driver.Navigate().GoToUrl(URL); 2 Listing B.3: Open command in C# 4 1private void IsElementPresent(By by) 2{6 3this.wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(by)); 4}8 Listing B.4: Check if element is present command in C# 10 1private void SelectFromLists(string text) 2{12 3IReadOnlyCollection<IWebElement> listElements = driver.FindElements(By. CssSelector("div.some_container > .logic_template_wrapper")); 14 4foreach (IWebElement listElement in listElements) 5{16 6IWebElement patient = listElement.FindElement(By.XPath(".//div/div[3]/div/ div")); 18 7if (patient.Text.Contains(text)) 8{20 9patient.Click(); 10 waitForGlinttLoadNotVisible(); 22 11 checkUncaughtErrors(); 12 return;24 13 } 14 }26 15 }28 Listing B.5: Select element from list given its text in C# B.2 Gsearcher’s Locator Strategy To exemplify the addition of a new locator strategy in the commandBuilds file, what follows is the 30 implementation of the developed locator Gsearcher: 32 1LocatorBuilders.add(’gsearcher’,function(e) { 2var path = ’’;34 3var reachedGsearcherContainer = false;// Turns true after reaching a node with an ID, because it’s parent node will be a div of class "ui-autocomplete-box" 36 4var text = e.innerText || e.textContent || ’’; 5var current = e; 38 6while (current != null) { 64
Procedure 7if (current.parentNode != null) { 8path = this.relativeXPathFromParent(current) + path;2 9if (1 == current.parentNode.nodeType && // ELEMENT_NODE 10 current.parentNode.getAttribute("id")) {4 11 reachedGsearcherContainer = true; 12 }6 13 if (1 == current.parentNode.nodeType && // ELEMENT_NODE 14 reachedGsearcherContainer && (current.parentNode.getAttribute("class").8 indexOf("ui-autocomplete-boxr") > -1)) { 1510 16 return this.preciseXPath("//" +this.xpathHtmlElement(current.parentNode. nodeName.toLowerCase()) +12 17 ’[contains(@class,"ui-autocomplete-box")]’ + 18 path + "[contains(text(), ’" + text + "’)]", e);14 19 } 20 }else {16 21 return null; 22 }18 23 current = current.parentNode; 24 }20 25 return null; 26 });22 Listing B.6: Gsearcher’s locator strategy 65