Search code examples
c#.netconfigurationplaywrightplaywright-sharp

How do you create a global configuration for Playwright .NET?


I am planning to use Playwright .NET to perform automated UI testing in a C# dotnet project. The issue is that I would like to have global configuration that can be set rather than needing to define the same settings repeatedly in the context of each test, but I cannot seem to find any working examples.

The documentation at playwright.dev implies that I should be able to simply include a "playwright.config.js" file at the root of the project, but no clear definition of what the content of that file should be. I have experimented with the example provided for Playwright Node.js, using:

import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
    use: {
        // Browser options
        headless: false,
        slowMo: 50,

        // Context options
        viewport: { width: 1280, height: 720 },
        ignoreHTTPSErrors: true,

        // Artifacts
        screenshot: 'only-on-failure',
        //video: 'retry-with-video',
  },
  outputDir: "C:\\stuff\\screenshots",
  preserverOutput: 'always',
  quiet: false,

};
export default config;

However, these settings do not seem to be applied and there is no indication that the playwright.config.js file is either loading or failing.

Any help or a simple example to get me pointed in the right direction would be much appreciated.


Solution

  • LaunchAsync expects a BrowserTypeLaunchOptions class. You could have that object serialized in a JSON file, parse it and pass that options instance as an argument.