azureyamlplaywrightazure-yaml-pipelines

Playwright Test execution on Azure Windows machine fails in pipeline with error as No test found, It works perfectly with same command


I am executing test cases on microsoft azure pipeline using YAML file. When I execute the test case locally on VS code it works perfectly but when I am executing it on pipeline it shows error as No tests found. Please check below YAML file for reference. Test cases are in tests folder and directory name in playwright is

testDir: './tests',

trigger:
- none

variables:
  - group: 'Common'
  - group: 'Optimizely'

pool:
  name: VMSS-Linux-Pool

resources:
  repositories:
    - repository: PlaywrightFramework
      type: git
      name: PlaywrightFramework

jobs:
- job: Build
  timeoutInMinutes: 0
  
  steps:
  - checkout: self
    displayName: 'Checkout SAGov'

  - checkout: PlaywrightFramework

      - script: |
          mv MavenSyso/* .
          rm -rf MavenSyso
          ls -l
        displayName: 'Prepare folder structure'
    
      - task: NodeTool@0
        inputs:
          versionSpec: '18.x'
        displayName: 'Install Node.js'
    
      - script: |
          npm install
          sudo npx playwright install-deps
          npx playwright install
          npm install -g allure-commandline --save-dev
        displayName: 'Install software'
    
      - script: |
          sudo apt-get update && sudo apt-get install -y jq
          buildID=$(Build.BuildId)
          jq --arg buildID "$buildID" --arg emailPass "$(EmailPassword)" '.buildID = $buildID | .executionENV = "pipeline" | .emailPassword = $emailPass' automation.config.json > temp.json && mv temp.json automation.config.json
        displayName: 'Update Automation config'
    
      - script: |
          export CI=true
          npx playwright test --project chrome
        env:
          SALESFORCE_UAT_BASEURL: $(SALESFORCE_UAT_BASEURL)
          SALESFORCE_API_USERNAME: $(SALESFORCE_API_USERNAME)
          SALESFORCE_API_PASSWORD: $(SALESFORCE_API_PASSWORD)
          SALESFORCE_API_CLIENTID: $(SALESFORCE_API_CLIENTID)
          SALESFORCE_API_CLIENTSECRET: $(SALESFORCE_API_CLIENTSECRET)
          OPTIMIZELY_USERNAME: $(Optimizely_Username)
          OPTIMIZELY_PASSWORD: $(Optimizely_Password)
        displayName: 'Run Playwright Tests'
    
      - task: AzureCLI@2
        displayName: 'Download Allure History from Blob Storage'
        condition: succeededOrFailed()
        inputs:
          azureSubscription: 'Execution'
          scriptType: 'pscore'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az storage blob download-batch --account-name $(StorageAccountName) --source 'reports' --pattern  'Maven_Regression/AutomationReport/history/*.*' --destination '$(Pipeline.Workspace)/s/allure-results'
    
      - script: |
          mv "$(Pipeline.Workspace)/s/allure-results/Maven/AutomationReport/history" "$(Pipeline.Workspace)/s/allure-results"
          rm -rf "$(Pipeline.Workspace)/s/allure-results/MavenSyso_Regression"
        condition: succeededOrFailed()
        displayName: 'Move Allure History Folder and Delete MavenSyso_Regression'
    
      - script: |
          allure generate allure-results --clean -o allure-report/AutomationReport
        condition: succeededOrFailed()
        displayName: 'Generate Allure Report'
    
      - task: PublishPipelineArtifact@1
        displayName: 'Attach Allure Report'
        condition: succeededOrFailed()
        inputs:
          targetPath: '$(Pipeline.Workspace)/s/allure-report'
          artifactName: 'Allure Report'
        
      - task: PublishPipelineArtifact@1
        displayName: 'Attach Allure Results'
        condition: succeededOrFailed()
        inputs:
          targetPath: '$(Pipeline.Workspace)/s/allure-results'
          artifactName: 'allure-results'
    
      - task: AzureCLI@2
        displayName: 'Upload Allure reports'
        condition: succeededOrFailed()
        inputs:
          azureSubscription: 'Maven-NonProd'
          scriptType: 'pscore'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az storage blob delete-batch --account-name "$(StorageAccountName)" --source 'reports' --pattern 'Maven_Regression/*'
            az storage blob upload-batch --account-name $(StorageAccountName) -d reports/Maven -s "$(Pipeline.Workspace)/s/allure-report"

enter image description here

Error Logs:

Generating script. Script contents: shell npx playwright test --project=chrome --grep='@DBVerification' ========================== Starting Command Output =========================== "C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\a_temp\705d70ac-de66-419f-9475-f2622d15d2cc.cmd"" globalVariables.startTime2024-07-24 07:53:56 Error: No tests found

Teardown finished ##[error]Cmd.exe exited with code '1'. Finishing: Run Playwright Tests

enter image description here


Solution

  • Playwright Test execution on Azure Windows machine fails in pipeline with error as No test found

    Based on your description, the playwright project can work fine on your local machine. And the issue exists in Azure Pipelines.

    The cause of the issue could be that the npx playwright test command is running in the folder that doesn't contain the tests.

    To solve this issue, you need to confirm the test folder path in the repo.

    For example:

    enter image description here

    Then you can set the workingDirectory in the Run Playwright Tests task.

    For example:

    - script: |
          npx playwright test --project=chrome --grep='@DBVerification'
      workingDirectory:  $(build.sourcesdirectory)/TestfolderPath
      displayName: 'Run Playwright Tests'