Espresso Is an Open Source Android User Interface (UI) Testing Framework Developed by Google
Total Page:16
File Type:pdf, Size:1020Kb
Espresso i Espresso About the Tutorial Espresso is an open source android user interface (UI) testing framework developed by Google. The term Espresso is of Italian origin, meaning Coffee. Espresso is a simple, efficient and flexible testing framework. This tutorial walks you through the basics of Espresso framework, how to setup Espresso framework in a project, work flow of the framework and finding, automating & asserting user interface components in the testing environment with simple android application. Audience This tutorial is prepared for professionals who are aspiring to make a career in the field of android mobile application as well as android automated testing. This tutorial is intended to make you comfortable in getting started with the Espresso testing framework concepts. Prerequisites Before proceeding with the various types of concepts given in this tutorial, we assume that the readers have the basic knowhow of android mobile programming. In addition to this, it will be very helpful, if the readers have a sound knowledge on Java. Copyright & Disclaimer Copyright 2019 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] i Espresso Table of Contents About the Tutorial ...................................................................................................................................... i Audience .................................................................................................................................................... i Prerequisites .............................................................................................................................................. i Copyright & Disclaimer ............................................................................................................................... i Table of Contents ...................................................................................................................................... ii 1. Espresso – Introduction ............................................................................................................................ 1 Features of Espresso .................................................................................................................................. 1 Advantages of Espresso ............................................................................................................................. 1 2. Espresso — Setup Instructions .................................................................................................................. 2 Prerequisites ............................................................................................................................................. 2 Configure Espresso Testing Framework ...................................................................................................... 2 Device Settings .......................................................................................................................................... 9 3. Espresso — Running Tests In Android Studio .......................................................................................... 10 4. Espresso — Overview of JUnit ................................................................................................................. 15 Write a Simple Unit Test .......................................................................................................................... 15 Annotations ............................................................................................................................................. 16 Order of Execution .................................................................................................................................. 21 Assertion ................................................................................................................................................. 21 5. Espresso — Architecture of Espresso Testing Framework ....................................................................... 22 Overview ................................................................................................................................................. 22 ViewMatchers ......................................................................................................................................... 23 ViewActions ............................................................................................................................................ 23 ViewAssertions ........................................................................................................................................ 23 Workflow of Espresso Testing Framework ................................................................................................ 23 Example – view assertion ......................................................................................................................... 25 6. View Matchers ........................................................................................................................................ 28 ii Espresso Hamcrest Library ..................................................................................................................................... 28 Matchers ................................................................................................................................................. 30 7. Espresso — Custom View Matchers ........................................................................................................ 38 8. Espresso — View Assertions ................................................................................................................... 41 9. Espresso — View Actions ........................................................................................................................ 45 10. Espresso — Testing AdapterView ............................................................................................................ 49 Methods .................................................................................................................................................. 49 Write a Sample Application...................................................................................................................... 50 11. Espresso — Testing WebView ................................................................................................................. 54 Write a Sample Application...................................................................................................................... 55 12. Espresso — Testing Asynchronous Operations ........................................................................................ 59 User Interface Threading ......................................................................................................................... 59 Overview ................................................................................................................................................. 59 Sample Application .................................................................................................................................. 60 13. Espresso — Testing Intents ..................................................................................................................... 71 Setup....................................................................................................................................................... 71 intended() ............................................................................................................................................... 71 intending()............................................................................................................................................... 77 14. Espresso — Testing UI for Multiple Application ...................................................................................... 80 Setup Instruction ..................................................................................................................................... 80 Workflow for Writing Test Case ............................................................................................................... 80 15. Espresso — Test Recorder ....................................................................................................................... 82 16. Espresso — Testing UI Performance ........................................................................................................ 89 17. Espresso — Testing Accessibility ............................................................................................................. 90 Conclusion ..............................................................................................................................................