Perfecto with XCUITest Example

Link to Perfecto with XCUITest Example copied to clipboard

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

Not for use with personal data

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. Verify that you have the prerequisites.

  2. Download the sample project from Github

  3. Open the Xcode project file to 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 the following locations 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"
        }
      ],
      ...
    }
  6. Open a Terminal window, enter cd , and then drag and drop the axe-devtools-ios-sample-app from Finder into the Terminal window. Hit return/enter.

  7. In the same window, type sh perfecto.sh. Hit return/enter.

There are three 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 three 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
  2. 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" 
            }
        }
    }
  3. Add Perfecto's 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 set up, 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 Perfecto Cloud's Test Analysis to check out your latest report.