ui testing - custom url scheme

Hi,


I was wondering how we can test opening a custom url within an XCTestCase while performing UI testing. I am trying:


// this custom url is registered within the application

let customURL = NSURL(string: "foo://localhost/doSomething"
let sharedApp = UIApplication.sharedApplication()

let fileURL = // an NSURL file path
UIPasteboard.generalPasteboard().setValue(fileURL, forPasteboardType: "com.foo")


XCTAssert(sharedApp.canOpenURL(customURL!), "cannot open url") // this passes
let status = sharedApp.openURL(customURL!)
XCTAssert(status, "did not open url") // this does NOT pass


canOpenURL passes, but openURL does not succeed. Furthermore, the openURL delegate method in my application is never called.


In the above snippet, I am also pasting a URL to the paste board because I am trying to open this test data file which was why I decided to try this with a custom URL.


Any one have any ideas? Am I not approaching this correctly? I was trying to use an .xcappdata file but since that file loads in the testing unit instead of the application being tested, I'm not sure how to place it within the data directory of the real app.


Thanks,

Jaime

This will probably never work as the UI tests are different target (process), hence cannot access your UIApplication.sharedApplication()

There should be some way to open URLs like what's proposed here. That there currently isn't is a known issue.

Did you ever find a way to do this? I'm also looking for a way to test custom URL scheme handling on app launch.

ui testing - custom url scheme
 
 
Q