Rayrun
← Back to Discord Forum

playwright starting up 3 webservers?

Its taking a long time for tests to run because playwright starts up 3 webservers. Can I lower this to 1 and speed up the process?

// playwright.config.ts
const config: PlaywrightTestConfig = {
    webServer: {
        command: 'pnpm run build && pnpm run preview',
        port: 4173
    },
    testDir: 'tests',
    testMatch: /(.+\.)?(test|spec)\.[jt]s/,
    projects: [
        { name: "Firefox Desktop", use: { browserName: "firefox", viewport: { width: 1920, height: 1080 } } }
    ]

};

This thread is trying to answer question "Can I lower the number of webservers Playwright starts up to speed up my tests?"

1 reply

A completely wild guess, but sound more like an issue with the machine/environment for running. Just feels like if one is so worried about one additinal process, they know they are on the very edge of where they can reasonable run stuff.. I know from having an old machine 2 cores 4 max thread, running 2 workers.... Well not a good picture... Got a new machine 20 something threads now, what use to run in 50 minutes is down to under 10, often 5, and a lot less flakiness...

Answer

Configuring Web Server Count in Playwright

Absolutely, you can reduce the number of web servers that Playwright fires up from 3 to 1. This can help speed up your testing process. Here's how you can do it:

Configuring a Single Web Server

You need to define the webServer property in your Playwright config. Here's an example:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  // Your other config...
  
  // Start your local dev server before tests
  webServer: {
    command: 'npm run start',
    url: 'http://ray.run:3000',
    reuseExistingServer: !process.env.CI,
    timeout: 120 * 1000,
  },
});

In this example, command is the shell command to start your local dev server, url is your HTTP server's URL, and reuseExistingServer decides if an existing server should be reused or a new one started.

By setting up only one web server like this, you can reduce overhead and speed up your tests.

Multiple Web Servers

If you need to launch multiple servers or background processes simultaneously for testing, you can provide an array of configurations for multiple web servers.

Remember, reducing the number of web servers might impact certain test scenarios where multiple servers are needed. So, consider any dependencies or interactions between these servers when deciding on their number and configuration.

By customizing your web server configuration in your Playwright tests, you can control the number of servers launched and potentially improve your testing speed.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.