31,19 €
Appium is an open source test automation framework for mobile applications. It allows you to test all three types of mobile applications: native, hybrid, and mobile web. It allows you to run the automated tests on actual devices, emulators, and simulators. Today, when every mobile app is made on at least two platforms, iOS and Android, you need a tool that allows you to test across platforms.
Having two different frameworks for the same app increases the cost of the product and time to maintain it as well. Appium helps save this cost.
With mobile app growth exploding, mobile app automation is mainstream now. In this book, author Nishant Verma provides you with a firm grounding in the concepts of Appium while diving into how to set up appium & Cucumber-jvm test automation framework, implement page object design pattern, automate gestures, test execution on emulators and physical devices, and implement continuous integration with Jenkins. The mobile app we have referenced in this book is Quikr because of its relatively lower learning curve to understand the application. It's a local classifieds shopping app.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 208
Veröffentlichungsjahr: 2017
BIRMINGHAM - MUMBAI
< html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2017
Production reference: 1290617
ISBN 978-1-78728-016-8
www.packtpub.com
Author
Nishant Verma
Copy Editor
Shaila Kusanale
Reviewers
Jagannath Balachandran
Kapil Sethi
Manoj Hans
Project Coordinator
Ritika Manoj
Commissioning Editor
Amarabha Banerjee
Proofreader
Safis Editing
Acquisition Editor
Siddharth Mandal
Indexer
Tejal Daruwale Soni
Content Development Editor
Aditi Gour
Graphics
Jason Monteiro
Technical Editor
Rashil Shah
Production Coordinator
Arvindkumar Gupta
Nishant Verma is a co-founder of TestVagrant Technologies. It's a service start-up addressing testing solutions for B2C companies with a focus on mobile and web, and helps companies deliver faster and reliably.
Nishant has 11 years of experience in software development and testing. He has worked with IT companies such as ThoughtWorks Inc., Aditi Technologies, and Altisource. He has extensive experience in setting up agile testing practices, functional and non-functional test automation, mentoring, and coaching. In the past, he has worked on web UIs and specializes in building test solutions in the mobile domain. He has hands-on experience with test automation tools such as WebDriver (Selenium2), Calabash, Frank, Appium, Watin, Sikuli, QTP, and DeviceAnywhere.
He actively maintains his own website on testing techniques, agile testing, automation techniques, and general learning. He has contributed to leading testing journals such as Testing Circus and Software Developer's Journal, and has been an active speaker at vodQA (testing event of Thoughtworks).
Nishant has authored a reference book on how to use Appium for automating Android apps using Java, which is available on Gitbook. It has received close to 200,000 views, 40,000 readers online, and has been downloaded around 3,000 times.
Jagannath Balachandran works as a lead consultant for ThoughtWorks India Pvt. Ltd. He has around 14 years of experience working with teams delivering software using agile and continuous delivery practices. He has extensively consulted clients on their journey toward continuous delivery.
Kapil Sethi is an agile practitioner with more than 12 years of experience in the software industry. He is a passionate advocate of shifting testing to the left most column in the agile development process and is a strong believer of the Testing Pyramid. He is a connoisseur of automation testing and has hands-on experience in designing automation testing frameworks using a variety of automation tools, such as WebDriver, Appium, Protractor, Applitools, Calabash, SoapUI, and QTP.
He has worked on numerous domains, including banking, mortgage, retail, e-commerce, and online gaming. His expertise involves helping development teams deliver quality products, coaching teams on agile adoption, transforming teams and thereby organizations, to make the working environment fun and passionate.
He is currently working with Nintex as an automation specialist. In the past, he has worked with companies such as MYOB, ThoughtWorks, Sapient, and Cognizant Technology Solutions, and performed the development lead, iteration manager, QA lead roles during his tenure.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1787280160.
If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Introduction to Appium
Native app
Mobile Web app
Hybrid app
Appium architecture
XCUITest
UiAutomator 2
Pros of using Appium
Summary
Setting Up the Machine
Machine setup for macOS
Installing Java
Installing Android SDK (using the Android command-line tool)
Installing Android SDK (using Homebrew) (Optional)
Creating Android Virtual Device (Optional)
Genymotion emulator
Debug help
Installing Appium
Installing Appium server (From Source) (Optional)
Selecting IDE
App under test
Machine setup for Windows
Installing Java
Installing Android SDK (using Android command-line tool)
Installing Node JS
Installing Appium
Installing Appium server (via npm)
Installing Genymotion
Selecting IDE
Appium GUI app
Summary
Writing Your First Appium Test
Creating an Appium Java project (using gradle)
Introduction to Cucumber
Writing our first Appium test
Running the feature file
Refactoring
Implementing the remaining steps
Running the scenario
Automating a mobile web app using Appium
Implementing the remaining steps
Automating the iOS app using Appium
Build the app
Deploying the app on the iOS Simulator
Via xcrun command
Using Appium
Generating Boilerplate code for iOS
Summary
Understanding Desired Capabilities
Refactoring -1
Server argument
Refactoring -2
Server capabilities
Refactoring -3
Android-only capabilities
Refactoring -4
iOS-only capabilities
Summary
Understanding Appium Inspector to Find Locators
Appium inspector
Implementing the other steps
UI Automator Viewer
Debugging mobile web apps using Chrome Inspect
Summary
How to Synchronize Tests
AppiumDriver
Implicit wait
Explicit wait
Fluent wait
Summary
How to Automate Gestures
Gestures
TouchAction
MultiTouch
Scroll
Swipe
Orientation
Summary
Design Patterns in Test Automation
Refactor -1
Page Object pattern
Refactor-2
Assertions
Implementing assertions in Page Object
Implementing assertion in test script
Avoiding dependencies between tests
Introducing set up and tear down
Summary
How to Run Appium Test on Devices and Emulators
Emulator
Running test on the Genymotion emulator
Devices
Running a test on actual Android devices
Running a test on actual iOS devices
Summary
Continuous Integration with Jenkins
Refactoring -1
Setting up Jenkins
Moving a project to Git
Adding Jenkins plugin
Setting up the Jenkins task
Viewing reports in Jenkins
Summary
Appium Tips and Tricks
Switching between views - web and native
Taking screenshots
Recording video execution
Interacting with another app
Running the test in parallel
Network conditioning
Summary
Appium Desktop App
Installing the new Appium app
Starting a simple server
Start New Session
Attach to an existing session
Desired Capabilities
Appium Inspector
Starting the server with advanced options
Appium Endpoints
Summary
Appendix
Introduction to Cucumber
How does Cucumber work?
Feature
Scenario
Background
Scenario Outline
Hooks in Cucumber
Running Cucumber
CLI Runner
JUnit Runner
Third-Party Runner (Via IntelliJ)
Finding an app's package name and launch activity
Using the ManifestViewer app
Using the Appium GUI app
Installing Google Play services in the Genymotion emulator
Summary
With the growing popularity of mobile apps and the enormous growth in the number of mobile devices all around the world, mobile ecosystems are poised to further scale up. Until a couple of years ago, the IT world was dominated by web and enterprise application development and testing. With the growth of mobile apps around the world, the trend is shifting toward mobile development and testing as a niche skill set. Mobile testing had largely been manual until the advent of standard test automation libraries, such as Calabash and Appium.
This book is an effort toward gearing up a better testing workforce by making them educated and aware of a mobile testing and automation tool called Appium. Appium is the most widely adopted mobile test automation tool. The community support has been vibrant, but there is a lack of a structured step-by-step guide or documentation around building a framework. This book is an attempt to bridge that gap and serves as a handheld guide for each tester who wants to build their own mobile test automation framework from scratch.
This book is intended for developers and testers who want to learn mobile app testing and automation using Appium. The book takes you on a journey of understanding Appium and slowly gets you started with the test automation ecosystem. Cucumber is one of the most promising technologies, and is rising in popularity due to the wide adoption of the agile and behavior-driven development methodologies. This book introduces you to the concept of Cucumber and shows how you can build your own testing framework in Cucumber and Appium from scratch. It contains example code snippets of creating a sample project, writing first Appium tests, evolving the test framework, and setting up Jenkins.
The book is organized into two parts:
Appium basics
: This largely covers an understanding of Appium, desired capabilities in Appium, Appium inspector, and how to use it to find locators, test synchronization, and automate widely used gestures, such as tap, scroll, press, and long press.
Appium advanced
: This covers design patterns for the automation framework, how to run tests on actual devices and emulators, how to run tests on a Genymotion emulator, continuous integration with Jenkins, and Appium tips and tricks.
Chapter 1, Introduction to Appium, starts with an introduction to the mobile app. It talks about different types of mobile app, that is, native, hybrid, and mobile web. We then take a little closer look at the advantages and limitations of each type of mobile app. We learn about Appium's architecture and about two different automation frameworks Appium uses, XCUITest and UIAutomator2 for iOS and Android, respectively.
Chapter 2, Machine Setup, starts with instructions for setting up your machine in order to start using Appium and write automated tests. In this chapter, we address the setup for both Windows and Mac machines. Some of the prerequisites to install are the most recent Java, Android SDK, Genymotion Emulator, Appium, IntelliJ as the preferred IDE, and the app under test. We will also learn to create the sample Android emulator as well as the Genymotion emulator. We will learn how to install Appium, both via npm and the Appium GUI app. We will take a detailed look at the Appium GUI app and the iOS and Android settings Appium allows.
Chapter 3, Writing Your First Appium Test, helps us write our first Appium test. We will start by creating a Java project in IntelliJ and then get introduced to Cucumber. We create a sample feature file and write our first scenario using the Given-When-Then format. We will learn how to start Appium session and use Appium Inspector. We will then write our first automated test and learn how to run the cucumber test. We will also learn how to write our first test for mobile web app and learn how to use the Chrome developer tools to find the locators. We then run these tests via the IDE.
Chapter 4, Understanding Desired Capabilities, tells us about the concept of desired capabilities in Appium. We learn about the mandatory capabilities and the device-specific desired capabilities, such as Android and iOS. We will look into the server argument and the various flags it exposes along with its sample usage.
Chapter 5, Understanding Appium Inspector to Find Locators, shows us how to use the Appium inspector to find the locator of a UI element. We learn to derive the xPath over the Appium-generated xPath values. We looked into another tool, UIAutomatorViewer, and how to use it. We also learn how to debug the mobile apps using Chrome's inspect feature.
Chapter 6, How to Synchronize Tests, explores the different types of drivers Appium allows you to create, along with the various synchronization strategies. We will learn about the implicit wait, explicit wait, and fluent wait. We also learn about ExpectedConditions and the various predefined conditions it allows.
Chapter 7, How to Automate Gestures, explains implementing various gestures that Appium supports. We will learn how to implement the most frequently used gestures, such as tap, swipe, scroll, and drag and drop. We will also learn about the orientation and how to change the orientation of devices between the landscape and portrait modes.
Chapter 8, Design Patterns in Test Automation, covers the concept of the design pattern in test automation. In this chapter, we will take a detailed look at the page object pattern and then learn how to implement it in the current framework, which we have been building since Chapter 3, Writing Your First Appium Test. We will learn about assertions and where they belong, and we will also learn about the concepts of setup and teardown and how to implement them using pre-specified hooks in cucumber.
Chapter 9, How to Run Appium Test on Devices and Emulators, shows you how to connect physical devices and prepare them for development and testing purposes. It also demonstrates how to configure the Genymotion emulator and run tests. We learn how to retrieve the UDID of iOS devices, the libraries we need to install, and the process for running the test on iOS.
Chapter 10, Continuous Integration with Jenkins, teaches the concept of Gradle and writing Gradle tasks. We start by creating a Gradle task to run the test via command line and moving the project to Git. We navigate through downloading and installing Jenkins. We learn how to set up a Jenkins job and trigger it and view the report. This chapter explains how to implement continuous testing using Jenkins.
Chapter 11, Appium Tips and Tricks, shows you some tips and tricks in the form of code snippets, that can be used to make your test framework more intelligent and innovative. We will learn about switching between webviews and native views, taking screenshots, and recording video using adb commands. We will also explore the approach of running tests in parallel on multiple devices and about the network simulation API.
Chapter 12, Appium Desktop App, explores the new Appium Desktop App. It discusses in details about how to install the new Appium GUI app, how to start an appium server with basic and advanced options. It also explains how to use the Desired Capabilities while setting up a session and how to connect to different end points (the non local server).
By the end of this book, you will have learned about Appium, how to build a test automation framework from scratch in Cucumber and Appium, and how to set up Jenkins to run tests.
Appendix, Appendix takes a deeper insight into different how to's which are needed across chapters. It includes a deep dive into Cucumber and explains various concepts of Cucumber. It also talks about finding details needed for Appium for android installer. Very importantly, it tells us how to install the Google Play services on the Genymotion Emulator.
To get started with this book, you need basic knowledge of Java. You should be aware of the OOPS concept and should be able to use loops and define classes. A basic understanding of mobile apps and knowledge of Android would be an added advantage; however, it is not a must. The book provides hands-on experience with writing and executing code. There are some software prerequisites, which are explained in the second chapter, which helps set up the development environment and readies your machine for any future mobile automation work using Appium.
This book is intended for developers/testers who want to learn mobile automation using Appium. It doesn't require any prior experience in testing mobile applications or automation. This book serves as a detailed guide for Appium and a step-by-step guide to building a mobile test automation framework from scratch. The only prerequisite for this book is to have a basic knowledge of Java programming. By the end of this book, you would have gained advanced knowledge of Appium and would have learned how to build a framework in Cucumber and Appium. You will be able to leverage this framework building knowledge by replacing Appium with any other UI automation tool, such as Selenium.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the
SUPPORT
tab at the top.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on
Code Download
.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mobile-Test-Automation-with-Appium. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
The mobile app market is huge, and it will increase further. Approximately, there are 2 billion smartphone devices worldwide, which is more than two times the number of personal computers in the world. A report (for more information, visit https://www.statista.com/topics/1002/mobile-app-usage/) shows that more than 102 billion apps have been downloaded worldwide, and the number is expected to reach 268 billion by 2017. According to one of the reports (for more information, visit http://www.statista.com/statistics/269025/worldwide-mobile-app-revenue-forecast/), the worldwide mobile revenue for 2015 amounted to $41.1 billion and is expected to reach $101.1 billion by 2020.
With all these promising growth numbers and trends, learning mobile app development and testing will be worth it and will have a huge demand.
In this chapter, we will cover the following topics:
Types of mobile apps
Native App
Mobile Web app
Hybrid App
Appium Architecture
What is XCUITest
What is UiAutomator 2
Let's take a look at mobile apps, which form this ecosystem, and how they are broadly categorized based on the way they are developed:
Let's understand the different types of mobile apps.
The mobile world is majorly dominated by two operating systems: iOS and Android. Most apps are made for both the platforms given the user base. In this chapter, we will take a detailed look at the following:
Native app, mobile web, and hybrid app
The characteristics of each type of app
A sample example app of each type
