Skip to main content

Quickstart

This guide will help you to get started with the Abra API package for iOS.

Setup

The Swift Package is published at GitHub

  1. Open Xcode and select File > Add Package Dependencies... from the menu bar.

    Screenshot highlighting the 'Add Package Dependencies' item in the menubarScreenshot highlighting the 'Add Package Dependencies' item in the menubar
  2. Paste the URL of the package in the search field in the top-right corner:

    https://github.com/abra-nl/abra-api-ios-package
  3. Press Add Package in the bottom-right corner.

    Screenshot highlighting the search field and 'Add package' buttonScreenshot highlighting the search field and 'Add package' button
    tip

    You can also set Dependency Rule to Exact Version, for example 1.1.0.

  4. Select your UI testing target in the Add to Target column.

  5. Press Add Package in the bottom-right corner.

    Screenshot highlighting the target selector and 'Add package' buttonScreenshot highlighting the target selector and 'Add package' button
tip

Check the release notes for available version.

Usage

After adding the package, you are ready to use it in your test target.

  1. Import the API:

    import AbraAPI
  2. Authenticate using your credentials or token:

    let user = try await AbraAPIClient.shared.login(
    email: "name@example.com",
    password: "XXXXXXXXXX"
    )
    AbraAPIClient.shared.token = user.token
  3. Upload results:

    let container = Results()
    results.forEach { result in
    container.add(
    /* Parameters */
    )
    }

    let response = try await api.createResults(
    screenId: "XXXXXXXXXX",
    results: container
    )

Example

tip

Also check the Abra SDK for iOS to learn how to audit the accessibility of your app.

warning

To avoid import conflicts when using Abra API and Abra SDK together, you need to add typealias for Result.

SDKResult.swift
import AbraSDK

typealias SDKResult = Result

and

APIResult.swift
import AbraAPI

typealias APIResult = Result

This will be fixed in a new version.

APITestCase.swift
import XCTest
import AbraAPI

class APITestCase: AbraTestCase {

internal var api: AbraAPIClient!

/// Setup the Abra API
override func setUp() async throws {
try await super.setUp()

// Login to get new token, or use existing token
let user = try await AbraAPIClient.shared.login(
email: "name@example.com",
password: "XXXXXXXXXX"
)
AbraAPIClient.shared.token = user.token

self.api = AbraAPIClient.shared
}

/// Upload audit results to the Abra Dashboard
func testAPI() async throws {
// Perform an audit using Abra rules
let rules = abra.abraRuleBuilder.all().build()
let results: [SDKResult] = try abra.audit(rules: rules)

// Create a result container and add audit results
let container = Results()
try results.forEach { result in
// Map SDK type to API type
guard let type = SeverityType(rawValue: result.metadata.type.rawValue) else {
fatalError("Missing support for severity type: \(result.metadata.type)")
}

// Use hash of first element for deduplication
let hash = result.elements.first?.hash.description

// Convert related elements to JSON
let elements = try result.elements.map { try $0.toJSON() }

// Convert related snapshots to JSON
let snapshots = try result.snapshots.map { try $0.toJSON() }

// Retrieve related screenshot images
let screenshots = result.snapshots.map { $0.screenshot.image }

// Add properties to container for optimized uploading
container.add(
vendor: result.metadata.vendor.identifier,
rule: result.metadata.rule.identifier,
type: type,
description: result.metadata.message,
source: .abraSDK,
hash: hash,
elements: elements,
snapshots: snapshots,
screenshots: screenshots
)
}

// Create results for a specific screen
let response = try await api.createResults(
screenId: "XXXXXXXXXX",
results: container
)
}
}