Open Safari and come Back with XCUITest
2 min readAug 20, 2023
During the development of the Siwonschool app, I made note of new insights I gained about XCUITest. I intend to revise and share these insights one by one.
How can I open Safari app with iOS Testing?
To launch another app, you must create a new instance of XCUIApplication
. The bundle identifier for Safari is com.apple.mobilesafari.
let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
safari.launch()
But how can I know if Safari has been launched successfully?
This piece of code waits until Safari is running in the foreground.
safari.wait(for: .runningForeground, timeout: 30)
I can now verify whether Safari has launched.
however how can I return to my app to run another test?.
The activate
method allows me to navigate back to my app and proceed with additional tests.
myApp.activate()
Troublesooting
Library not loaded: @rpath/Alamofire.framework/Alamofire
target 'talktrans' do
use_frameworks! #<-- remove this
The Swift pod `FirebaseCoreInternal` depends upon `GoogleUtilities`, which does not define modules
target 'talktrans' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
...
target 'talktransUITests' do # <-- move this
# use_modular_headers!
inherit! :search_paths
# Pods for testing
end
end
# to here