ThatGuyZ
ThatGuyZ

Reputation: 23

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.

Upvotes: 2

Views: 4647

Answers (2)

Michael Freidgeim
Michael Freidgeim

Reputation: 28501

From https://github.com/microsoft/playwright/issues/30890#issuecomment-2124346961

We just released an update to the .NET docs which should make it more clear, does this help you?

I have a related question How to set values in Playwright BrowserContext options from config file?

Upvotes: 1

hardkoded
hardkoded

Reputation: 21695

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.

Upvotes: 0

Related Questions