Setup for Appium Testing

Link to Setup for Appium Testing copied to clipboard
tip

Codeless accessibility testing via Appium is Coming Soon!

We're developing an Appium Plugin that's set to launch early 2024. This plugin will enable you to better integrate accessibility testing for any mobile application throughout your Appium tests, no matter the language they are written in and without access to source code!

Using Appium with axe DevTools Today?

Today Appium support is only available for native Android XML applications via an embedded code element. The below guide walks you through the set up steps.

Important note: Appium support will remain with axe DevTools Version 4.3.0 as referenced below. The embedded code element has been removed beginning in version 5.0.0 in preparation for the launch of the Appium plugin. Please continue to use version 4.3.0 until the plugin is available.

Step 1: Application Setup

The embedded floating action button is required today for Appium to interact with the axe DevTools Mobile framework to initiate a scan. First, you'll need to import the library.

Connect to Dependency Source

Using Maven Central

Inside the project's build.gradle file add mavenCentral to the repositories list. This may be within the buildscript block or the allprojects block.

buildscript {
    repositories {
        mavenCentral()
    }
}

or

allprojects {
    repositories {
        mavenCentral()
    }
}

Using Artifactory

View the instructions for using Artifactory.

Import the axe DevTools Mobile library for Android

In the application build.gradle file, add:

implementation 'com.deque.android:axe-devtools-android:4.3.0'

and

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        
        //For Espresso Tests:
        exclude 'META-INF/AL2.0' 
        exclude 'META-INF/LGPL2.1'
    }
}

also, make sure there is Internet permission in the AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

Full Example

Below is a complete sample application build.gradle file.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    dataBinding {
        enabled = true
    }

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 24
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        
        //For Espresso Tests:
        exclude 'META-INF/AL2.0' 
        exclude 'META-INF/LGPL2.1'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.deque.android:axe-devtools-android:4.3.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Step 2: Add the Floating Action Button (FAB) to Initiate Scans

You will need to add this to each Activity that you would like to run scans on.

Login and Load the Floating Action Button

Choose from logging in with an API key or username / password.

Connect with API key:

Generate an API key at axe.deque.com.

val axe = AxeDevTools()
    
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    axe.connect(
        "<your_api_key>"
    )
    axe.showA11yFAB(this)
}

Connect with username and password:

val axe = AxeDevTools()
    
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    axe.connect(
        "<your_username>",
        "<your_password>"
    )
    axe.showA11yFAB(this)
}
important

Access the axe object within any activity you wish to test and register that activity for testing with axe.showA11yFAB(this).

Step 3: Appium Tests

Now that the application you wish to test is set up, next is getting your Appium tests ready to go. We have full examples in Java or Kotlin to better guide you. Each example interacts with the FAB to initiate a scan, then uses our REST API to pull the result from the server.

tip

The floating action button can be moved around the screen to not obstruct development. Scans will automatically be sent to axe DevTools Mobile Dashboard where you can view the results.

Note: Altering the screen state prior to the floating action button finishing its scan may result in a crash.