Quickstart
This guide will help you to get started with the Abra API package for Android.
Setup
The Android Library is published at: Maven Central
-
Open Android Studio.
-
Open the Gradle settings file of your project, e.g.
settings.gradle.kts
. -
Ensure Maven Central is included as repository in the
dependencyResolutionManagement
section.settings.gradle.ktsdependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
} -
Open the Gradle file of your module, e.g.
build.gradle.kts
. -
Add
ai.abra:abra-api:{VERSION}
asandroidTestImplementation
in thedependencies
section.settings.gradle.ktsdependencies {
androidTestImplementation("ai.abra:abra-api:1.1.0")
} -
Press
Sync now
to download and import the library.
Check the release notes for available version.
Usage
After adding the library, you are ready to use it in your test target.
-
Import the API:
import ai.abra.api.AbraAPI
-
Authenticate using your credentials or token:
val user = AbraAPI.auth.login(
email = "name@example.com",
password = "XXXXXXXXXX"
)
AbraAPI.token = user.get().token -
Upload results:
val container = Results()
results.forEach { result ->
container.add(
/* Parameters */
)
}
val response = api.result.create(
screenId = "XXXXXXXXXX",
results = container
)
Example
Also check the Abra SDK for Android to learn how to audit the accessibility of your app.
package ai.abra.mobile.tests
import ai.abra.api.AbraAPI
import ai.abra.api.model.enums.SeverityType
import ai.abra.api.model.enums.Source
import ai.abra.api.model.result.Results
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class APITestCase: AbraTestCase() {
protected lateinit var api: AbraAPI
@Before
override fun before() = runBlocking {
super.before()
api = withContext(Dispatchers.IO) {
val user = AbraAPI.auth.login(
email = "name@example.com",
password = "XXXXXXXXXX"
)
AbraAPI.token = user.get().token
return@withContext AbraAPI
}
}
@Test
fun testAPI() = runBlocking {
val rules = abra.abraRules { all() }
val results = abra.audit(rules = rules)
// Create a result container and add audit results
val container = Results()
results.forEach { result ->
// Map SDK type to API type
val type = SeverityType.valueOf(result.metadata.type.toString())
// Use hash of first element for deduplication
val hash = result.elements.firstOrNull()?.hash.toString()
// Convert related elements to JSON
val elements = result.elements.map { it.toJSON() }
// Convert related snapshots to JSON
val snapshots = result.snapshots.map { it.toJSON() }
// Retrieve related screenshot bitmaps
val screenshots = result.snapshots.mapNotNull { it.screenshot?.bitmap }
// Add properties to container for optimized uploading
container.add(
vendor = result.metadata.vendor.identifier,
rule = result.metadata.rule,
type = type,
description = result.metadata.message,
source = Source.ABRA_SDK,
hash = hash,
elements = elements,
snapshots = snapshots,
screenshots = screenshots
)
}
// Create results for a specific screen
val response = api.result.create(
screenId = "XXXXXXXXXX",
results = container
)
}
}