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.
Get the Perfecto access token from the Perfecto UI.
Open your Codemagic app settings, and go to the Environment variables tab.
Enter the desired Variable name, e.g.
PERFECTO_TOKEN
.Copy and paste the Perfecto token string as Variable value.
Enter the variable group name, e.g. perfecto_credentials. Click the button to create the group.
Make sure the Secure option is selected.
Click the Add button to add the variable.
Add the variable group to your
codemagic.yaml
fileenvironment: 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:
Generate a folder named PerfectoRunAndroid (can be named differently) in the root directory of your project.
Change dir to PerfectoRunAndroid directory and initiate Gradle by executing the following commands in your local terminal:
cd PerfectoRun
gradle init
./gradlew wrapper
- Running the above commands will create the necessary gradle files along with an empty
build.gradle
. Edit thebuild.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
}
- 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.
- 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:
Create another folder in the root directory named PerfectoRunIos (can be named differently)
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"
}
- 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
}
- 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