Created
June 7, 2017 08:51
-
-
Save fuxx/b9a67a86928b65b5a5fdedf6a75de21e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SafariTestsBaseClass.swift | |
// C24Core | |
// | |
// Created by Stefan Mayer-Popp on 24.05.16. | |
// Copyright © 2016 CocoaPods. All rights reserved. | |
// | |
import Foundation | |
import XCTest | |
class SafariTestsBaseClass: XCTestCase, AppMenuTestable, SafariLaunchable { | |
/// The CHECK24 app | |
let app = XCUIApplication() | |
/// A launched Safari.app instance | |
var safariApp: XCUIApplication = Safari.launch() | |
/// CHECK24 app link test site URL | |
var appLinkTestURLString: String { | |
return "https://xxx.check24.de/xxx.html" | |
} | |
/// Name of the open button for an opening AppLink | |
var safariAlertOpenButton: XCUIElement { | |
return safariApp.buttons["Öffnen"] | |
} | |
/** | |
Launches the app. | |
Resets data if set to tru | |
- parameter reset: Set to true if app data should be deleted | |
*/ | |
func launchApp(arguments: [LaunchArgumentRepresentable]? = nil) { | |
// Clean arguments | |
app.launchArguments.removeAll() | |
// append arguments if they are provided | |
if let arguments = arguments { | |
app.launchArguments.appendContentsOf(arguments.map { return $0.rawValue }) | |
} | |
// We dont want to see the onboarding or push notification alert, or a logged in user | |
app.launchArguments.append(LaunchOptionArgument.AppRate.SuppressAppRateDialog.rawValue) | |
app.launchArguments.append(LaunchOptionArgument.PushNotification.SuppressPushNotificationDialog.rawValue) | |
app.launchArguments.append(LaunchOptionArgument.User.LogoutUser.rawValue) | |
// Launch app | |
app.launch() | |
} | |
override func setUp() { | |
super.setUp() | |
continueAfterFailure = false | |
} | |
override func tearDown() { | |
super.tearDown() | |
// Terminate app and safari after each test | |
app.terminate() | |
safariApp.terminate() | |
} | |
/** | |
Opens the app link test site | |
*/ | |
func openAppLinkTestSite() { | |
safariApp = Safari.launch() | |
Safari.open(URLString: appLinkTestURLString, inSafariApp: safariApp) | |
} | |
/** | |
Opens a given URL on the app link test site | |
- parameter urlString: The url to open | |
*/ | |
func openCustomAppLink(forURLString urlString: String) { | |
/// The app link test site as element on the app link test site | |
var testURLLinkElement: XCUIElement { | |
return safariApp.links[urlString] | |
} | |
// Open test site | |
openAppLinkTestSite() | |
// Tap on custom link text field | |
safariApp.staticTexts["Customlink"].tap() | |
// Type url | |
safariApp.typeText(urlString) | |
// Long touch to open activity list | |
expect(.Exists, object: testURLLinkElement, timeout: 4).pressForDuration(1.0) | |
// Enter custom link url | |
safariApp.sheets[urlString].collectionViews.buttons.containingPredicate(NSPredicate(format: "label CONTAINS[C] 'Holding Alpha'")).element.tap() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment