Codemagic
Codemagic is a cloud-based CI/CD platform for Android, iOS, Flutter, and React Native apps that integrates with Perfecto to run tests in conjunction with code-hosting solutions such as Azure DevOps, GitHub, GitLab, Bitbucket, and other self-hosted or cloud-based Git repositories. Codemagic allows you to build mobile apps on standard or premium instances of macOS, Linux, and Windows build machines. By integrating Codemagic with Perfecto, you can execute automated testing on real devices or emulators/simulators, which will allow you to automatically publish your app with every build.
Integrate your workflows with Codemagic using the codemagic.yaml
file or your existing Flutter project.
If you are new to Codemagic and would like an introductory call to get your workflow set up, schedule a complimentary on-boarding session with a member of the Codemagic team. If you are new to Perfecto and need help with the platform, contact Perfecto Support.
On this page:
Step-by-step instructions
Click an option to view integration steps.
To integrate your workflows using the codemagic.yaml
file, perform the following steps.
To integrate using codemagic.yaml:
-
Upload the release APK and/or IPA file(s) to the Perfecto platform by running the following cURL script in a post-build script (a script that is run after executing build commands in the
codemagic.yaml
file):Copycurl "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.apk\",\"artifactType\":\"ANDROID\",\"override\":true}" -F "inputStream=@/path/to/your_binary"
where the
PERFECTO_TOKEN
is the Perfecto security token.To generate or retrieve the security token:-
In the Perfecto UI at <YourCloud>.app.perfectomobile.com (where YourCloud is your actual cloud name, such as mobilecloud), click your user name and select My security token.
-
In the My security token form, click Generate Security Token.
-
Click Copy to clipboard. Then paste it into any scripts that you want to run with Perfecto.
- Click Close.
-
-
Add environment variables in the Codemagic web app using the 'Environment' variables tab.
You can then import your variable groups into your codemagic.yaml. For example, if you named your variable group ‘perfecto_credentials’, you would import it as follows:
workflows:
workflow-name:
environment:
groups:
- perfecto_credentialsFor further information about using variable groups, click here.
You can use the uploaded files to start your automation testing. To do this, set desired capabilities inside your custom-made test scripts in your project. For example, if your testing includes camera usage (QR code, Barcode) or biometric scanning (FaceID/Fingerprint), set sensorInstrument
as follows:
capabilities.setCapability("sensorInstrument", true);
For more information about the Perfecto and Flutter integration, see Flutter.
Set up the Perfecto Flutter integration in Codemagic for Android apps
To set up the integration for Flutter-specific apps, perform the following steps:
-
In the root directory of your project, create a folder named
PerfectoRunAndroid
(can be named differently). -
Switch to the
PerfectoRunAndroid
directory and initiate Gradle by executing the following commands in your local terminal:Copycd Perfecto
Run gradle init
./gradlew wrapperRunning these commands will create the necessary gradle files along with an empty
build.gradle
file. -
Adjust the content of the
build.gradle
file as follows:Copybuildscript {
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:Copy{
"cloudURL": "<CLOUD-ID>.perfectomobile.com",
"securityToken": "<TOKEN>",
"devices": [
{
"platformName" : "Android",
"platformVersion": "^12.*”,
“description”:”free”
},
{
"platformName_" : "Android",
"platformVersion_": "^11.*”,
“description”:”free”
}
],
"jobName": "Flutter_Android_Job",
"jobNumber": 1,
"branch": "Flutter_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
}where the
securityToken
is the Perfecto security token.To generate or retrieve the security token:-
In the Perfecto UI at <YourCloud>.app.perfectomobile.com (where YourCloud is your actual cloud name, such as mobilecloud), click your user name and select My security token.
-
In the My security token form, click Generate Security Token.
-
Click Copy to clipboard. Then paste it into any scripts that you want to run with Perfecto.
- Click Close.
-
-
To generate
testBuildType
, which refers totestApkPath
, run the following command in a pre-build script (a script that is run after executing build commands) insidecodemagic.yaml
:Copy- name: Build Android Test release
script: |
./gradlew assembleAndroidTest -
To successfully upload files and enable test automation, run the following commands:
Copy- name: Upload files to Perfecto and run tests
script: |
cd PerfectoRunAndroid
./gradlew perfecto-android-inst
Set up the Perfecto Flutter integration in Codemagic for iOS apps
Flutter iOS apps require almost the same steps as Android builds, as follows:
-
Create another folder in the root directory named
PerfectoRunIos
(can be named differently). -
Manually create
build.gradle
along with the following content:Copybuildscript {
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
configFile.json
and add the following content:Copy{
"cloudURL": "<CLOUD_ID>.perfectomobile.com",
"securityToken":"<TOKEN>",
"appPath":"repository:PATH_TO_IPA",
"hostedTestModuleName":"RunnerTests",
"isHostedTestModule":true,
"devices": [
{"deviceName":"xxxxxxxx-xxxxxxxxxxxxxxxx"},
{"deviceName":"xxxxxxxx-xxxxxxxxxxxxxxxx "}
],
"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":
}where:
-
The
securityToken
is the Perfecto security token.To generate or retrieve the security token:-
In the Perfecto UI at <YourCloud>.app.perfectomobile.com (where YourCloud is your actual cloud name, such as mobilecloud), click your user name and select My security token.
-
In the My security token form, click Generate Security Token.
-
Click Copy to clipboard. Then paste it into any scripts that you want to run with Perfecto.
- Click Close.
-
-
the
deviceName
can be found in the Perfecto cloud.
-
-
To successfully upload files and enable test automation, run the following commands:
Copy- name: Upload iOS files to Perfecto and run tests
script: |
cd PerfectoRuniOS
gradle perfecto-xctest
Sample projects
To view a sample project that shows how to configure the Perfecto integration for real device testing, see https://github.com/codemagic-ci-cd/codemagic-sample-projects/tree/main/integrations/perfecto_sample_project.
Additionally, to view a sample project that shows how to configure the Perfecto integration for App Automate for Flutter apps, visit https://github.com/codemagic-ci-cd/codemagic-sample-projects/tree/main/integrations/perfecto_flutter_sample_project.