Skip to content

How do i snapshot test a scroll view? #264

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

Closed
bitwit opened this issue Oct 28, 2019 · 6 comments
Closed

How do i snapshot test a scroll view? #264

bitwit opened this issue Oct 28, 2019 · 6 comments

Comments

@bitwit
Copy link

bitwit commented Oct 28, 2019

I'm trying to write some snapshot tests around a UITableView and was attempting to scroll to snapshot the bottom of the table but no matter what I do the snapshot appears to ignore scoll position.

Originally i was snapshotting a view controller, but then tried snapshotting the tableview directly and got a fatal error warning me View not renderable to image at size ...

Am I taking the wrong approach to this or is there some way to snapshot a scrollable view to capture all its contents?

Thanks for the help. This library is a thing of beauty and I'm excited to finally be playing with it at work.

@bitwit
Copy link
Author

bitwit commented Oct 28, 2019

I think I have a solution so i will close this issue.

In case anyone else has the problem, I found that rendering to a custom image size configuration allowed me to get everything in a single image:

assertSnapshot(matching: vc, as: .image(on: .init(safeArea: .zero, size: .init(width: 480, height: 2000), traits: .init())))

@bitwit bitwit closed this as completed Oct 28, 2019
@stephencelis
Copy link
Member

Hi @bitwit! Yeah that's the solution we typically go with. Not quite sure where it might fit to document for others, but if you have any ideas please let us know!

@UrsKahmann
Copy link

UrsKahmann commented Jan 22, 2021

Hey @stephencelis and @bitwit , did you guys by any chance find a way to take a screenshot of scroll view, which is only as large as the content? The approach that @bitwit used (with setting a fixed size) works, but requires a good guess at how heigh the scroll view will be.

@bitwit
Copy link
Author

bitwit commented Jan 24, 2021

@UrsKahmann last time I checked there is no way to only capture a page's worth of content at a time. Typically I set the height a reasonable amount higher than I anticipate so there's some wiggle room, but it's not perfect.

@robinsalehjan
Copy link

robinsalehjan commented Mar 10, 2021

@bitwit Did you manage to get this working on Travis/CircleCI? The difference in width/height between the simulator and the snapshot results in a failure.

@bitwit
Copy link
Author

bitwit commented Mar 28, 2021

@robinsalehjan yes, this was functional on bitrise CI always. Not sure why you're getting a dimension difference if you set it manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants