pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.75k stars 570 forks source link

Full Page Snapshot #271

Closed Sherlouk closed 4 years ago

Sherlouk commented 4 years ago

In iOS 13, Apple added a "Full Page" option when taking a screenshot of the device inside of a webview etc. I was wondering if there would be a way to do this same functionality but for any scroll view in the app? (and not limited to iOS 13)

Essentially this would scroll any UIScrollView, UITableView, UICollectionView, UIWebView, all of the NS equivalents and probably others I can't think of. We'd probably need to limit it to single axis only (but this should be configurable to either horizontal or vertical)

image

Proposed API would be to introduce a new scroll or scrolling parameter to the image strategy. This would accept an enum for none (no scrolling), vertical and horizontal.

assertSnapshot(matching: viewController, as: .image(on: .iPhone, scroll: .none)) // Default
assertSnapshot(matching: viewController, as: .image(on: .iPhone, scroll: .vertical))
assertSnapshot(matching: viewController, as: .image(on: .iPhone, scroll: .horizontal))
Sherlouk commented 4 years ago

While we shouldn't depend on a library like this - does look like the hard work has likely been done for us before:

https://github.com/davidman/DHSmartScreenshot https://github.com/st3fan/iphone-experiments/blob/master/Miscellaneous/ScrollViewScreenShot/Classes/ScreenShotViewController.m https://stackoverflow.com/a/40923897

etc

sunshinejr commented 4 years ago

@Sherlouk this would be awesome to get, did you by any chance start working on the solution?

Sherlouk commented 4 years ago

Hey @sunshinejr, I did take an early stab at it and had some positive results but never got around to "productionising" the code or doing extensive testing!

Still think it would be amazingly helpful though... might need to revisit it if no one else does!

stephencelis commented 4 years ago

This would definitely be cool! We're trying to close out old feature requests and ideas to keep the focus of issues on bugs. Hopefully GitHub Discussions will make it easier to discuss snapshot strategy ideas like this in the future soon! Thanks for the idea @Sherlouk!