playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Get report folder from playwright config file.

Open quldude opened this issue 1 year ago • 5 comments

Need a way to get the folder specified in playwright config file. Eg:

// playwright config ts file
reporter: [['html', { open: 'never', outputFolder: 'reports/playwright' }]],

Folder name extracted would be reports/playwright.

quldude avatar May 15 '23 16:05 quldude

@quldude There is no special API for this, but you can always import your config and read values from it. Let me know if that helps.

const value = await import('./playwright.config').reporter[0][1].outputFolder;

dgozman avatar May 15 '23 18:05 dgozman

I found another way:

onBegin(config: FullConfig, suite: Suite): void {
      for (const [name, options] of config.reporter) {
        if (name === 'html' && options) {
          this.reportFolder = options.outputFolder;
          break;
        }
      }
...

do you know if I use the environment variable PLAYWRIGHT_HTML_REPORT, will that override the folder mentioned in config file?

quldude avatar May 15 '23 20:05 quldude

do you know if I use the environment variable PLAYWRIGHT_HTML_REPORT, will that override the folder mentioned in config file?

PLAYWRIGHT_HTML_REPORT will be used instead of the config, but value in the config itself will not be replaced.

dgozman avatar May 17 '23 20:05 dgozman

Same question, if I want to get the name of the project for judgment, how do I get this configuration

luqy avatar May 18 '23 10:05 luqy

@luqy In your custom reporter, call suite.project(). Inside a test, use test.info().project.

dgozman avatar May 18 '23 15:05 dgozman