Skip to content
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

Timeouts on WKWebView image snapshot #126

Closed
kaqu opened this issue Dec 5, 2018 · 10 comments
Closed

Timeouts on WKWebView image snapshot #126

kaqu opened this issue Dec 5, 2018 · 10 comments

Comments

@kaqu
Copy link

kaqu commented Dec 5, 2018

Hi, one more issue from me 😇 It looks like WKWebView is never performing image snapshot when there is no content loaded. I have the case where one of my views contains WKWebView that have no content initially. If I've debugged that correctly image snapshot on web view waits until the page finishes loading. But when there is no page loading it never occurs resulting in a timeout.
I am wondering if making it possible to take a snapshot when there is no content in web view is a good solution here.
Workaround for this is to load any file from disk into, even empty one.

@stephencelis
Copy link
Member

Ah, good point, embedded web views shouldn’t time out if possible. Will look into this soon! Thanks for so thoroughly testing things 🙌

@kaqu
Copy link
Author

kaqu commented Dec 5, 2018

Applications I am covering now with snapshot tests (fortunately) have a lot of weird things 😅

@stephencelis
Copy link
Member

@kaqu I can't seem to reproduce this failure. WKWebView snapshots should only time out if the web view thinks that it isLoading. As long as the web view is not actively loading content, it should render a blank screen. Any chance you can produce a failing test case for us?

@kaqu
Copy link
Author

kaqu commented Dec 5, 2018

Ok, I will try to reproduce it outside or find if there is some other case here.

@kaqu
Copy link
Author

kaqu commented Dec 5, 2018

This makes timeout:

func testWebView() {
        class VC: UIViewController {
            override func loadView() {
                let browser: WKWebView = .init()
                view = browser
                browser.load(URLRequest(url: URL(string: "url")!))
            }
        }
        let vc = VC()
        vc.view.frame = .init(x: 0, y: 0, width: 200, height: 200)
        assertSnapshot(matching: vc, as: .image)
    }

It turns out that it was loading url, but it was kind of invalid.

@kaqu
Copy link
Author

kaqu commented Dec 5, 2018

I am wondering if loading other valid URL like base64 data which is accepted by browsers will behave similarly.

@stephencelis
Copy link
Member

Ah. I think it’s kind of correct to fail in this case. Any way to modify your code to avoid the loading for the test? Or to load a valid HTML string instead?

@stephencelis
Copy link
Member

(Up for other suggestions, too! We just want to wait for loading web pages to load.)

@kaqu
Copy link
Author

kaqu commented Dec 5, 2018

Thanks for help though, sorry for incomplete debug 🙂 I agree that timeout in that case is good (loading base64 data seems to work correctly)

@stephencelis
Copy link
Member

Going to close this issue and track the improvement here #136.

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

2 participants