GPT Driver User Guide
GPT Driver SDK
GPT Driver SDK
  • 👋Welcome
  • Overview
    • 💡Why GPTD
    • SDKs
      • Prerequisites
      • Python
        • Setup
        • Examples
        • Reference
      • Typescript
        • Setup
        • Examples
        • Reference
      • Java
        • Setup
        • Examples
          • GPT Driver + TestNG
          • GPTD + Lambdatest
          • GPTD + SauceLabs
          • GPT Driver + BrowserStack
        • Reference
        • Use within Android
      • Android Native (Java/Kotlin)
        • Setup
        • Example
        • Reference
      • Swift
        • Setup
        • Usage
Powered by GitBook
On this page
  1. Overview
  2. SDKs
  3. Swift

Usage

You can utilize our our Swift SDK with or without appium. Appium has the advantage that our SDK can interact with the full device, whereas with the XCUITest method we can only interact with the app itself.

  1. Import the GPT Driver pacakge

import gptd_swift

  1. Initialize GPT Driver in the setUp function of an XCTestCase file, and pass the XCUIApplication instance.

DemoUITests.swift
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()
        
        // Init gpt driver by passing the XCUIApplication
        gptDriver = GptDriver(
            apiKey: "<api_key>",
            nativeApp: app
        )
    }

    override func tearDownWithError() throws {
        app = nil
    }
    
    func testNavigationToSecondScreen() async throws {
        
        try await gptDriver.execute("Tap on the Go to Second Screen button")
        
        try await gptDriver.execute("Check if you can see a screen with a second screen headline")
        
    }
    
}
  1. Import the GPT Driver pacakge

import gptd_swift
  1. Initialize GPT Driver in the setUp function of an XCTestCase file, by providing the appium server URL

DemoUITests.swift
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()
        
        // Init gpt driver by passing the appium server URL
        gptDriver = GptDriver(
            apiKey: "<api_key>",
            appiumServerUrl: URL(string: "http://localhost:4723")!
        )
    }

    override func tearDownWithError() throws {
        app = nil
    }
    
    func testNavigationToSecondScreen() async throws {
        
        try await gptDriver.execute("Tap on the Go to Second Screen button")
        
        try await gptDriver.execute("Check if you can see a screen with a second screen headline")
        
    }
    
}
  1. Start an appium server before running the test

Terminal
appium

PreviousSetup

Last updated 3 months ago