Skip to content

Instantly share code, notes, and snippets.

@oliverepper
Created September 1, 2022 10:56
Show Gist options
  • Save oliverepper/52ba996ae78d237bedea3f717876e933 to your computer and use it in GitHub Desktop.
Save oliverepper/52ba996ae78d237bedea3f717876e933 to your computer and use it in GitHub Desktop.
//
// BikeRRUITests.swift
// BikeRRUITests
//
// Created by Oliver Epper on 14.08.21.
//
// swiftlint:disable all
import XCTest
class BikeRRUITests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
addUIInterruptionMonitor(withDescription: "Motion permission") { element -> Bool in
if element.elementType == .alert {
var btn: XCUIElement?
if element.staticTexts["To enable automatic recording of your trips BikeRR needs permanent access to your location information."].exists ||
element.staticTexts["Um deine Fahrten automatisch aufzeichnen zu können braucht BikeRR permanenten Zugriff auf deine Ortsinformationen."].exists {
// location -> press 0 btn
btn = element.buttons.element(boundBy: 1)
}
if element.staticTexts["To automatically stop your trips BikeRR needs access to your activity information."].exists ||
element.staticTexts["Um deine Fahrten automatisch stoppen zu können braucht BikeRR Zugriff auf deine Aktivitäten."].exists {
// motion -> press 1 btn
btn = element.buttons.element(boundBy: 1)
}
if let _ = btn?.exists {
btn?.tap()
return true
}
}
return false
}
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testForScreenshots() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
setupSnapshot(app)
app.launch()
snapshot("01_welcome")
app.buttons.element(boundBy: 0).tap()
snapshot("02_automatic")
app.buttons.element(boundBy: 1).tap()
snapshot("03_manual")
app.buttons.element(boundBy: 1).tap()
snapshot("04_permissions")
app.buttons.element(boundBy: 1).tap()
snapshot("05_selection")
app.buttons.element(boundBy: 1).tap()
wait(for: 25)
snapshot("06_status")
let tabBar = app.tabBars.element(boundBy: 0)
tabBar.buttons.element(boundBy: 1).tap()
wait(for: 5)
snapshot("07_map")
tabBar.buttons.element(boundBy: 3).tap()
snapshot("09_settings")
tabBar.buttons.element(boundBy: 2).tap()
wait(for: 50)
snapshot("08_trips")
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
// func testLaunchPerformance() throws {
// if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// // This measures how long it takes to launch your application.
// measure(metrics: [XCTApplicationLaunchMetric()]) {
// XCUIApplication().launch()
// }
// }
// }
}
extension XCTestCase {
func wait(for duration: TimeInterval) {
let waitExpectation = expectation(description: "Waiting")
let when = DispatchTime.now() + duration
DispatchQueue.main.asyncAfter(deadline: when) {
waitExpectation.fulfill()
}
// We use a buffer here to avoid flakiness with Timer on CI
waitForExpectations(timeout: duration + 0.5)
}
}
// swiftlint:enable all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment