167 lines
5.8 KiB
Swift
167 lines
5.8 KiB
Swift
//
|
|
// CableUITestsScreenshotLaunchTests.swift
|
|
// CableUITestsScreenshot
|
|
//
|
|
// Created by Stefan Lange-Hegermann on 06.10.25.
|
|
//
|
|
|
|
import XCTest
|
|
|
|
final class CableUITestsScreenshotLaunchTests: XCTestCase {
|
|
private func launchApp(arguments: [String] = []) -> XCUIApplication {
|
|
let app = XCUIApplication()
|
|
var launchArguments = ["--uitest-reset-data"]
|
|
launchArguments.append(contentsOf: arguments)
|
|
app.launchArguments = launchArguments
|
|
app.launch()
|
|
return app
|
|
}
|
|
|
|
private func resolvedSystemsList(in app: XCUIApplication) -> XCUIElement {
|
|
let collection = app.collectionViews["systems-list"]
|
|
if collection.waitForExistence(timeout: 6) {
|
|
return collection
|
|
}
|
|
|
|
let table = app.tables["systems-list"]
|
|
XCTAssertTrue(table.waitForExistence(timeout: 6))
|
|
return table
|
|
}
|
|
|
|
private func resolvedLoadsList(in app: XCUIApplication) -> XCUIElement {
|
|
let collection = app.collectionViews["loads-list"]
|
|
if collection.waitForExistence(timeout: 6) {
|
|
return collection
|
|
}
|
|
|
|
let table = app.tables["loads-list"]
|
|
XCTAssertTrue(table.waitForExistence(timeout: 6))
|
|
return table
|
|
}
|
|
|
|
|
|
private func takeScreenshot(name: String,
|
|
lifetime: XCTAttachment.Lifetime = .keepAlways) {
|
|
let screenshot = XCUIScreen.main.screenshot()
|
|
let attachment = XCTAttachment(screenshot: screenshot)
|
|
attachment.name = name
|
|
attachment.lifetime = lifetime
|
|
add(attachment)
|
|
}
|
|
|
|
override class var runsForEachTargetApplicationUIConfiguration: Bool {
|
|
false
|
|
}
|
|
|
|
override func setUpWithError() throws {
|
|
continueAfterFailure = false
|
|
}
|
|
|
|
|
|
@MainActor
|
|
func testOnboardingLoadsView() throws {
|
|
let app = launchApp(arguments: ["--uitest-reset-data"])
|
|
takeScreenshot(name: "01-OnboardingSystemsView")
|
|
|
|
let createSystemButton = app.buttons["create-system-button"]
|
|
XCTAssertTrue(createSystemButton.waitForExistence(timeout: 5))
|
|
createSystemButton.tap()
|
|
takeScreenshot(name: "02-OnboardingLoadsView")
|
|
|
|
let componentsTab = app.buttons["components-tab"]
|
|
XCTAssertTrue(componentsTab.waitForExistence(timeout: 3))
|
|
componentsTab.tap()
|
|
|
|
let libraryCloseButton = app.buttons["library-view-close-button"]
|
|
let browseLibraryButton = onboardingSecondaryButton(in: app)
|
|
XCTAssertTrue(browseLibraryButton.waitForExistence(timeout: 5))
|
|
browseLibraryButton.tap()
|
|
XCTAssertTrue(libraryCloseButton.waitForExistence(timeout: 5))
|
|
Thread.sleep(forTimeInterval: 10)
|
|
takeScreenshot(name: "04-ComponentSelectorView")
|
|
libraryCloseButton.tap()
|
|
|
|
let createComponentButton = onboardingPrimaryButton(in: app)
|
|
XCTAssertTrue(createComponentButton.waitForExistence(timeout: 5))
|
|
createComponentButton.tap()
|
|
takeScreenshot(name: "03-LoadEditorView")
|
|
}
|
|
|
|
func testWithSampleData() throws {
|
|
let app = launchApp(arguments: ["--uitest-sample-data"])
|
|
|
|
let systemsList = resolvedSystemsList(in: app)
|
|
|
|
let firstSystemCell = systemsList.cells.element(boundBy: 0)
|
|
XCTAssertTrue(firstSystemCell.waitForExistence(timeout: 3))
|
|
let systemName = firstSystemCell.staticTexts.firstMatch.label
|
|
|
|
takeScreenshot(name: "05-SystemsWithSampleData")
|
|
|
|
let rowButton = firstSystemCell.buttons.firstMatch
|
|
if rowButton.waitForExistence(timeout: 2) {
|
|
rowButton.tap()
|
|
} else {
|
|
firstSystemCell.tap()
|
|
}
|
|
|
|
let navButton = app.navigationBars.buttons[systemName]
|
|
if !navButton.waitForExistence(timeout: 3) {
|
|
let coordinate = firstSystemCell.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
|
|
coordinate.tap()
|
|
XCTAssertTrue(navButton.waitForExistence(timeout: 3))
|
|
}
|
|
|
|
tapComponentsTab(in: app)
|
|
|
|
let loadsElement = resolvedLoadsList(in: app)
|
|
XCTAssertTrue(loadsElement.waitForExistence(timeout: 6))
|
|
|
|
XCTAssertTrue(loadsElement.cells.firstMatch.waitForExistence(timeout: 3))
|
|
Thread.sleep(forTimeInterval: 1)
|
|
takeScreenshot(name: "06-AdventureVanLoads")
|
|
|
|
let bomButton = app.buttons["system-bom-button"]
|
|
XCTAssertTrue(bomButton.waitForExistence(timeout: 2))
|
|
bomButton.tap()
|
|
|
|
// let bomView = app.otherElements["system-bom-view"]
|
|
// XCTAssertTrue(bomView.waitForExistence(timeout: 3))
|
|
//
|
|
// Thread.sleep(forTimeInterval: 1)
|
|
// takeScreenshot(name: "07-AdventureVanBillOfMaterials")
|
|
}
|
|
|
|
private func tapComponentsTab(in app: XCUIApplication) {
|
|
let button = componentsTabButton(in: app)
|
|
XCTAssertTrue(button.waitForExistence(timeout: 3))
|
|
button.tap()
|
|
}
|
|
|
|
private func onboardingPrimaryButton(in app: XCUIApplication) -> XCUIElement {
|
|
let button = app.buttons["create-component-button"]
|
|
if button.exists { return button }
|
|
return app.buttons["onboarding-primary-button"]
|
|
}
|
|
|
|
private func onboardingSecondaryButton(in app: XCUIApplication) -> XCUIElement {
|
|
let button = app.buttons["select-component-button"]
|
|
if button.exists { return button }
|
|
return app.buttons["onboarding-secondary-button"]
|
|
}
|
|
|
|
private func componentsTabButton(in app: XCUIApplication) -> XCUIElement {
|
|
let idButton = app.buttons["components-tab"]
|
|
if idButton.exists {
|
|
return idButton
|
|
}
|
|
|
|
let labels = ["Components", "Verbraucher", "Componentes", "Composants", "Componenten"]
|
|
for label in labels {
|
|
let button = app.buttons[label]
|
|
if button.exists { return button }
|
|
}
|
|
return app.tabBars.buttons.element(boundBy: 1)
|
|
}
|
|
}
|