0

As per Playwright .NET documentation, to run tests in Azure Pipelines using headed mode, you need to specify xvfb-run before dotnet test if using a Linux agent.

However, in terms of the YAML configuration, what I have been using is something like this (when I was using Selenium):

- task: DotNetCoreCLI@2
  displayName: 'Run Tests'
  condition: eq('${{ parameters.runTests }}', 'true')
  continueOnError: true
  inputs:
    command: 'test'
    projects: '${{ variables.MyTestProject }}'
    arguments: '--no-restore --logger "console;verbosity=normal" --filter "Category=MyCategory"'
  env:
    URL: ${{ variables.URL }}
    UserName: ${{ variables.UserName }}
    Password: '$(Secret-Password)'

Now I'm migrating to Playwright, this works fine in headless mode. But in headed mode, I can't find a way to pass the xvfb-run command before dotnet test.

I've tried a custom command here, instead of test, and set it to be xvfb-run test (and variations on this). However, the DotNetCoreCLI@2 task appends dotnet to the front of the command. So every time, it breaks.

I've also tried general Bash/script tasks to supply my own command. This appeared to work initially - something like this:

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: xvfb-run dotnet test --no-restore --logger "console;verbosity=normal" --filter "Category=MyCategory"
  env:
    URL: ${{ variables.URL }}
    UserName: ${{ variables.UserName }}
    Password: '$(Secret-Password)'

However, the tests then did not get supplied the variables I need - URL, Username and Password etc. So the tests tried to run in headed mode, but then failed due to null variables.

Anyone have any idea how I can pass xvfb-run and supply variables to my tests in this pipeline setup?


Assuming the variables are being passed in, I wondered if my approach of accessing them in-code was wrong. I've tried 2 approaches - neither of which have worked:

_scenarioContext.Add("UserName", Environment.GetEnvironmentVariable("Applications:UserName"));

And this way:

var config = new ConfigurationBuilder().AddUserSecrets(Assembly.GetExecutingAssembly(), true).AddEnvironmentVariables().Build();
_scenarioContext.Add("UserName", config["Applications:UserName"]);
5
  • What you've shown should work, per learn.microsoft.com/en-us/azure/devops/pipelines/tasks/…
    – jonrsharpe
    Commented Feb 8 at 10:07
  • I've added an update with some further info - I wondered if the issue was actually the way in which I retrieve the variables in my test code.
    – Moorpheus
    Commented Feb 9 at 9:14
  • 1
    Apologies - please can you resubmit them? I must've missed the update.
    – Moorpheus
    Commented Feb 9 at 10:15
  • 1
    Accepted those edits now - sorry about that. Early morning syndrome on a Friday!
    – Moorpheus
    Commented Feb 9 at 10:29
  • I've been able to switch to a Windows agent, so my immediate issue has resolved itself (I no longer need the xvfb-run element). I will keep this question open as I'm still curious about the solution!
    – Moorpheus
    Commented Feb 9 at 15:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.