screenshot-tests-for-android
screenshot-tests-for-android copied to clipboard
Add TextureView/SurfaceView support
We are working on adding screenshot testing to the Mapbox SDK Test App.
In order to try screenshot-tests-for-android I added a test (which takes a screenshot after a simple map gets loaded) in app-example-androidjunitrunner.
The problem is that I'm getting a screenshot with the part of the map transparent. Screenshot:

Examining the code I found you're not taking into account views like TextureView or SurfaceView (we use them to paint maps).
Trying to add this enhancement (firstly with TextureView) I added some changes and got same screenshot 😕

Funny thing is if I remove the drawClippedView() call, I get the screenshot with map properly painted but (obviously) the rest of the views not (e.g. Mapbox logo). Even clearer checking another screenshot generated from other test (whole screenshot is transparent).
Screenshot:

Any thoughts on how to fix this? Any info would help us adding this feature to the framework.
So, I'm not a TextureView/SurfaceView expert, but based on your description you seem to be on the right path, and I'd love to have the eventual fix pulled in.
In this particular case, it looks like the View is drawing over your TextureView, probably because you have a view behind the TextureView which in production will be drawn first, but in your code is drawn after the TextureView.. something like this
- BackgroundView
- TitleBar
- TextureView
- MapboxImage
The solution will be to draw the TextureView while drawing the rest of the views, which might be tricky (since it's the draw() that dispatches the draw() for the children). Perhaps a ScreenshotSafeTextureView that detects if it's running in a screenshot test and in which case just do the logic you showed inside of its onDraw() method?
Hey 👋 @tdrhq
Revisiting this one, the solution you suggested wasn't feasible because subclasses of TextureView cannot do their own rendering with the Canvas object so I opted to create both Bitmaps and do a simple merge.
How does that sound? Do you see any drawbacks?
It still remains adding a way to get a Bitmap from SurfaceViews, but at least TextureViews are unblocked.
Happy to know what you think about #71
Thanks a lot!