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
66.39k stars 3.63k forks source link

[BUG] Error failed to launch: Error: spawn /bin/sh ENOENT #28446

Closed karpikpl closed 10 months ago

karpikpl commented 10 months ago

Context:

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:

Describe the bug

Config file

// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';

/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */
require('dotenv').config();

/**
 * See https://playwright.dev/docs/test-configuration.
 */
export default defineConfig({
  testDir: '.',
  /* Run tests in files in parallel */
  fullyParallel: true,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: [
    // ['line'],
    // ['playwright-trx-reporter', { outputFile: "./test-results/output.trx" }],
    ['html', { open: 'never' }],
    ['junit', { outputFile: './test-results/playwright-results.xml' }]
  ],
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Base URL to use in actions like `await page.goto('/')`. */
    baseURL: process.env.TEST_URL || 'http://localhost:4200',

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'retain-on-failure',
    screenshot: 'on'
  },

  /* Configure projects for major browsers */
  projects: [
    // Setup project
    {
      name: 'setup-ad-user', testMatch: '**/smoke-tests/auth.setup.js',
      use: {
        ...devices['Desktop Edge'],
        channel: 'msedge',
      }
    },

    {
      name: 'edge-smoke-ci',
      testMatch: '**/smoke-tests/*.spec.js',
      use: {
        ...devices['Desktop Edge'],
        channel: 'msedge',
        // Use prepared auth state.
        storageState: 'playwright/.auth/user.json',
      },
      dependencies: ['setup-ad-user'],
    },

    {
      name: 'edge-all',
      testMatch: '**/tests/*.spec.js',
      use: {
        ...devices['Desktop Edge'],
        channel: 'msedge',
        // Use prepared auth state.
        storageState: 'playwright/.auth/user.json',
      },
      dependencies: ['setup-ad-user'],
    },
});

Test file (self-contained)

import { test, expect } from '@playwright/test';

test('foo', async ({ browser, browserName }, testInfo) => {

    const page = await browser.newPage();
});

Steps

Expected

Test runs

Actual

image

karpikpl commented 10 months ago

Ok, so this happens when there are multiple profiles and one of the has this section

  /* Run your local dev server before starting the tests */
  webServer: {
    cwd: 'web-app',
    command: 'npx http-server -p 4200',
    url: 'http://localhost:4200',
    timeout: 240000,
    reuseExistingServer: !process.env.CI,
    stderr: 'pipe',
    stdout: 'pipe'
  },

that other profile get selected by DEFAULT (!) which causes this error image

shouldn't default profile be playwright.config.ts ?

pavelfeldman commented 10 months ago

shouldn't default profile be playwright.config.ts

Default profile is the first profile in the list when you first open VS Code.

karpikpl commented 10 months ago

ok, makes sense