Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture screenshots from the Android device during integration tests #104

Merged
merged 1 commit into from
Feb 22, 2012

Conversation

rtyley
Copy link
Contributor

@rtyley rtyley commented Feb 22, 2012

ddmlib supports capturing screenshots from your Android device, which is awesome, and this commit adds support for capturing select screenshots while running your integration tests- ie robotium-style tests that drive your app - and additionally creates an animated gif of the resulting sequence, which can be pushed to your chatroom on every build to give a quick visual assessment of the state of the app.

Handling the scheduling of the screenshots is tricky, and to this end I've created a small framework to address issues around taking screenshots with ddmlib:

  • ddmlib image capture is slow, around 600ms+ per image
  • if the device screen is updating, the captured image is likely to show
    a partially-updated framebuffer
  • ddmlib is invoked on the development environment side of your setup
    (ie your machine executing the Maven build) - your app code can't
    easily take screenshots itself, but in order to get best screenshot
    results your device screen should not be changing when the screenshot
    is taken

The android-screenshot framework addresses these issues:

https://github.com/rtyley/android-screenshot-lib

Your development environment runs an OnDemandScreenshotService, using ddmlib to listen for log messages tagged screenshot_request. Your app integration test code just writes one of these log messages when it wants a screenshot taken, and the service obliges by capturing an image from the device. To get the best results, your tests should then pause for a second so that the screenshot is of a static screen. That simple operation is wrapped up for convenience in the Screenshots class packaged into the android-screenshot-celebrity artifact - but you don't have to use it, if you want to write the log-and-sleeping statements yourself.

For the android-maven-plugin, the screenshots are written to the 'screenshots' folder under the target folder. They are organised into subfolders based on the friendly device name, so you can get a snapshot of how your app looks across several different devices very easily by just running it on a multi-device build - obviously that works with the emulator too.

ddmlib supports capturing screenshots from your Android device, which is
awesome, and this commit adds support for capturing select screenshots
while running your integration tests- ie robotium-style tests that
drive your app -and additionally creates an animated gif of the
resulting sequence, which for example can be pushed to your chatroom on
every build to give a quick visual assessment of the state of the app.

Handling the scheduling of the screenshots is tricky, and to this end
I've created a small framework to address issues around taking
screenshots with ddmlib:

* ddmlib image capture is slow, around 600ms+ per image
* if the device screen is updating, the captured image is likely to show
  a partially-updated framebuffer
* ddmlib is invoked on the development environment side of your setup
  (ie your machine executing the Maven build) - your app code can't
  easily take screenshots itself, but in order to get best screenshot
  results your device screen should not be changing when the screenshot
  is taken

The android-screenshot framework addresses these issues:

https://github.com/rtyley/android-screenshot-lib

Your development environment runs an OnDemandScreenshotService, using
ddmlib to listen for log messages tagged 'screenshot_request'. Your app
integration test code just writes one of these log messages when it wants
a screenshot taken, and the service obliges by capturing an image from
the device. To get the best results, your tests should then pause for a
second so that the screenshot is of a static screen. That simple
operation is wrapped up for convenience in this class (but you don't
have to use it):

https://github.com/rtyley/android-screenshot-lib/blob/master/celebrity/src/main/java/com/github/rtyley/android/screenshot/celebrity/Screenshots.java

For the android-maven-plugin, the screenshots are written to the
'screenshots' folder under the target folder. They are organised into
subfolders based on the friendly device name, so you can get a snapshot
of how your app looks across several different devices very easily
by just running it on a multi-device build - obviously that works with
the emulator too.
@mosabua
Copy link
Member

mosabua commented Feb 22, 2012

Wow... that is awesome! Just rocking! My one request would be to switch this feature off by default and add a config parameter to activate it. Otherwise you would potentially use up LOTS of diskspace..

Ok...I read the documentation better now. Since the screenshots are on request I think it is totally fine as is. My main request would be to add the documentation from above somewhere as javadoc so it becomes visible as documentation on the generated maven site and potentially also add it on the wiki. It would also be good to enhance e.g. the morseflash example to take screenshots as an example for usage. But that is all sugar... this works as is so I am pulling it in!

mosabua added a commit that referenced this pull request Feb 22, 2012
Capture screenshots from the Android device during integration tests
@mosabua mosabua merged commit b5cb41d into simpligility:master Feb 22, 2012
@rtyley
Copy link
Contributor Author

rtyley commented Feb 22, 2012

Fantastic :) thanks man, I'm glad you like it

@mosabua
Copy link
Member

mosabua commented Feb 22, 2012

The CI builds passed just fine. We will have to sort out documentation somehow.. easiest might be to wire it into the morseflash example.

@rtyley
Copy link
Contributor Author

rtyley commented Feb 22, 2012

Awesome - I'm trying to get on top of the documentation (I know it needs it!), just a little swamped right now, but should be able to get something in by tomorrow

@mosabua
Copy link
Member

mosabua commented Feb 22, 2012

not stress.. there are lots of other pull request that I had to keep waiting for a few weeks since they need some work... I am a bit swamped..

@amorenew
Copy link

how to use this with gradle ?

@william-ferguson-au
Copy link
Contributor

The same way you would use any other maven mojo from gradle.

@amorenew
Copy link

i don't understand how to make this:
"Your development environment runs an OnDemandScreenshotService, using ddmlib to listen for log messages tagged screenshot_request"

@mosabua
Copy link
Member

mosabua commented Feb 24, 2015

If you need to do screenshot capturing with Gradle... you need to ask on a Gradle list or so @amorenew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants