← All repositories

listless

A simple list app for Apple platforms

git clone https://code.inqk.net/listless.git


Tests/UI/ListlessWatchScreenshots.swift (1309B)

1import XCTest
2
3final class ListlessWatchScreenshots: XCTestCase {
4    var app: XCUIApplication!
5
6    static let screenshotDir = "/tmp/listless-screenshots"
7
8    override class func setUp() {
9        super.setUp()
10        try? FileManager.default.createDirectory(
11            atPath: screenshotDir,
12            withIntermediateDirectories: true
13        )
14    }
15
16    override func tearDownWithError() throws {
17        app.terminate()
18    }
19
20    private func launchApp(_ additionalArgs: [String] = []) {
21        app = XCUIApplication()
22        app.launchArguments = ["UI_TESTING"] + additionalArgs
23        app.launch()
24    }
25
26    func saveScreenshot(name: String) {
27        let screenshot = XCUIScreen.main.screenshot()
28        let attachment = XCTAttachment(screenshot: screenshot)
29        attachment.name = name
30        attachment.lifetime = .keepAlways
31        add(attachment)
32
33        let data = screenshot.pngRepresentation
34        let path = "\(Self.screenshotDir)/\(name).png"
35        try? data.write(to: URL(fileURLWithPath: path))
36    }
37
38    func testScreenshot01_Items() throws {
39        launchApp(["SCREENSHOT_SEED"])
40
41        let list = app.collectionViews.firstMatch
42        XCTAssertTrue(list.waitForExistence(timeout: 5))
43
44        usleep(500_000)
45
46        saveScreenshot(name: "01-items")
47    }
48}