Skip to main content

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

  1. Open Android Studio.

  2. Open the Gradle settings file of your project, e.g. settings.gradle.kts.

  3. Ensure Maven Central is included as repository in the dependencyResolutionManagement section.

    settings.gradle.kts
    dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
    google()
    mavenCentral()
    }
    }
  4. Open the Gradle file of your module, e.g. build.gradle.kts.

  5. Add ai.abra:abra-api:{VERSION} as androidTestImplementation in the dependencies section.

    settings.gradle.kts
    dependencies {
    androidTestImplementation("ai.abra:abra-api:1.1.0")
    }
  6. Press Sync now to download and import the library.

tip

Check the release notes for available version.

Usage

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

  1. Import the API:

    import ai.abra.api.AbraAPI
  2. Authenticate using your credentials or token:

    val user = AbraAPI.auth.login(
    email = "name@example.com",
    password = "XXXXXXXXXX"
    )
    AbraAPI.token = user.get().token
  3. Upload results:

    val container = Results()
    results.forEach { result ->
    container.add(
    /* Parameters */
    )
    }

    val response = api.result.create(
    screenId = "XXXXXXXXXX",
    results = container
    )

Example

tip

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

APITestCase.kt
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
)
}
}