Android Espresso Cheat Sheet



チェンチュー[Chiu-Ki Chan]

  1. Android Espresso Cheat Sheet
  2. Android Espresso Cheat Sheet
  3. Android Espresso Cheat Sheet Pdf
  4. Android Cheat Sheet
  5. Android Espresso Cheat Sheet Printable
  6. Android Espresso Cheat Sheet Free

@chiuki
+ChiuKiChan

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Espresso Cheat Sheet In an older postfrom 2013 I briefly described the Android test automation tool called Espresso. Espresso is the test automation framework provided by Google to implement fast and reliable tests for Android apps. Espresso by default has many matchers that help you find views that you need to do some checks or interactions with them. Most important ones can be found in the following cheat sheet: Some examples of matchers are: withId(R.id.IDofobjectyouarelookingfor). Espresso Test Android Cheat Sheet Thanks to Google, testers have a clear cheat sheet that they can refer to while developing test cases with Espresso. The cheat sheet below provides references to most of the instances that come with the Espresso Components discussed earlier. Image Credit: Espresso Framework by Android Developers – Google. Espresso Theory. The core API is small, predictable, and easy to learn and yet remains open for customization. Espresso tests state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way.

Automatic UI testing

Espresso

  • Android Testing Support Library
  • Simulate user interactions
  • Automatic synchronization of test actions with app UI


No need to sleep

Formula

ViewMatcher

ViewAction

ViewAssertion

More info

  • github.com/chiuki/espresso-samples under hello-world

Espresso library

Hamcrest

Sheet

Espresso

developer.android.com/training/testing/espresso/cheat-sheet.html

Hamcrest

marcphilipp.de/downloads/posts/2013-01-02-hamcrest-quick-reference/Hamcrest-1.3.pdf

Toolbar title

Hierarchy Viewer

isAssignableFrom

toolbar.getTitle()

toolbar.getTitle()

  • Verify the Toolbar
  • TextMatcher instead of String

More info

  • github.com/chiuki/espresso-samples under toolbar-title

Formula

ListView

App

App

App

Test

withValue

RecyclerView

Espresso

RecyclerView

onData

RecyclerViewActions

actionOnItemAtPosition
  • actionOnHolderItem with Matcher<VH>
  • actionOnItem with Matcher<View>

More info

  • github.com/chiuki/espresso-samples under list-view-basic
  • github.com/chiuki/espresso-samples under recycler-view-basic

Espresso Idle

  • No UI events queued
  • No tasks in AsyncTask thread pool

Custom IdlingResource

Define your own condition

e.g. IntentService is not running.

IntentServiceIdlingResource

isIntentServiceRunning()

Register

More info

Dagger

Dependency injection.

Different objects for app and test.

Mockito

Mock objects in test.

Dagger components

Application

MockApplication

MockTestRunner

build.gradle

Mockito

More info

Summary

  • Matcher, ViewAction, ViewAssertion
  • Combining matchers
  • Custom matchers
  • ListView
  • RecyclerView
  • Idling Resource
  • Dagger and Mockito

Friend Spell

  • Google Plus
  • Nearby API
  • Database
Android Espresso Cheat Sheet
  • Dagger
  • Mockito
  • JUnit
  • UI-less instrumentation
  • Espresso

Thank you!

  • bit.ly/advesp
  • github.com/chiuki/espresso-samples
  • github.com/chiuki/android-test-demo
  • github.com/chiuki/friendspell
  • bit.ly/pluralsight-chiuki
  • gumroad.com/chiuki
  • techspeak.email
  • blog.sqisland.com
  • @chiuki
  • +ChiuKiChan
  • tinyletter.com/sqisland
UncategorizedAndroid Espresso Cheat Sheet

The year is slowly coming to an end, so just the right time to look into what’s new around test automation frameworks.

Top on the list of the most used testing tools for Android is still Espresso, so I’ll give a brief overview of developments, but then also introduce some new test automation frameworks.

Here is the section overview:

  • What’s new in Android Espresso?
  • Kaspresso
  • Barista
  • BusyBee
  • Repeato
  • Waldo

What’s new in Android Espresso?

Since Android Espresso is already very well known, I will not go into the basic description of the framework here. Instead, I have compiled a list of the features that have been released in the last few months (Jan 2020 – Nov 2020):

  • Add Espresso ViewMatcher APIs for negative conditions
  • Allow unregistering Loopers from Espresso IdlingRegistry
  • Support specifying junit RunListeners via java.util.ServiceLoader
  • Support filtering by prerelease SDKs via SdkSuppress#codeName
  • Add truth extensions for Location
  • Add truth assertions for Bundle string and parceable arrays.
  • Support ActivityOptions in ActivityScenario
  • Make activity lifecycle transition timeout configurable
  • Add a BundleMatchers.isEmpty() and isEmptyOrNull() methods
  • Allow Intents.release without Intents.init
  • Add ViewMatchers.isFocused()
  • Enhance error messaging for WithIdMatcher
  • ViewMatchers.isDisplayingAtLeast() works for views with negative scale.
  • Remove spurious wait in waitForAtLeastOneActivityToBeResumed.
  • Set correct meta state for ACTION_UP

Samsung syncmaster 710v manual. On top of that there is a great cheat sheet available for download here.

Nothing has changed about the tiresome topic of idling resources. These are still necessary to keep espresso up to date about whether it needs to wait before executing the next step. For example because a background process has not yet been completed.

NestedScrollViews are still not supported either, so an extra implementation is necessary.

Kaspresso

Kaspresso is a test automation framework built on top of Espresso and UIAutomator. With a lot of useful additions. It was developed to improve some of the known weaknesses of espresso (flakiness, no ADB support, difficult to read code).

The Kakau Library was used to ensure better readability.

Let’s take a look how Kakau compares to pure Espresso. Here is a simple Espresso test example: Terraria maps android.

And here the same test in Kakau DSL syntax:

Because longer tests can become confusing, Kaspresso’s team has extended the Kakau DSL. This way we can also don’t have to care about what is under the hood of our tests, it’s either Espresso or UI Automator.
A full test written with Kaspresso could look like this:

The speed comparison with a conventional UIAutomator (Appium) Test is also remarkable:

Kaspresso chooses a very sophisticated strategy (compared to Espresso or Barista) to improve the stability (flakiness) of tests: Android’s event queue is monitored and commands are only sent when Android is in a calm state and there is a low likeliness that UI commands will be skipped because of lack of computation resources. In addition, the testing framework also automatically closes system dialogs that sometimes cause a test to fail because they cover important elements of the app.

If you want to know more, the project and functions are really well documented.

Advantages of Kaspresso:

  • Greatly improved stability for tests compared to all other test automation frameworks
  • Improved speed
  • Abstraction and thus better maintainability for tests
  • Open Source (110 PullRequests & 887 stars on Github)

Cons of Kaspresso:

  • DSL adds a further level of abstraction and requires some time to get to know and familiarize yourself with
  • DSL can sometimes lead to confusing code. See an example here.
  • Documentation and some issues are partly in Russian

Barista

Barista is a big extension of espresso. The stability (flakiness) is improved with a retry strategy. For certain tests, you can specify how often a test should be repeated if it fails. In addition, like Kaspresso, Barista uses an abstraction applied to PageObjects for UI components and test routines.

A simple example:

Fairly legible right? Obviously, some more work is needed to implement those methods. But still, the structure is very clean and readable:

In case of a feature change in the app you might be able to avoid changing all your 50 tests and instead only change the implementation of a single test method.

Advantages of Barista:

  • Improved stability through auto retry and auto scroll
  • Good readability thanks to an additional level of abstraction (Page objects)
  • Very good documentation, easy to use
  • Open source and active community (220 pull requests & 1222 stars on Github)

Disadvantages of Barista:

  • Idling resources still have to be implemented manually

BusyBee

BusyBee is also an extension of Espresso. More specifically, a substitute for CountingIdlingResource is used, which has some known difficulties. One of them being debugging: If a test fails because CountingIdlingResource does not signal an idling state, it is often not clear why the exception happened.

Instead of just tracking the number of ongoing processes, BusyBee logs the specific, currently running processes. This is accomplished by tracking a Java object, a character string or an ID.
If a timeout occurs, the list of running processes can be output. This way debugging is getting easier.

Advantages of BusyBee:

  • Simple tool that simplifies the handling of tiresome IdlingResources
  • Open Source (11 pull requests, 143 stars)

Cons of BusyBee:

  • Small tool, no substitute for barista or kaspresso

Repeato

Repeato is a new NoCode test automation framework for Android. Tests can be recorded using a recorder and then played back. More specifically: When recording, small “fingerprints” are recorded in the vicinity of the mouse pointer. On replay, these are used to find the corresponding UI element again.

There is also the possibility of creating “Script Steps” which allow you to execute ADB or other terminal commands.

That’s how you record a test:

Cluster of atoms. Please find below the Cluster of atoms for short answer and solution which is part of Daily Themed Crossword March 24 2020 Answers.Many other players have had difficulties with Cluster of atoms for short that is why we have decided to share not only this crossword clue but all the Daily Themed Crossword Answers every single day. In case something is wrong or missing kindly let us know.

https://www.repeato.app/wp-content/uploads/2020/11/record.mp4

Afterwards, the recorded steps can then be played back:

https://www.repeato.app/wp-content/uploads/2020/11/replay.mp4

Tests created with Repeato are stored in the file system and can also be versioned via Git as well as shared and edited within your team.

There is a free version, but advanced features such as continuous integration support or workspaces are not included.

The tool is particularly helpful as an extension for manual testing: Since developer resources are often scarce, it makes sense to outsource part of the test automation to the QA team.

Advantages of Repeato:

  • Very easy to use, can be used by non-developers (QA team)
  • Repeato does not need access to the source code of the app
  • Installation of the software only takes a few minutes
  • Visual reporting dramatically simplifies troubleshooting

Android Espresso Cheat Sheet

Cons of Repeato:

  • no open source
  • extended version is commercial (49 EUR per month)

Waldo

Waldo is a new cloud service that allows you to record tests using a recorder. The developers have focused on offering a simple interface that also allows non-developers to create tests. The whole thing works, just as with Repeato, without a line of code.

A visual comparison of the original test run (everything worked) with the faulty test run (exception happened) makes debugging a breeze:

Disclaimer: I encountered some difficulties while testing the service:

Android Espresso Cheat Sheet

  1. The instructions on how to export the build were not visible (empty dialog)
  2. When starting the build, an error occurred several times – unfortunately that’s when I ran out of patience. TBC…!

Advantages:

  • Very clear UI, easy to use
  • Great animation, the llama signup is really fun!

Android Espresso Cheat Sheet Pdf

Cons:

  • Price ($ 1999 USD / month)
  • more complex use cases or data driven testing not possible
  • Currently no Android support (“Coming soon”)
  • The service does not seem to be over beta stage yet

Conclusio

Even with Espresso continuously being improved, there is still enough potential to make test automation more practicable, maintainable and intuitiv. Therefore there are still new but also older alternative test automation frameworks that address these weaknesses. Unfortunately, there is no clear test winner. Each of the frameworks clearly has its strengths and weaknesses.

Computer Vectors by Vecteezy

Android Cheat Sheet

Tags:android ui testing, android UI testing tools, espresso, espresso idling resource, test automation tool, ui testing

Android Espresso Cheat Sheet Printable

Like this article? there’s more where that came from.

Android Espresso Cheat Sheet Free

  • Tdd Vs Bdd: What Is The Difference Between The Two
  • 5 New Test Automation Frameworks for Android (2020)
  • Why I Chose to Write my Own Android UI testing tool
  • How to write Flutter UI tests
  • How to choose the Best Android UI Testing Tool in 2020




  • Comments are closed.