lundi 8 mars 2021

UITesting: Opening a file in app bundle from Safari

I've written some XCUITests to verify deeplink handling logic in my app. I have a set of links in an html file that's part of the Resources bundle for my tests. I use let path = Bundle(for: Self.self).path(forResource: deeplinkFileName, ofType: "html") to find the full path to the file and

        let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
        safari.launch()
        guard safari.wait(for: .runningForeground, timeout: 5) else {
            throw DeeplinkError.safariAppLoadTimeout
        }
        
        safari.descendants(matching: .button)["URL"].tap()
        safari.typeText(path)
        safari.buttons["Go"].tap()

to launch Safari, type the path in the address bar, and open the file.

This works great on Simulator, but when I run my test suite on a physical device, Safari times out trying to open the file. I assume this is because it doesn't have access to open a file inside my app bundle.

Is there a location to which I could move this file, so that Safari can access it? If I understand it correctly, even the Documents directory is still inside the app sandbox and can't be accessed from outside the app.

Aucun commentaire:

Enregistrer un commentaire