Slide 28
Slide 28 text
import XCTest
struct Launcher {
var viewControllerName: String
var userInfo: [AnyHashable: Any]?
init(viewControllerName: String, userInfo: [AnyHashable: Any]? = nil) {
self.viewControllerName = viewControllerName
self.userInfo = userInfo
}
var env: [String: String] {
var result: [String: String] = [LaunchKeys.viewController: self.viewControllerName]
if let userInfo: [AnyHashable: Any] = self.userInfo {
if let data: Data = try? JSONSerialization.data(withJSONObject: userInfo, options: []),
let userInfoString: String = String(data: data, encoding: .utf8) {
result[LaunchKeys.userInfo] = userInfoString
}
}
return result
}
func launch() -> XCUIApplication {
let app: XCUIApplication = XCUIApplication()
app.launchEnvironment = env
app.launch()
return app
}
}
28