简体   繁体   中英

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.?

PS 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM