Skip to main content

Implementing UI tests on iOS and Android using screenshot comparison tools

Have you ever thought when writing or maintaining UI tests, there must be a better way?

Take a look at screenshot tests provided by Google Firebase and Facebook:

ios-snapshot-test-case
A "snapshot test case" takes a configured UIView or CALayer and uses the renderInContext: method to get an image snapshot of its contents. It compares this snapshot to a "reference image" stored in your source code repository and fails the test if the two images don't match.

GitHub Facebook

screenshot-tests-for-android
Testing rendering for your Android app is hard. How do you prevent visual regressions in paddings and margins and colors from creeping in?
Iterating on UI code is hard. How do you quickly verify that your layout or view changes work correctly in all configurations?

screenshot-tests-for-android can solve these problems by providing a test framework that checks for visual differences across changes.

GitHub Facebook

Google Firebase Test Lab
Test Lab lets you run Espresso, Robotium, or UI Automator 2.0 instrumentation tests written to exercise your app from the Firebase console, Android Studio, or the gcloud command line interface. You can also use Robo test to automatically exercise your app from the Firebase console or the gcloud command line.


Robo test captures logs, creates an "activity map" that shows a related set of annotated screenshots, and creates a video from a sequence of screenshots to show you the simulated user operations that it performed. Learn more about Robo test.

Firebase Test Lab

Firebase Test Lab for Android includes a library that you can use to take screenshots when running instrumentation tests, such as tests written using the Espresso test framework. To add this capability to your test, use the cloudtestingscreenshotter_lib.aar library.

The ability to take screenshots is already incorporated into the test APK, app-debug-test-unaligned.apk, for the NotePad sample app, and screenshots are also captured when you run Robo test. The following instructions tell you how to add the screenshot library to your app and how to call that library from your test.

After your test has run, you can review the screenshots in Android Studio or in the Firebase console.
Screenshot comparison screen

Firebase Take Screenshots

PointFree SnapShotTesting with Swift!

Comments

Most Favorite Posts

Pieceable Viewer

Show your iOS apps on the web inside an interactive flash movie. Pieceable Viewer works with most iPhone applications. If you have a native binary that runs on the iOS Simulator, it should run in Pieceable Viewer. UIKit based applications work best. OpenGL and MapView based content runs but isn't rendered - these will be better supported in a later version. iPad applications will be supported in a later version. Pieceable

Simple Reachability + Blocks

I like this block-based approach much more as opposed to listening for notifications or having a delegate callback on a central Reachability instance. In most uses-cases I have seen so far you are probably just calling a method on the watching view controller and there it helps that the observer block can capture some state. Because of this we don’t need to use the C-level state passing. At the time of this writing the code for DTReachability is now present on the develop branch of DTFoundation, it will be merged into master for the next release. Since it has a dependency on the SystemConfiguration.framework I put it into its own static lib and Cocoapods sub spec to use individually. I am using this in AutoIngest for Mac now, but it should work without modification on iOS just the same. Your feedback is welcome. Cocoanetics

Server-driven UI (SDUI): Meet Zalandos AppCraft and AirBnB Lona

A short WTF: Joe Birch:  SERVER DRIVEN UI, PART 1: THE CONCEPT Zalando seems to follow the SDUI principle as well - defining a common design language and construct the screens on the backend while displaying them natively on the clients. They even go one step further; they implemented a mighty toolset to enable non-technical stakeholders to define their own native app screens Compass: Web tooling to create screens and bind data Beetroot: Backend service that combines the screen layout definition with the data Lapis/Golem: iOS/Android UI render engines Crazy cool! Good job, guys (when you do an open-source release?) To even move faster a Flutter based UI render engine implementation was great! See also AirBnB Lona SDUI approach Building a Visual Language Why Dropbox sunsetted its universal C++ mobile project and AirBnB its React Native implementation

FF Chartwell: Defining pie chart, bar charts and many others via vector font!

  With FF Chartwell you can define Charts via OpenType font, and transform a string, e.g. " 60+ 30 + 10 " into a Pie Chart 60%-30%-10% including color support (not only b/w!) without rendering anything: directly via font without using any images! Check this out: FontBlog FF Chartwell So great!

10 Coolest Keyboard Shortcuts You Never Knew About

Keyboard shortcuts are the lifeblood of many productive Mac users. Not only can keyboard shortcuts make for a nicer user experience and cut down on the time needed to do a task, they can also just be plain cool. Mac OS X has many shortcuts ready and willing to do your bidding, but also has many hidden and unknown shortcuts. That's why we've compiled a list of 10 of the coolest keyboard shortcuts you never knew about. MacLife

Facebook SDK 3.0 Beta for iOS

1. Better user session management: In the past, managing auths, user sessions and tokens was hard. We've spent a lot of time working to make these takes easier for you. This release introduces FBSession, which manages, stores and refreshes user tokens with default behaviors you can override. It uses the block metaphor to notify your app when a user's token changes state. 2. Ready-to-Use Native UI Views: This SDK release includes a variety of pre-built user interface (UI) components for common functions. You can quickly drop them into your apps instead of building each one from scratch or using dialogs. This gives you a fast, native and consistent way to build common features. 3. Modern Objective-C language features support: With Automatic Reference Counting (ARC), you no longer have to spend as much time on memory management. Support for blocks means that it’s now more straightforward to handle sessions and calls to asynchronous Facebook APIs. This, along with inclusion o...

Writing High-Performance Swift Code

Enabling Optimizations Whole Module Optimizations (WMO) Reducing Dynamic Dispatch Dynamic Dispatch Advice: Use 'final' when you know the declaration does not need to be overridden Advice: Use 'private' and 'fileprivate' when declaration does not need to be accessed outside of file Advice: If WMO is enabled, use 'internal' when a declaration does not need to be accessed outside of module Using Container Types Efficiently Advice: Use value types in Array Advice: Use ContiguousArray with reference types when NSArray bridging is unnecessary Advice: Use inplace mutation instead of object-reassignment Wrapping operations Advice: Use wrapping integer arithmetic when you can prove that overflow cannot occur Generics Advice: Put generic declarations in the same module where they are used The cost of large Swift values Advice: Use copy-on-write semantics for large values Unsafe code Advice: Use unmanaged references to avoid reference counting overhead Protocols Ad...