Skip to main content
Glama
TestSnapshotCache.swift2.04 kB
import Foundation import PeekabooAutomationKit import PeekabooCore /// Test-only snapshot cache helper for UI automation snapshots. /// /// Prefer using `TestServicesFactory.makeAutomationTestContext()` for most unit tests. final class SnapshotCache { let snapshotId: String private let snapshotManager: SnapshotManager typealias UIAutomationSnapshot = PeekabooAutomationKit.UIAutomationSnapshot typealias UIElement = PeekabooCore.UIElement private init(snapshotId: String, snapshotManager: SnapshotManager) { self.snapshotId = snapshotId self.snapshotManager = snapshotManager } static func create() async throws -> SnapshotCache { let snapshotManager = SnapshotManager() let snapshotId = try await snapshotManager.createSnapshot() return SnapshotCache(snapshotId: snapshotId, snapshotManager: snapshotManager) } func save(_ data: UIAutomationSnapshot) async throws { if let screenshotPath = data.screenshotPath { try await self.snapshotManager.storeScreenshot( snapshotId: self.snapshotId, screenshotPath: screenshotPath, applicationBundleId: data.applicationBundleId, applicationProcessId: data.applicationProcessId, applicationName: data.applicationName, windowTitle: data.windowTitle, windowBounds: data.windowBounds ) } } func load() async throws -> UIAutomationSnapshot? { try await self.snapshotManager.getUIAutomationSnapshot(snapshotId: self.snapshotId) } func clear() async throws { try await self.snapshotManager.cleanSnapshot(snapshotId: self.snapshotId) } func getSnapshotPaths() -> (map: String) { let baseDir = FileManager.default.homeDirectoryForCurrentUser .appendingPathComponent(".peekaboo/snapshots/\(self.snapshotId)") return ( map: baseDir.appendingPathComponent("snapshot.json").path ) } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/steipete/Peekaboo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server