Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Use UIAutomator to get system Screenshot #75

Closed
NitroG42 opened this issue Feb 18, 2016 · 6 comments
Closed

Use UIAutomator to get system Screenshot #75

NitroG42 opened this issue Feb 18, 2016 · 6 comments
Labels

Comments

@NitroG42
Copy link

Screengrab looks awesome, but there is just a little quirk, the systembar is not shown (except for the color), and also the button bar (of buttonless devices like nexus) are only a black rectangle.

I don't know if you have some ways to workaround that (like adding the bar manually using command like convert), but if you don't, you could use UIAutomator.

It provides a method takeScreenshot(File) from the class UIDevice that take a complete screenshot of the device, system bar and button bar included.

It requires a minSdk 18, but it's easy to work around that (using a product flavor, for example).

@amostyaev
Copy link

Great idea!

Also current implementation doesn't capture shadow below the toolbar. UiDevice.takeScreenshot(File) does that.

@trevor-e
Copy link

Yea, seems like screengrab doesn't capture shadows anywhere, like for CardView too. Maybe it would make sense to expose how screengrab creates the screenshot files? Right now they're all private static methods which I had to copy over to my project in order to use UiDevice.

@mfurtak
Copy link
Contributor

mfurtak commented Feb 25, 2016

Thanks for the reports and suggestions, all. This is definitely on our short list of things to address!

@simplysoft
Copy link

We had also to workaround the issue by coping some private code from the Screengrab file and the use UiAutomator to take the screenshot. In the end the actual screenshot method looks like this:

Bitmap bitmap = InstrumentationRegistry.getInstrumentation().getUiAutomation().takeScreenshot();

File file = screenshotFile(name);
OutputStream fos = null;
try {
    fos = new BufferedOutputStream(new FileOutputStream(file));
    bitmap.compress(Bitmap.CompressFormat.PNG, FULL_QUALITY, fos);
    Chmod.chmodPlusR(file);
} finally {
    bitmap.recycle();
    if (fos != null) {
        fos.close();
    }
}

while screenshotFile was taken from the Screengab file to match the convetion, this way the tool it will happily take the UiAutomator screenshot instead of the own ones:

private static File screenshotFile(String screenshotName) throws IOException {
        File screenshotDirectory = getFilesDirectory(InstrumentationRegistry.getTargetContext(), Locale.getDefault());
        String screenshotFileName = System.currentTimeMillis() + NAME_SEPARATOR + screenshotName + EXTENSION;
        return new File(screenshotDirectory, screenshotFileName);
    }

@VictorJava
Copy link

Hi,
I have the same problem.

I following suggestion simplysoft(previous message).
This works, but when I have DialogFragment and ProgressDialog in the same time - I cant capture ProgressDialog. It isnt visible on screen.
In another words. If I have two dialogs the top isn`t captured.

Could you help me?

@fastlanebot
Copy link

This issue was migrated to fastlane/fastlane#2080. Please post all further comments there.

fastlane is now a mono repo, you can read more about the change in our blog post. All tools are now available in the fastlane main repo 🚀

@fastlane-old fastlane-old locked and limited conversation to collaborators Mar 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants