-
Notifications
You must be signed in to change notification settings - Fork 252
Cannot get a correct screenshot from a view that overrides drawRect #20
Comments
Does it work with #19 ? |
It does not work with #19. I get: I expect something more like: |
@dblock can you post the actual and expected images when you use master? |
I suspect animation is involved in setting up the view. |
@dstnbrkr They are above (the red dots aren't in the same place because the view centers itself after painting). I have waited for animation for many seconds, the view paints still only after the test finishes. Something is holding it. |
Is the waiting happening on the main thread? That would prevent the animation from completing. |
I'd recommend rendering the view on a background thread, then when that background task completes - take the snapshot. That would prevent the actual test running on the main thread from blocking the animation, which also happens on the main thread. |
This wasn't working because the view believed it was off-screen. Adding a dummy window fixed the issue, the code is here. If you think that ios-snapshot-test-case should do something to detect this kind of scenario (after-all views actually repaint explicitly whether they are visible or not), lets leave this open. Otherwise feel free to close. |
I'd say the fact that the test fails in that case is sufficient detection ;-) Testing views via controllers might be prone to this kind of error. Can probably avoid by testing the view in isolation and doing set up in the test (or moving the view setup into another view object and let the controller load that view). |
I am not sure what the deal is, but a view with custom drawing is not screen-shotted properly. There's a test in https://github.com/dblock/NAMapKit/blob/tiled-map-view/Demo/DemoTests/NATiledImageMapViewControllerTests.m#L24 that reproduces this.
The text was updated successfully, but these errors were encountered: