Search code examples
androidazure-devopsandroid-espressobrowserstack

Building & uploading espresso tests to Browserstack using AzureDevOps


I'm following this link on how to run an automated espresso test on Browserstack. I want to upload the required APKs mentioned there to Browserstack using an azure pipeline I've created. I've managed to build and upload my app's APK as you can see in the .yaml file below but I can't figure out how to generate a test APK for my Test class through azure so that I can upload it to BrowserStack. The guide above mentions uploading a test-suite, do they mean the APK generated when building and running a Test class file? If so, wouldn't I need to change the build configuration through azure and then build again?

pool:
  vmImage: ubuntu-latest

# build apk
- task: Gradle@2
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx3072m'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleDebug'

# retain the apk artifact
- task: CopyFiles@2
  inputs:
    contents: '**/*.apk'
    targetFolder: '$(build.artifactStagingDirectory)'

- task: BrowserStackConfig@0
  inputs:
    BrowserStackServiceEndPoint: 'BrowserStack connection'

# Upload apk to BrowserStack
- task: BrowserStackAppUploader@0
  inputs:
    appPath: '/my/path/debug/presentation-google-debug.apk'
    appCustomId: 'myID'
  displayName: 'Uploading apk to BrowserStack'

# build and upload test apk here

# post test results
- task: BrowserStackResults@0

Solution

  • You'll need to add the steps to build the test suite APK as per your setup.

    For uploading the test suite and triggering the test, you can use something like:

    - script: |
    
       echo "upload test suite"
    
       curl -u "username:access_key" \
       -X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/test-suite" \
       -F "file=@/path/to/app/file/Application-debug-test.apk" \
       -F "custom_id=SampleTest"
     
       echo "triggering test" 
       
       curl -u "username:access_key" \
       -X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
       -d '{"app": "myID", "testSuite": "SampleTest", "devices": ["Samsung Galaxy S9 Plus-9.0"]}' \
       -H "Content-Type: application/json" 
    
      displayName: 'uploading test suite and triggering test'