Steve French
Steve French

Reputation: 991

How can I save screenshots and videos as attachments in Azure Build Pipeline with TestCafe and Yaml?

I am trying to create a build pipeline in Azure Devops that

  1. runs tests created in TestCafe Studio
  2. Saves screenshots on error, and saves videos of every test
  3. Saves videos of the test runs
  4. Publishes the results of the testing to Test Runs
  5. Publishes the screenshots and videos as attachments to both the rest results in the build pipeline and in the resulting test runs

For the life of me, neither me, nor my team can figure out how to do that - we are currently in a state of saving test runs, and saving videos and screenshots as artifacts, but none of them are attached to the test results in either the builds or test runs - here is an example of one of our YAML files

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: NodeTool@0
  inputs:
    # Replace '10.14' with the latest Node.js LTS version
    versionSpec: '10.14'
  displayName: 'Install Node.js'

- script: npm install -g testcafe testcafe-reporter-xunit
  displayName: 'Install TestCafe'

- script: npm install --save @ffmpeg-installer/ffmpeg
  displayName : Install FFMpeg

- script: npm install testcafe-reporter-nunit3
  displayName: Install NUnit

- script: testcafe chrome **/Tests/**/* -S -s takeOnFails=true --video --reporter spec,xunit:report.xml
  displayName: Run tests - Save screenshots and videos
  continueOnError: true 

- task: PublishTestResults@2
  displayName: Publish test results
  continueOnError: true
  inputs:
    testResultsFiles: '**/report.xml'
    searchFolder: $(System.DefaultWorkingDirectory)
    testResultsFormat: 'NUnit'
    publishRunAttachments: true
    testRunTitle: "Task Results"
    failTaskOnFailedTests: false

- task: CopyFiles@2
  inputs:
    sourceFolder: '$(Build.SourcesDirectory)'
    contents: '**/?(*0.png|*1.png|*2.png|*3.png|*4.png|*5.png|*6.png|*7.png|*8.png|*9.png|*.mp4)'
    targetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: Saved failure screenshots

There seems to be some obvious step that we're missing, but none of us can find it, and after exhaustive searches none of us can find a solution. What are we missing?

Upvotes: 4

Views: 3252

Answers (1)

vasily.strelyaev
vasily.strelyaev

Reputation: 838

I have prepared a sample repository. Please take a look: testcafe-azure-pipelines-example. The test result page shows a video and screenshot in the Attachments tab.

Upvotes: 6

Related Questions