-
Notifications
You must be signed in to change notification settings - Fork 476
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
Use Better Screenshot Means #4
Comments
Root detection added in |
Alternatively, try to use this: http://code.google.com/p/android-screenshot-library/ then we wouldn't need root! |
Just thinking out loud: Would it be possible to take the screenshots via ddms? Somehow the instrumenation app would need to send a command up to the runner, so it could invoke IDevice.getScreenshot. |
The test would also have to block until the screenshot was taken which is the harder problem. |
I managed to get DDMS take screenshots. Tests are also blocking until the screenshot is taken. I hooked up android-screenshot-lib (not the same as the one on google code). Basically it listens for logs with a special tag. To get the test to block, a file will be created on the device which gets deleted via adb. As soon as the file is gone the test continues. Root is obviously not needed on the device. I didn't request a pull yet, because it's not fully tested yet (+I didn't write tests) and there is still one issue: screenshots appear to be duplicated in the resulting report. But I didn't find the cause yet. Also the screenshots are not rotated with respect to the current device orientation, but I actually don't mind that. May I ask for a review? See my screenshot-ddms branch |
@panzerfahrer We explicitly avoided going that route since it's very fragile and the blocking is awkward. You may have noticed that the library is where we stole the animated GIF creation from, however. One way we were going to approach it was to start a web server on the desktop and use adb to port forward it to all of the devices. This way the The other would be to use a native service deployed via adb on test run which allows taking full screen captures on the device and then pulling at the end in the normal fashion. For something like what you describe to be added we definitely would need things like proper orientation support. I'll try to take a look at what you have tonight. |
I am following this issue as I would like to see dialogs in the screenshots. I am using Robotium in addition to Spoon, when I used their solo.takeScreenshot method it captured the dialog fine. However, it just captured the view for the dialog and not the entire screen. You probably don't like that approach as it would mess up the animated gif. |
Correct. We also don't want to depend on Robotium! We'll likely go the route of starting a native service over ADB and use it to take screenshots of the entire screen (including the status bar and soft buttons, woot). |
Started work on the AOSP has two on-device binaries for capturing the framebuffer We also need an effective way of not starting duplicate servers and killing the server once execution has completed. A simple PID file should suffice. I don't have the time to work on this now. Maybe in 4-6 weeks. |
After my first attempt with the quirky "lock file" approach, I tried it with running a server on the device. I'm starting a server within the InstrumentationTestRunner. spoon-runner houses a client which connects to the server via an ADB port forwarding. I'm not using a native service, but plain Java socket channels. Unfortunately, it's not really working and I couldn't yet figure out what I'm missing. Anyhow, maybe it can be of help. I had to postpone my work on this, so I'm not sure when can get a look into it again. |
@panzerfahrer That's the route we initially wanted to go as well. Haven't really had time to explore it. If I get back around to work on it before you do I will definitely take a look. Thanks! |
New in 4.3 eh? |
Has there been any progress on the issue of not being able to see dialogs in screenshots? |
No. Free time is fleeting nowadays. |
But we do accept pull requests. |
Thanks for the reply! No problem I understand. We're looking to get it working for a project at work so I'll see if I can get the time to fix this. Looking at the code inside the takeScreenshot method of Robotium it seems at first glance like a more sophisticated version of what you use in Spoon. Would it be ok if we tried to port their stuff over into Spoon? There wouldn't be any dependency, I'd just move their code over to spoon. |
You mean the gross, grab-all-the-windows-with-reflection-and-render-them-in-reverse method? I suppose there's worse things... go for it. |
Pretty much. The goal for us to to have screenshots which show things like dialogs as well as the foreground activity. Ideally we'd just use the UIAutomation class but we'd like it to work on older devices too. I'll take a look and see what I can do with it. |
Here is some code that I wrote. I have a higher level automation api which encapsulates both Spoon and Robotium. I should probably do a pull request. Two methods for taking screenshots:
First one will call Spoon's method. Second flavor calls the ScreenshotTaker class below. You can see that I put the screenshots in the same folder as Spoon, and I use the same convention for naming the files. This way when the test is run, Spoon pulls the screenshots taken by both methods.
ScreenshotTaker class which has pretty much the same code as what Robotium uses... import android.graphics.Bitmap; import java.io.File; import static com.evernote.test.framework.TestLogger.logTestError; public class ScreenshotTaker {
} |
Any plans for "UiAutomation.html#takeScreenshot()" support ( with fallback for older API versions )? Also, it would be great if there was a Spoon.logImage(String tag, Bitmap bitmap) which puts any bitmap in the Spoon report. This could be used for testing a standalone custom view and for snapshot Animations in progress. |
Just tried quickly hacking in takeScreenshot support. Took about 5 minutes, but it turns out takeScreenshot occasionally (and for no reason I can predict..) returns null. (We had a fun issue where our tests would fail due to a "please update your google play services version" dialog. All our screenshots looked perfect, but when we ran without headless mode we could spot the huge dialog over the entire screen :P ) |
Better than the decorview on devices that supports it atleast. |
Caution, UiAutomation.html#takeScreenshot() is flaky and can sometimes cause issues with OpenGL memory allocations... We have had cases where it causes other apps to crash ( like the launcher ), presumably because it is triggering system wide issues with OpenGL memory allocations. |
|
There's other means of taking a screenshot like |
We use the UiAutomation.takeScreenshot() method for our tests without problems. Not sure what you guys have different, but it never returned null or crashed the app for us. We use it in different real devices and we have something like 50+ test cases. |
@RichardGuion Thank you for your help ! It's working for me 👍 |
I just tried out this library, and it works like a charm with dialogs. |
It just loops over all the windows like Robotium and smashes them together. On Sat, Mar 19, 2016, 8:56 AM Richard Radics [email protected]
|
I am using UiAutomation.takeScreenshot() without any issues.. with spoon 1.7.1 don't like the fact that I have to click on a link in the report.... |
I use both Spoon library and Falcon library and it works well. And use this code to capture dialog: |
...to get awesome full-screen screenshots.
Socket to the host which captures using normal means through ddmlib. Could be a simple REST API or just dumb text communication. Client would block until a response was received. Fall back to decor view.
The text was updated successfully, but these errors were encountered: