Perfecto integration

How to integrate your workflows with Perfecto using codemagic.yaml

Perfecto is a cloud-based test automation platform for web and mobile that allows application developers and QA engineers to create and execute tests across devices and browsers at scale. Being a market leader in its area, Perfecto offers many ways to integrate with different stages of the software development and testing lifecycle. It is possible to integrate with Perfecto directly from your codemagic.yaml

A sample project that shows how to configure Perfecto integration for real device testing is available in our Sample projects repository.

A sample project showcasing Perfecto App Automate integration for Flutter apps is available here.

Configuring Perfecto access

Signing up with Perfecto is required in order to get credentials that are needed during an upload process.

  1. Get the Perfecto access token from the Perfecto UI.

  2. Open your Codemagic app settings, and go to the Environment variables tab.

  3. Enter the desired Variable name, e.g. PERFECTO_TOKEN.

  4. Copy and paste the Perfecto token string as Variable value.

  5. Enter the variable group name, e.g. perfecto_credentials. Click the button to create the group.

  6. Make sure the Secure option is selected.

  7. Click the Add button to add the variable.

  8. Add the variable group to your codemagic.yaml file

      environment:
        groups:
          - perfecto_credentials

Uploading to Perfecto

Using the following cURL script in a post-build script, Release APK and Release IPA binaries can be uploaded to the Perfecto platform:

  scripts:
    - name: Upload to Perfecto
      script: | 
        curl "https://web.app.perfectomobile.com/repository/api/v1/artifacts" \
        -H "Perfecto-Authorization: $PERFECTO_TOKEN" \
        -H "Content-Type: multipart/form-data" \
        -F "requestPart={\"artifactLocator\":\"PRIVATE:app.aab\",\"artifactType\":\"ANDROID\",\"override\":true}" \
        -F "inputStream=@/path/to/your_binary"

Test Automation

The uploaded files can be directly used to start your automation testing. To do this, desired capabilities can be set inside your custom-made test scripts in your project. For example, if your application requires device sensors such as camera or fingerprint reader, then sensorInstrument needs to be set:

  capabilities.setCapability("sensorInstrument", true);

Flutter apps integration

In order to set up integration for Flutter specific apps the following steps must be followed:

  1. Generate a folder named PerfectoRunAndroid (can be named differently) in the root directory of your project.

  2. Change dir to PerfectoRunAndroid directory and initiate Gradle by executing the following commands in your local terminal:

cd PerfectoRun 
gradle init 
./gradlew wrapper
  1. Running the above commands will create the necessary gradle files along with an empty build.gradle. Edit the build.gradle by adding the following:
buildscript {
    repositories {
        maven {
            url "https://repo1.perfectomobile.com/public/repositories/maven/"      
        }
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.perfectomobile.instrumentedtest.gradleplugin:plugin:+"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
// Apply the plugin 
apply plugin: 'com.perfectomobile.instrumentedtest.gradleplugin'
perfectoGradleSettings {
    configFileLocation "ConfigFile.json"
}
    task clean(type: Delete) {
        delete rootProject.buildDir
}
  1. Create a file called ConfigFile.json and add the following Json content in there:
{
      "cloudURL": "web-fra.perfectomobile.com",
      "securityToken": "xxxxxxxxxxxx",
      "devices": [
            {
              "platformName" : "Android",
              "platformVersion": "^12.*”,
              “description”:”free”
            },
            {
              "platformName_" : "Android",
              "platformVersion_": "^11.*”,
              “description”:”free”
            }
      ],
      "jobName": "some_job",
      "jobNumber": 1,
      "branch": "some_branch",
      "projectName": "My_Flutter_project",
      "projectVersion": "v1.0",
      "tags": [
        "espresso", "plugin"  ],
      "apkPath": "YOUR_APK_PATH",
      "testApkPath": "YOUR_TEST_APK_PATH",
      "installationDetails" : {"preCleanUp" : "true"},
      "postExecution" : {"uninstall" : "false" },
      "debug": false,
      "failBuildOnFailure": false,
      "takeScreenshotOnTestFailure": true,
      "shard": false,
      "testTimeout" : 60000
    }

“securityToken” contains your Perfecto Token that can be fetched from your Perfecto account.

  1. Modify your codemagic.yaml file to include post-build scripts to generate testBuildType and upload the files to Perfecto
  scripts:
    - name: Build Android Test release
      script: | 
        ./gradlew assembleAndroidTest
    - name: Upload files to Perfecto and run tests
      script: | 
        cd PerfectoRunAndroid
        ./gradlew perfecto-android-inst

In order to set up integration for Flutter specific apps the following steps must be followed:

  1. Create another folder in the root directory named PerfectoRunIos (can be named differently)

  2. Manually create build.gradle file with the following content:

buildscript {
    repositories {
        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"
}
  1. Create a file called ConfigFile.json and add the following Json content in there:
{
    "cloudURL": "beta.perfectomobile.com",
    "securityToken":"xxxxxxxxxxxx",
	"appPath":"repository:PATH_TO_IPA",
	"hostedTestModuleName":"RunnerTests",
	"isHostedTestModule":true,
	"devices": [
			{"deviceName":"00008020-000D2CC42ED8002E"},
			{"deviceName":"00008101-000B05283081401E"}
	],
	"shard": false,
	"jobName": "Flutter_iOS_Job",
  	"jobNumber": 1,
  	"branch": "Flutter_Branch",
  	"projectName": "My_Flutter_iOS_Project",
  	"projectVersion": "v1.0",
  	"tags": [
    "XCUI", "plugin"  ],
	"takeScreenshotOnTestFailure": false,
	"takeScreenshotOnTestEnd": false,
	"takeScreenshotOnTestStep": false,
	"runUITests":true,
	"runUnitTests":false,
	"installationDetails": {
		"resign": true
	  },  
  	"numOfDevices": 2
  }
  1. Modify your codemagic.yaml file to include a script upload the files to Perfecto
  scripts:
    - name: Upload iOS files to Perfecto and run tests
      script: | 
        cd PerfectoRunIos
        gradle perfecto-xctest

Get Help and Support with Perfecto

To test how Perfecto supports Flutter Integration Testing for native mobile applications, visit their website and get access to a free trial. Additionally, for video demonstrations and some more information on how to set up Flutter for iOS and Android apps in Perfecto, visit the following documentation pages: 1. Setting up Flutter for iOS in Perfecto 2. Setting up Flutter Android in Perfecto