Basic navigation test
import XCTest
import gptd_swift
@MainActor
final class DemoUITests: XCTestCase {
var app: XCUIApplication!
var gptDriver: GptDriver!
override func setUpWithError() throws {
continueAfterFailure = false
app = XCUIApplication()
app.launch()
gptDriver = GptDriver(
apiKey: "<YOUR_API_KEY>",
nativeApp: app
)
}
override func tearDownWithError() throws {
app = nil
}
func testNavigationToSecondScreen() async throws {
try gptDriver.execute("Tap on the Go to Second Screen button")
try gptDriver.execute("Check if you can see a screen with a second screen headline")
}
}
With caching enabled
override func setUpWithError() throws {
continueAfterFailure = false
app = XCUIApplication()
app.launch()
gptDriver = GptDriver(
apiKey: "<YOUR_API_KEY>",
nativeApp: app,
cachingMode: CachingMode.interactionRegion,
testId: self.name
)
}
func testLoginFlow() async throws {
try gptDriver.execute("Tap the email field and enter test@example.com")
try gptDriver.execute("Tap the password field and enter SecurePass123")
try gptDriver.execute("Tap the Sign In button")
try gptDriver.assert("The home screen is displayed with a welcome message")
}
With additional context
gptDriver = GptDriver(
apiKey: "<YOUR_API_KEY>",
nativeApp: app,
additionalUserContext: "When asked about Location Permissions, grant it. When a marketing popup appears, dismiss it."
)
func testOnboarding() async throws {
try gptDriver.execute("Complete the onboarding flow by tapping Next on each screen")
try gptDriver.execute("Tap Get Started on the final screen")
try gptDriver.assert("The main dashboard is visible")
}

