Rayrun
← Back to Discord Forum

WebServer

Can you have different webServer per project in the .config file or do you need to have different configuration files ?

i.e:

projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'] }, webServer: {}... }, { name: 'firefox', use: { ...devices['Desktop Firefox'] }, webServer: {}... }, ],

This thread is trying to answer question "Can you have different webServer per project in the .config file or do you need to have different configuration files?"

2 replies

If that doesn’t suit your needs then you’ll probably have to have different config files

Answer

Sure, you can definitely set up different web servers for each project in the .config file with Playwright. It's as simple as providing an array of webServer configurations. Each object in this array represents a separate web server or background process you want to launch for your tests.

Here's an example:

module.exports = {
  projects: [
    {
      name: 'Project 1',
      webServer: {
        command: 'npm run start',
        port: 3001,
        timeout: 120 * 1000,
        reuseExistingServer: true,
      },
    },
    {
      name: 'Project 2',
      webServer: {
        command: 'npm run server',
        port: 3002,
        timeout: 120 * 1000,
        reuseExistingServer: true,
      },
    },
  ],
};

In this example, we have two projects each with its own web server. The command property is the shell command to start the server, port is where it's expected to appear, timeout is the duration before timing out, and reuseExistingServer tells Playwright whether to reuse an existing server if one is available.

Remember, each project can have its own configurations like timeouts, retries, and filters for running specific tests. So, you can associate specific projects with their respective web servers by configuring them accordingly.

This way, you can test against different environments or scenarios using distinct web servers without needing separate configuration files. It's all about flexibility with Playwright!

For more details, check out the official Playwright documentation.

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.