Running Playwright dotnet tests on Azure DevOps

1.5k views Asked by At

I'm trying to execute Playwright dotnet tests with Nunit framework on Azure DevOps. I'm unable to execute testcases as and when I try to install playwright as a part of pipeline, there is an error thrown and build gets failed with the following message

Couldn't find project using Playwright. Ensure a project or a solution exists in D:\a\1\s, or provide another path using -p. Below is my azure pipeline steps, Can someone please help me where exactly the issue is and I have tried both Windows and latest Ubuntu agents

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-latest'

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

steps:
- task: UseDotNet@2
  displayName: 'Install .NET'
  inputs:
    packageType: 'sdk'
    version: '6.0.x'
    installationPath: $(Agent.ToolsDirectory)/dotnet
    includePreviewVersions: true

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'new'
    arguments: 'tool-manifest'
- task: DotNetCoreCLI@2
  displayName: 'Installing Playwright Cli'
  inputs:
    command: 'custom'
    custom: 'tool'
    arguments: 'install Microsoft.Playwright.CLI'

- task: DotNetCoreCLI@2
  displayName: 'Building tests project'
  inputs:
    command: 'build'
    projects: '**/*Tests*.csproj'

- task: DotNetCoreCLI@2
  displayName: Run Playwright Install
  inputs:
    command: custom
    custom: 'tool '
    arguments: run playwright install

- task: DotNetCoreCLI@2
  displayName: 'Run tests'
  inputs:
    command: 'test'
    projects: '**/*Tests*.csproj'
    testRunTitle: 'new pipeline'
1

There are 1 answers

1
Kwame On

With Visual Studio projects you can add post-build-events, which will run on you dev machine and in the Azure Pipeline during a build (tested with VSBuild@1)

Example using the VS UI: (you will need to adjust paths for ubuntu)

echo $(TargetDir).playwright\node\win32_x64\playwright.cmd install
$(TargetDir).playwright\node\win32_x64\playwright.cmd install
echo Done

or adding directly to a .csproj

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="echo $(TargetDir).playwright\node\win32_x64\playwright.cmd install;$(TargetDir).playwright\node\win32_x64\playwright.cmd install;echo Done" />
  </Target>