Nokhbeh
Nokhbeh

Reputation: 11

How can I get a snapshot of the foreground Android activity (in my own application) programmatically?

I am writing a JUnit test for an Android application. I'd like to take snapshots of the application under test programmatically through the JUnit test. I've searched for days and it seems like my best shot is to follow How to programmatically take a screenshot in Android?.

The problem is I traverse the application under test by clicking buttons, etc. and by doing so I bring up different activities in the application under test. I can use getActivity to get and render the starting activity, but how can I get the activity instances that come up by clicking buttons, etc.?

P.S. ActivityManager.RunningTaskInfo does not do since it only gives me the activity names and not their instances.

Also, I don't want to manipulate the application under test in anyway.

Upvotes: 1

Views: 504

Answers (1)

s.d
s.d

Reputation: 29436

Here's a good library for capturing screen-shots during tests:

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

Just call poseForScreenshot() in your test code.

Upvotes: 1

Related Questions