azure-devopsplaywrightallureazure-automationplaywright-test

Integrating Allure Reporting into Playwright Tests Azure Pipeline


I am practicing with Playwright automation and learning to integrate it with CI/CD pipelines in Azure. I have managed to create a Repo and Pipeline in Azure that runs my Playwright code, but I am a little stuck on getting Allure reporting to work

This is my yaml file for the azure pipeline, I have added in the Allure steps as follows:

trigger:
- none

pool: customagent
  

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '18'
  displayName: 'Install Node.js'
- script: npm ci
  displayName: 'npm ci'
- script: npx playwright install --with-deps
  displayName: 'Install Playwright browsers'
- script: npm run regression
  displayName: 'Run Playwright tests' 
- script: npx playwright test --reporter=line,allure-playwright
  displayName: 'Use Allure reports'
- script: npm run GenReport
  displayName: 'Generate Allure reports and clean'
- task: qameta.allure-azure-pipelines.PublishAllureReport.PublishAllureReport@1
  inputs:
    testResultsDir: 'allure-results'
    reportName: 'Report'
  env:
    CI: 'true'

This is what is in my Playwright package.json file, I have added custom scripts:

{
  "name": "playwright",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "regression": "npx playwright test",
    "GenReport": "npx allure generate ./allure-results --clean",
    "Open Allure Reports": "allure open ./allure-report"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@playwright/test": "^1.43.1",
    "@types/node": "^20.7.1",
    "@zerostep/playwright": "^0.1.5",
    "allure-playwright": "^2.15.1"
  },
  "dependencies": {
    "@cucumber/cucumber": "^10.4.0"
  }
}

When I run the pipeline, it ends up opening the html reporter and then remains on that step. I'm really not sure what to do from this point, I have installed the necessary marketplace extension for the Allure report viewer, which I used in my yaml file

enter image description here


Solution

  • I can reproduce the same issue when running the npx playwright test.

    enter image description here

    To solve this issue, you can add an Pipeline variable: CI:true at the root level of the Pipeline.

    For example:

    trigger:
    - none
    
    pool: customagent
    
    variables:
      CI: true 
    
    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '18'
      displayName: 'Install Node.js'
    - script: npm ci
      displayName: 'npm ci'
    - script: npx playwright install --with-deps
      displayName: 'Install Playwright browsers'
    - script: npm run regression
      displayName: 'Run Playwright tests' 
    - script: npx playwright test --reporter=line,allure-playwright
      displayName: 'Use Allure reports'
      continueOnError: true
    - script: npm run GenReport
      displayName: 'Generate Allure reports and clean'
      continueOnError: true
    - task: qameta.allure-azure-pipelines.PublishAllureReport.PublishAllureReport@1
      inputs:
        testResultsDir: 'allure-results'
        reportName: 'Report'
      continueOnError: true
      env:
        CI: 'true'
    

    Or you can add environment variable to the script task:

    For example:

    - script: npm run regression
      displayName: 'Run Playwright tests' 
      env:
        CI: true
    

    Then it will continue to run the next tasks.