How to open URL in Safari and return to the app under UITests in Xcode 7?

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

enter image description here

When I click this button, I get the URL and open it in Safari (it works). Then I can return using the "Back to Wishlist" button (it also works).

enter image description here

The problem is that I am trying to verify this in UITests.

 itemsTable.cells.elementBoundByIndex(0).buttons["addressButton"].tap() //press the button to open link in Safari 

Along with this line:

 app.statusBars.buttons["Back to Wishlist"].tap() //go back, doesn't work, although it was recorded by Xcode itself. 

- error:

User Interface Testing Error - Failed to get screenshot for 5 seconds.

And also in the Navigator problem

User Interface Test Error - Unable to quickly update application state.

enter image description here

+3
source share
2 answers

User Interface Testing cannot interact with anything outside of your application. In your scenario, the infrastructure will no longer be able to do anything once your application opens Safari.

To verify this, try printing out the application hierarchy after opening Safari. You will notice that nothing appears in Safari and the navigation bar - you will see information about your application.

 print(XCUIApplication().debugDescription) 
+7
source

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

To return to your application, you would 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 
+6
source

All Articles