Add screenshot generator

This commit is contained in:
世界
2026-01-08 16:13:20 +08:00
parent 264c4eed81
commit 6b589cb771
57 changed files with 1931 additions and 109 deletions
+74
View File
@@ -0,0 +1,74 @@
import XCTest
@MainActor
final class SnapshotTests: XCTestCase {
let app = XCUIApplication()
override func setUpWithError() throws {
continueAfterFailure = false
setupSnapshot(app)
app.launch()
}
func test01Dashboard() throws {
#if os(macOS)
if app.outlines.staticTexts["Dashboard"].exists {
app.outlines.staticTexts["Dashboard"].click()
}
#endif
sleep(1)
snapshot("01_Dashboard")
}
func test02Logs() throws {
#if os(iOS)
if app.tabBars.buttons["Logs"].exists {
app.tabBars.buttons["Logs"].firstMatch.tap()
} else if app.buttons["Logs"].exists {
app.buttons["Logs"].firstMatch.tap()
}
#elseif os(macOS)
if app.outlines.staticTexts["Logs"].exists {
app.outlines.staticTexts["Logs"].click()
}
#elseif os(tvOS)
let remote = XCUIRemote.shared
for _ in 0 ..< 3 {
remote.press(.down)
usleep(300_000)
}
if app.cells["Logs"].exists {
app.cells["Logs"].tap()
} else {
remote.press(.select)
}
#endif
sleep(1)
snapshot("02_Logs")
}
func test03Settings() throws {
#if os(iOS)
if app.tabBars.buttons["Settings"].exists {
app.tabBars.buttons["Settings"].firstMatch.tap()
} else if app.buttons["Settings"].exists {
app.buttons["Settings"].firstMatch.tap()
}
#elseif os(macOS)
if app.outlines.staticTexts["Settings"].exists {
app.outlines.staticTexts["Settings"].click()
}
#elseif os(tvOS)
let remote = XCUIRemote.shared
remote.press(.down)
usleep(300_000)
if app.cells["Settings"].exists {
app.cells["Settings"].tap()
} else {
remote.press(.select)
}
#endif
sleep(1)
snapshot("03_Settings")
}
}
+40
View File
@@ -0,0 +1,40 @@
//
// UITests.swift
// UITests
//
// Created by sekai on 2026-01-06 15:19.
//
import XCTest
final class UITests: 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 its 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.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
@MainActor
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
@MainActor
func testLaunchPerformance() throws {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
+32
View File
@@ -0,0 +1,32 @@
//
// UITestsLaunchTests.swift
// UITests
//
// Created by sekai on 2026-01-06 15:19.
//
import XCTest
final class UITestsLaunchTests: XCTestCase {
override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}
override func setUpWithError() throws {
continueAfterFailure = false
}
@MainActor
func testLaunch() throws {
let app = XCUIApplication()
app.launch()
// Insert steps here to perform after app launch but before taking a screenshot,
// such as logging into a test account or navigating somewhere in the app
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "Launch Screen"
attachment.lifetime = .keepAlways
add(attachment)
}
}