Skip to content

Instantly share code, notes, and snippets.

View raxxpack's full-sized avatar

Rahim M raxxpack

View GitHub Profile
@raxxpack
raxxpack / confirmPurchase.swift
Created February 18, 2020 20:59
Confirm purchase with retry
extension XCUIApplication {
/// Confirms buying of a subscription purchase and retries once if the user is not authorized.
private func confirmBuyingOfSubscription(signInRequired: Bool = true,
account: AppStoreConnectService.AppStoreSandboxUser,
retryCount: Int,
_ block: () -> ()) {
block()
if signInRequired {
@raxxpack
raxxpack / recognizeAlert.swift
Created February 18, 2020 20:23
Recognize Alert
// Recognize alert
let springboardApp = XCUIApplication("com.apple.springboard")
let privacyAlert = springboardApp.alerts["App Store & Privacy"]
if privacyAlert.waitForExistence(timeout: 30) { ... }
@raxxpack
raxxpack / signOutOfiTunesSandboxAccount.swift
Created February 18, 2020 20:15
XCUIApplication Extension to signOutOfiTunesSandboxAccount
extension XCUIApplication {
/// Signs out the Sandbox account on the device if signed in.
/// Assumes user is in the Settings app.
func signOutOfiTunesSandboxAccount() {
#if !targetEnvironment(simulator)
// If running UI tests on simulator, don't go anything.
tables.element(boundBy: 0).waitForIt().cells.staticTexts["iTunes & App Store"].tap()
let detailsTable = oniPad ? tables.element(boundBy: 1).waitForIt() : tables.element(boundBy: 0).waitForIt()
detailsTable.swipeUp()
@raxxpack
raxxpack / launchSettingsApp.swift
Created February 18, 2020 20:08
XCUIApplication Extension - Launch Settings
extension XCUIApplication {
/// Launches the Settings app and verifies that the initial screen exists.
static func launchSettingsApp() -> XCUIApplication {
let app = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
// Launch, terminate and again launch the Settings app to ensure we are in a clean state.
app.launch()
app.terminate()
app.launch()
app.navigationBars["Settings"].waitForIt()
return app
@raxxpack
raxxpack / convenienceMethods.swift
Last active February 18, 2020 20:17
Convenience methods for XCUIElement
extension XCUIElement {
/// Asserts that the element exists within the time interval.
@discardableResult
func waitForIt(timeout: TimeInterval = 30) -> XCUIElement {
XCTAssertTrue(waitForExistence(timeout: timeout))
return self
}
/// Asserts that the element is hittable within the time interval.