Skip to content

Instantly share code, notes, and snippets.

@fuxx
Created June 7, 2017 08:49
Show Gist options
  • Save fuxx/0c47bf64d093646a64d65ea457755578 to your computer and use it in GitHub Desktop.
Save fuxx/0c47bf64d093646a64d65ea457755578 to your computer and use it in GitHub Desktop.
import Foundation
import XCTest
enum Safari {
static func launch() -> XCUIApplication {
// Open safariapp
let safariApp = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.mobilesafari")
// Launch safari app
safariApp.launch()
// Wait some seconds for launch
sleep(2)
// Return application handle
return safariApp
}
static func open(URLString urlString: String, inSafariApp app: XCUIApplication) {
// Find URL bar
app.otherElements["URL"].tap()
// Tap URL bar
app.textFields["Suchbegriff oder Website"].exists ? app.textFields["Suchbegriff oder Website"].tap() : app.textFields["Search or enter website name"].tap()
// Enter the URL string
app.typeText(urlString)
// Simulator keyboard is english, on the device we use german
app.buttons["Öffnen"].exists ? app.buttons["Öffnen"].tap() : app.buttons["Go"].tap()
}
}
protocol SafariLaunchable {
var safariApp: XCUIApplication { get }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment