Skip to main content

Quickstart

This guide will help you to get started with the Abra SDK 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-sdk:{VERSION} as androidTestImplementation in the dependencies section.

    settings.gradle.kts
    dependencies {
    androidTestImplementation("ai.abra:abra-sdk: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 SDK:
    import ai.abra.sdk.Abra
  2. Configure the SDK:
    val config = AbraConfig(
    license = "<YOUR-SDK-LICENSE>",
    identifier = "<YOUR-APP-IDENTIFIER>"
    )
    val abra = Abra(config = config)
  3. Configure the rules:
    val abraRules = abra.abraRules { 
    all()
    }
    val googleRules = abra.googleRules {
    all()
    }
  4. Perform an audit:
    val results = abra.audit(rules)

Example

tip

Also check the Abra API for Android to learn how to upload results to the Abra Dashboard.

AbraTestCase.kt
package ai.abra.mobile.tests

import ai.abra.sdk.Abra
import ai.abra.sdk.AbraConfig
import ai.abra.sdk.rule.ResultType
import ai.abra.sdk.rule.Rule

import android.app.Instrumentation
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.UiDevice
import junit.framework.TestCase.assertNotNull

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Before
import org.junit.rules.ErrorCollector

@RunWith(AndroidJUnit4::class)
open class AbraTestCase {

private val LICENSE = "XXXXXXXXXX"
private val IDENTIFIER = "com.android.settings"

protected lateinit var instrumentation: Instrumentation
protected lateinit var device: UiDevice
protected lateinit var context: Context

protected lateinit var abra: Abra
protected lateinit var rules: List<Rule>

@get:org.junit.Rule
val collector = ErrorCollector()

@Before
open fun before() {
this.instrumentation = InstrumentationRegistry.getInstrumentation()
this.device = UiDevice.getInstance(instrumentation)
this.context = ApplicationProvider.getApplicationContext()

val config = AbraConfig(
license = LICENSE,
identifier = IDENTIFIER,
)
this.abra = Abra(config = config)
this.rules = abra.abraRules { all() } +
abra.googleRules { all() }
}

@Test
fun testAccessibility() {
val intent = context.packageManager.getLaunchIntentForPackage(IDENTIFIER)
assertNotNull("Launch intent must be available for $IDENTIFIER", intent)
context.startActivity(intent)

val results = abra.audit(rules)

results.forEach { result ->
collector.checkSucceeds {
if (result.metadata.type == ResultType.ERROR) {
throw AssertionError("${result.metadata.rule}: ${result.metadata.message}")
}
}
}
}
}

Results

Screenshot of Android Studio logs where a contrast issue is reportedScreenshot of Android Studio logs where a contrast issue is reported