Now I'm writing the unit tests. There is a problem to test the WKWebView. Do you know how to execute the navigationDelegate methods. I have tried like this, but it crashed. Could you please help me? Thanks in advance. let wkNavigation = WKNavigation() let error = NSError() vc.wkWebView?.navigationDelegate?.webView!(vc.wkWebView!, didFail: wkNavigation, withError: error)
How to test WKWebview
I have tried like this, but it crashed.
That’s kinda vague. Which line specifically crashed? And what did the crash look like?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
The crash is bellow.
Thread 1: EXC_BAD_ACCESS(code=1,address=0x0)
The crash is bellow.
Below what?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
[For those reading along at home, the above conversation is a little confusing because leaf1 edited their post to fix the problem I was concerned with.]
That’s not what I was looking for, alas. Rather, I was wondering where this crash occurred in your source code (specifically with reference to the three statements you showed in your original post).
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
func testWKNavigation() {
_ = WKNavigation()
}
This is enough to get the crash: Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
You need to declare your instance of WKNavigation in a scope that out lives the scope of the test function itself. This will work, though:
Code Block swift class MyTestCase: XCTestCase { let navigation = WKNavigation() func testDelegate() { // some assertions delegate.webView(webView, didFail: navigation, withError: error) // some assertions } }