Run native app tests in CI

Prerequisites

  • Build process with .ipa or .apk file as output, for example:
  • Native application tests can be executed from the command line, for example:

Upload the app and run tests

Below, you can find samples of CI configuration for uploading the app file and running tests.

pipeline {
    agent {
        label '<AGENT_LABEL>'
    }
    parameters {
        string(name: 'ACCESS_KEY', description: 'The access token for API authentication and connecting to the Appium')
        string(name: 'INSTANCE_HOST', defaultValue: 'app.mobitru.com', description: 'Hostname of instance with the Mobitru')
        string(name: 'PROJECT_NAME', defaultValue: '<NAME>', description: 'Name of a Project, which assigned to you in the Mobitru')
    }
    stages {
        stage('Run test') {
            tools {
                maven 'maven'
            }
            steps {
                cleanWs()
                catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE'){
                //checkout tests code
                    git branch: "main",
                        url: '<GIT_URL>',
                        credentialsId: '<CRED_ID_IN_JENKINS>'
                    script{
                        //find a device
                        def APP_ID = sh(script:"curl --location -k --request POST 'https://app.mobitru.com/billing/unit/${params.PROJECT_NAME}/automation/api/v1/spaces/artifacts' --header 'x-File-Name: <IPA_OR_APK_FILENAME>' --header 'X-Content-Type: application/zip' --header 'Authorization: Bearer ${params.ACCESS_KEY}' --form 'file=@\"<PATH_TO_IPA_OR_APK_FILE>\"' --form 'checksum=\"None\"' | python -c 'import json,sys;obj=json.load(sys.stdin);sys.stdout.write(obj[\"id\"])'", returnStdout: true)
                        
                        //find a device
                        def DEVICE_UDID = sh(script:"curl --location -k --request GET 'https://app.mobitru.com/billing/unit/${params.PROJECT_NAME}/automation/api/device/${params.DEVICE_PLATFORM}?model=${params.DEVICE_MODEL}' --header 'Authorization: Bearer ${params.ACCESS_KEY}' | python -c 'import json,sys;obj=json.load(sys.stdin);sys.stdout.write(obj[0][\"desiredCapabilities\"][\"udid\"])'", returnStdout: true)

                        //take it
                        sh "curl --location -k --request POST 'https://app.mobitru.com/billing/unit/${params.PROJECT_NAME}/automation/api/device/$DEVICE_UDID' --header 'Authorization: Bearer ${params.ACCESS_KEY}'"

                        //install the app
                        sh "curl --location -k --request GET 'https://app.mobitru.com/billing/unit/${params.PROJECT_NAME}/automation/api/storage/install/${DEVICE_UDID}/${APP_ID}' --header 'Authorization: Bearer ${params.ACCESS_KEY}'"

                        //start tests
                        sh "mvn -B -U -ntp clean test -Dapi.key=${params.API_KEY} -Dproject.name=${params.PROJECT_NAME} -Dappium.hub.hostname=${params.INSTANCE_HOST} -Ddevice.udid='${DEVICE_UDID}'"

                    }
                }
            }
        }
    }
}
image: maven:3-jdk-11

variables:
  ACCESS_KEY:
    description: "ACCESS key"
  BILLING_UNIT:
    description: "Billing unit"


default:
  tags:
    - <RUNNER_TAG>
stages:
  - test

test:
  stage: test
  when: always
  script:
    - 'APP_ID=$(curl --location --request POST "https://app.mobitru.com/billing/unit/$BILLING_UNIT/automation/api/v1/spaces/artifacts" --header "x-File-Name: <IPA_OR_APK_FILENAME>" --header "X-Content-Type: application/zip" --header "Authorization: Bearer $ACCESS_KEY" --form "file=@<PATH_TO_IPA_OR_APK_FILE>" --form "checksum=None" | grep -o -E "\"id\":*.+," | cut -d "\"" -f 4)'
    - 'DEVICE_UDID=$(curl --location --request GET "https://app.mobitru.com/billing/unit/$BILLING_UNIT/automation/api/device/android?model=Pixel" --header "Authorization: Bearer $ACCESS_KEY" | grep -o -E "\"udid\":*.+" | cut -d "\"" -f 4 | head -1)'
    - 'curl --location --request POST "https://app.mobitru.com/billing/unit/$BILLING_UNIT/automation/api/device/$DEVICE_UDID" --header "Authorization: Bearer $ACCESS_KEY"'
    - 'curl --location --request GET "https://app.mobitru.com/billing/unit/$BILLING_UNIT/automation/api/storage/install/$DEVICE_UDID/$APP_ID" --header "Authorization: Bearer $ACCESS_KEY"'
    - echo "START TESTS"
    - mvn -B -U -ntp clean test -Dapi.key=$ACCESS_KEY -Dudid=$DEVICE_UDID -Dproject.name=$BILLING_UNIT
  artifacts:
    when: always
    expire_in: 1 days
    paths:
      - ./target/allure-results

  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
    - if: $CI_PIPELINE_SOURCE == "web"
Scroll to Top