Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to take a screenshot and test pixel values with espresso?

I started using espresso and wrote some simple UI Tests for clicking on buttons, typing in text and checking if everything is there where it should be. Now I wanted to take a screenshot and test some pixel values, but I can't find a way to do this. Has anyone any suggestions? Is it even possible with espresso?

like image 991
meatboy Avatar asked Nov 12 '13 11:11

meatboy


People also ask

What is Screenshot testing?

screenshot-tests-for-android generates deterministic screenshots of views during a test run. By deterministic, we mean that every single run of your tests generates a pixel-perfect screenshot of the app as it would appear on a user's device.

What is espresso testing used for?

Espresso is a testing framework that helps developers write automation test cases for user interface (UI) testing. It has been developed by Google and aims to provide a simple yet powerful framework. It allows both black-box testing as well as testing of individual components during development cycles.


2 Answers

As espresso tests are simple InstrumentationTestCases, you could use paparazzo and celebrity to take screenshots of your application.

Spoon also as a very nice screenshot system. Sharper than paparazzi but that can only take a screenshot of activities, not dialogs for instance.

And last but not least, since android SDK 16, you can use screencap utility to take very fast and sharp screenshots of an app. I think this solution is really the best but it works only with SDK 16+.

Finally to test screenshots against a reference screenshot, there is no real tools. You can find great ideas of implementation on stack over flow, but up to now, noone came with a reference tool that can be used on android.

like image 69
Snicolas Avatar answered Sep 17 '22 20:09

Snicolas


There's a tool made by Facebook for comparing screenshots if that's what you're looking for: http://facebook.github.io/screenshot-tests-for-android/

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.

like image 29
Piotr Zawadzki Avatar answered Sep 19 '22 20:09

Piotr Zawadzki