如何在Safari中打开url,并在Xcode 7中的UITests下返回到应用程序? [英] How to open url in Safari and the get back to the app under UITests in Xcode 7?
问题描述
这是我的自定义视图,其中"LondonStreet"
是一个按钮.
This is my custom view where "LondonStreet"
is a button.
当我点击该按钮时,我会得到url并在Safari中打开它(它有效).然后,我可以使用"Back to Wishlist"
按钮返回它(也可以使用).
When I tap that button I get url and open it in Safari (it works). Then I can go back, using "Back to Wishlist"
button (it also works).
问题是当我尝试在UITests下进行测试时.
The problem is when I try to test this under UITests.
itemsTable.cells.elementBoundByIndex(0).buttons["addressButton"].tap() //press the button to open link in Safari
沿这行:
app.statusBars.buttons["Back to Wishlist"].tap() //go back, doesn't work, although it was recorded by Xcode itself.
是错误:
UI测试失败-无法在5秒内获取屏幕截图.
UI Testing Failure - Failed to get screenshot within 5s.
以及 issue Navigator
UI测试失败-无法及时更新应用程序状态.
UI Testing failure - Unable to update application state promptly.
推荐答案
从iOS 11开始,您可以使用XCUIApplication(bundleIdentifier :)初始化程序与其他应用程序进行交互.
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
这篇关于如何在Safari中打开url,并在Xcode 7中的UITests下返回到应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!