How to open url in Safari and the get back to the app under UITests in Xcode 7?

后端 未结 2 628
时光说笑
时光说笑 2021-02-04 05:45

This is my custom view where \"LondonStreet\" is a button.

When I tap that button I get url and open it in Safari (it works). Then I can go back, u

2条回答
  •  别那么骄傲
    2021-02-04 05:51

    Starting in iOS 11 you can interact with other applications using the XCUIApplication(bundleIdentifier:) initializer.

    To get back to your app you'd do something like:

    let myApp = XCUIApplication(bundleIdentifier: "my.app.bundle.id")
    let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
    
    // Perform action in your app that opens Safari
    
    safari.wait(for: .runningForeground, timeout: 30)
    myApp.activate() // <--- Go back to your app
    

提交回复
热议问题