Quickstart
This guide will help you to get started with the Abra API package for iOS.
Setup
The Swift Package is published at GitHub
-
Open Xcode and select
File > Add Package Dependencies...
from the menu bar. -
Paste the URL of the package in the search field in the top-right corner:
https://github.com/abra-nl/abra-api-ios-package
-
Press
Add Package
in the bottom-right corner.tipYou can also set
Dependency Rule
toExact Version
, for example1.1.0
. -
Select your UI testing target in the
Add to Target
column. -
Press
Add Package
in the bottom-right corner.
Check the release notes for available version.
Usage
After adding the package, you are ready to use it in your test target.
-
Import the API:
import AbraAPI
-
Authenticate using your credentials or token:
let user = try await AbraAPIClient.shared.login(
email: "name@example.com",
password: "XXXXXXXXXX"
)
AbraAPIClient.shared.token = user.token -
Upload results:
let container = Results()
results.forEach { result in
container.add(
/* Parameters */
)
}
let response = try await api.createResults(
screenId: "XXXXXXXXXX",
results: container
)
Example
Also check the Abra SDK for iOS to learn how to audit the accessibility of your app.
To avoid import conflicts when using Abra API and Abra SDK together, you need to add typealias
for Result
.
import AbraSDK
typealias SDKResult = Result
and
import AbraAPI
typealias APIResult = Result
This will be fixed in a new version.
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
)
}
}