Perfecto with XCUITest Example

Link to Perfecto with XCUITest Example copied to clipboard

Test your iOS app for accessibility issues on devices from Perfecto.

Run your UI Tests on Perfecto to get a comprehensive understanding of your app's accessibility health across devices.

Requires:

  • Perfecto Enterprise Private Cloud

Prerequisites

  1. Your UI Tests are integrated with axe DevTools Mobile for iOS. Checkout our getting started guide if needed.

  2. Prepare your app for distribution. Since you'll be testing on Perfecto with real devices, having the app and UI Test targets provisioned results in a smoother process.

  3. Install Gradle

Example Project

Looking for an example? Our Sample iOS Project has an integration ready to test.

  1. Finish the prerequisites
  2. Download the sample project from Github
  3. Open the Xcode project file and add your development team to the app and UITest targets for provisioning
  4. Add your axe DevTools for Mobile API key to Login.swift
  5. Adjust the values in following location to match your Perfecto cloud:

perfecto.sh

CLOUDNAME="<<perfecto-cloud-name>>"

configFile.json Review the values cloudURL, securityToken, and deviceName:

{
  "cloudURL": "<<perfecto-cloud-name>>",
  "securityToken": "<<security-token>>",
  ...
  "devices": [
    {
      "deviceName": "00005302-BF389EDED8B22DBD"
    }
  ],
  ...
}
  1. Open a Terminal window, enter cd , then drag and drop the axe-devtools-ios-sample-app from Finder into the Terminal window. Hit return/enter.
  2. In the same window, type sh perfecto.sh. Hit return/enter.

There are 3 files in the sample project used for Perfecto integration: perfecto.sh, configFile.json, and build.gradle.

Add Perfecto to Your XCUI Test

Setup

Note: All 3 files are expecting to be in your project's root.

  1. Create a shell script, to orchestrate executing tests on Perfecto's platform. Be sure to adjust the values for APP_LOCATION, APP_NAME and CLOUDNAME to match your application and Perfecto cloud.
APP_LOCATION="DerivedData/Build/Products/Debug-iphoneos"
APP_NAME="axe-devtools-ios-sample-app"
CLOUDNAME="<<perfecto-cloud-name>>"

TOKEN="<<security-token>>"
JOBNUMBER="<<job-number>>"

rm -rf *.app
# Prepare app files
gradle buildForRealDevice
mv $APP_LOCATION/$APP_NAME.app .
mv $APP_LOCATION/"$APP_NAME"UITests-Runner.app .
# Run on Perfecto cloud
gradle perfecto-xctest -PconfigFileLocation=configFile.json -PcloudURL=$CLOUDNAME.perfectomobile.com -PsecurityToken=$TOKEN -PjobNumber=$JOBNUMBER --stacktrace --debug
rm -rf DerivedData
  1. Add your Gradle file, build.gradle. Be sure to update the last section to match your application's values.
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        def flatDirPath = project.hasProperty('flatDirPath') ? project.getProperty('flatDirPath') : ''
        if(flatDirPath != '') {
            flatDir {
                dirs flatDirPath
            }
        } else {
            maven {
                url "https://repo1.perfectomobile.com/public/repositories/maven/"
            }
        }
    }

    dependencies {
        classpath "com.perfectomobile.instrumentedtest.gradleplugin:plugin:+"
    }
}

apply plugin: 'com.perfectomobile.instrumentedtest.gradleplugin'

perfectoGradleSettings {
    configFileLocation "configFile.json"
}

tasks.register('cleanPreviousBuild', Exec) {
    workingDir projectDir
    commandLine "bash", "-c", "rm -fr *.xctestproducts dd"
}

tasks.register('buildForRealDevice') {
    dependsOn cleanPreviousBuild
    doLast {
        exec {
            commandLine "bash", "-c", "xcodebuild build-for-testing " +
                    " -destination generic/platform='iOS' " +
                    " -configuration Debug" +
                    " -scheme axe-devtools-ios-sample-app" +
                    " -target axe-devtools-ios-sample-appUITests" + 
                    " -sdk iphoneos" + 
                    " -derivedDataPath DerivedData/  -quiet -allowProvisioningUpdates" 
        }
    }
}
  1. Add Perfectos configuration JSON and review the values cloudURL, securityToken, appPath, testAppPath and deviceName to match your Perfecto authentication, application and available real device UUID.

The above build.gradle is looking for a config file named configFile.json - be sure to update it if you use a different name.

{
  "cloudURL": "<<perfecto-cloud-name>>",
  "securityToken": "<<security-token>>",
  "appPath": "axe-devtools-ios-sample-app.app",
  "testAppPath": "axe-devtools-ios-sample-appUITests-Runner.app",
  "devices": [
    {
      "deviceName": "00005302-BF389EDED8B22DBD"
    }
  ],
  "tags": [
    "xcuitest",
    "sample"
  ],
  "projectName": "Axe-XCUITest",
  "projectVersion": "v1-test",
  "jobName": "AXE-XCUITEST-LATEST",
  "jobNumber": 1,
  "branch": "master",
  "failBuildOnFailure": false,
  "installationDetails": {
    "preCleanUp": true,
    "resign": true
  },
  "postExecution": {
    "uninstall": false
  },
  "acquireDeviceRetryNumber": 1,
  "acquireDeviceRetryInterval": 200,
  "debug": true,
  "runUnitTests": true,
  "runUiTests": true,
  "shard": false,
  "takeScreenshotOnTestEnd": true,
  "testTimeout": "60000"
}

Run

Once your project is setup, run the shell script to execute a test on your Perfecto cloud.

Verify locally:

  1. Open your project in the Terminal
  2. Type sh perfecto.sh and hit enter
  3. Open your Perfect Cloud's Test Analysis to checkout your latest report