microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
63.95k stars 3.47k forks source link

[Feature] Adding webServer settings for multiple projects #28054

Open alSergey opened 8 months ago

alSergey commented 8 months ago

I have 4 projects. For 2 of them I need the webServer setting, but for the other 2 I don't need it. I would like to be able to add a setting only for specific projects, and not for all at once.

How it works now

const isDevmode = (): boolean => process.env.TEST_TYPE.startsWith('devmode') || false

const config: PlaywrightTestConfig = {
    use: {
        baseURL: 'https://example.ru',
    },
    webServer: isDevmode() ? {
        command: 'npm run start',
        url: 'http://localhost:3000',
        stdout: 'pipe',
        stderr: 'pipe',
    } : undefined,
    projects: [
        {
            name: 'def',
            testMatch: [/** **/],
        },
        {
            name: 'devmode-def',
            testMatch: [/** **/],
            use: {
                baseURL: 'http://localhost:3000',
            },
        },
        {
            name: 'def-n3',
            testMatch: [/** **/],
        },
        {
            name: 'devmode-def-n3',
            testMatch: [/** **/],
            use: {
                baseURL: 'http://localhost:3000',
            },
        },
    ],
}

How I wish it worked

const config: PlaywrightTestConfig = {
    use: {
        baseURL: 'https://example.ru',
    },
    projects: [
        {
            name: 'def',
            testMatch: [/** **/],
        },
        {
            name: 'devmode-def',
            testMatch: [/** **/],
            use: {
                baseURL: 'http://localhost:3000',
            },
            webServer: {
                command: 'npm run start',
                url: 'http://localhost:3000',
                stdout: 'pipe',
                stderr: 'pipe',
            },
        },
        {
            name: 'def-n3',
            testMatch: [/** **/],
        },
        {
            name: 'devmode-def-n3',
            testMatch: [/** **/],
            use: {
                baseURL: 'http://localhost:3000',
            },
            webServer: {
                command: 'npm run start',
                url: 'http://localhost:3000',
                stdout: 'pipe',
                stderr: 'pipe',
            },
        },
    ],
}
slutske22 commented 2 months ago

Need this!