GptDriver
Constructor
AI commands
execute
Execute a natural language instruction on the current screen.assert
Verify a condition without taking action. Throws on failure, and marks the session as failed.assertBulk
Verify several conditions against a single screenshot, in one round trip. Throws if any of them fails.checkBulk
The same check asassertBulk, but it returns the results instead of throwing, so you can branch on what is on screen.
assert, assertBulk and checkBulk take maxRetries (default 2) and retryDelay (default 1.0 seconds). A condition that is not met yet is re-checked against a fresh screenshot, which covers a screen that is still settling.extract
Extract information from the current screen. Takes an array and returns a dictionary keyed by the strings you asked for.Native-first execution
Every AI command has an overload taking anativeAction closure. The SDK runs your XCUITest code first and only falls back to the natural language command when that code fails, so a step that works natively costs no AI round trip.
XCTAssert. Assertion failures inside the closure are intercepted and are not recorded as test failures, since the fallback takes over. Only a failure of the fallback itself fails the test.
Write the command to describe what the native code does, not only what to do if it breaks. It is also the label the step carries in the session recording.
For checkBulk, a closure that succeeds reports every condition as true.
Successful blocks are reported to the platform with a screenshot taken just before the closure runs, so they appear as steps in the session recording alongside AI steps. Reporting is best effort and never fails a passing test. Set
logNativeExecutions: false in the constructor to skip it and trade the recording for speed.Session lifecycle
The session starts automatically on the first AI command. Report the outcome at the end of a test so the dashboard records it.assert or assertBulk marks the session as failed for you. Nothing marks it as succeeded, so a session you never close is recorded as auto-completed, which reads as “the test stopped calling” rather than “the test passed”.
Closing a session also releases its slot against your account’s parallel session limit straight away, instead of leaving it held until it ages out.
Session metadata
Passmetadata to record your own key/values on the session, anything your CI knows and the SDK does not.
master alone for instance.
Keys are free-form and values are strings. language and version are reserved for the SDK’s own identity: it reports Swift and the package version it was built from, and a key of your own with either name is ignored rather than recorded.
metadata requires SDK 1.12.0 or later.Session URL
The SDK creates a session URL for each test run, accessible via:gptDriver.sessionURL: public propertyonSessionCreatedcallback: for real-time access- XCTest Attachments: saved as a
.weblocfile in test results - OS Logs: logged at
.noticelevel
Retrieving in CI
The session URL is saved as an XCTest attachment namedGPTDriver Session URL Link with lifetime .keepAlways. Extract it from the .xcresult bundle in your CI pipeline.
