Home > OS >  How to run Playwright in headless mode?
How to run Playwright in headless mode?

Time:11-29

I created a new Vue app using npm init vue@latest and selected Playwright for e2e tests. I removed firefox and webkit from projects in the playwright.config.ts file, so it will only use chromium.

Running npm run test:e2e works fine, the process exists with a success code.

When forcing the tests to fail by modifying the ./e2e/vue.spec.ts file the output is

enter image description here

but the process does not exit with an error code, it still opened browser windows and so CI environments would freeze.

I searched the docs for a specific flag e.g. "headless" and tried --max-failures -x but that didn't help.

How can I tell Playwright to run in headless mode and exit with an error code when something failed?

CodePudding user response:

It's serving the html report and asking to press 'Ctr C' to quite.You can disable it using below configuration.

// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  reporter: [ ['html', { open: 'never' }] ],
};
export default config;

Refer - Report Doc

Issue - https://github.com/microsoft/playwright/issues/9702

CodePudding user response:

To add to the answer above, you can set headless: true in the 'use' block of the config which is above the projects block. Anything set at that level will apply to all projects unless you specifically override the setting inside a project specific area:

// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  reporter: [ ['html', { open: 'never' }] ],
  use: {
    headless: true,
  },
  projects: [
    {
      name: 'chromium',
      use: {
        browserName: 'chromium',
      },
    },
  },
};
export default config;
  • Related