Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] playwright object not available in the browser devtools console when running from VS Code in "Debug Test" mode #21429

Open
1 task done
segevfiner opened this issue Mar 6, 2023 · 5 comments

Comments

@segevfiner
Copy link
Contributor

segevfiner commented Mar 6, 2023

System info

  • Playwright Version: v1.31.2
  • Operating System: macOS 13.2.1
  • Browser: Chromium
  • Other info: VS Code extension v1.0.7

Source code

  • I provided exact source code that allows reproducing the issue locally.

Link to the GitHub repository with the repro

Just a vanilla new pnpm create vue@3 project with playwright.

Config file

import type { PlaywrightTestConfig } from '@playwright/test'
import { devices } from '@playwright/test'

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

/**
 * See https://playwright.dev/docs/test-configuration.
 */
const config: PlaywrightTestConfig = {
  testDir: './e2e',
  /* Maximum time one test can run for. */
  timeout: 30 * 1000,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 5000
  },
  /* 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: 'html',
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
    actionTimeout: 0,
    /* Base URL to use in actions like `await page.goto('/')`. */
    baseURL: 'http://localhost:5173',

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on-first-retry',

    /* Only on CI systems run the tests headless */
    headless: !!process.env.CI
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome']
      }
    },
    {
      name: 'firefox',
      use: {
        ...devices['Desktop Firefox']
      }
    },
    {
      name: 'webkit',
      use: {
        ...devices['Desktop Safari']
      }
    }

    /* Test against mobile viewports. */
    // {
    //   name: 'Mobile Chrome',
    //   use: {
    //     ...devices['Pixel 5'],
    //   },
    // },
    // {
    //   name: 'Mobile Safari',
    //   use: {
    //     ...devices['iPhone 12'],
    //   },
    // },

    /* Test against branded browsers. */
    // {
    //   name: 'Microsoft Edge',
    //   use: {
    //     channel: 'msedge',
    //   },
    // },
    // {
    //   name: 'Google Chrome',
    //   use: {
    //     channel: 'chrome',
    //   },
    // },
  ],

  /* Folder for test artifacts such as screenshots, videos, traces, etc. */
  // outputDir: 'test-results/',

  /* Run your local dev server before starting the tests */
  webServer: {
    /**
     * Use the dev server by default for faster feedback loop.
     * Use the preview server on CI for more realistic testing.
    Playwright will re-use the local server if there is already a dev-server running.
     */
    command: process.env.CI ? 'vite preview --port 5173' : 'vite dev',
    port: 5173,
    reuseExistingServer: !process.env.CI
  }
}

export default config

Test file (self-contained)

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

// See here how to get started:
// https://playwright.dev/docs/intro
test("visits the app root url", async ({ page }) => {
  await page.goto("/");
  await expect(page.locator("div.greetings > h1")).toHaveText("You did it!");
});

Steps

  • Set a breakpoint in some line in the test after goto.
  • Run the test using debug test in VS Code.
  • Open the browser devtools.
  • Check for the global playwright object.

If you check process.env.PWDEBUG in the debug console, it is set...

Expected

It is there.

Actual

It is not there

@segevfiner segevfiner changed the title [BUG] playwright object not available in the browser devtools console despite the extension setting PWDEBUG=console [BUG] playwright object not available in the browser devtools console when running from VS Code in "Debug Test" mode. Mar 6, 2023
@segevfiner segevfiner changed the title [BUG] playwright object not available in the browser devtools console when running from VS Code in "Debug Test" mode. [BUG] playwright object not available in the browser devtools console when running from VS Code in "Debug Test" mode Mar 6, 2023
@mxschmitt
Copy link
Member

This should be fixed in the extension version 1.0.8, please re-test.

@segevfiner
Copy link
Contributor Author

I just tried. Doesn't work with "Show browser" unticked in the extension and the headed browser launched when you debug a test (Similar to #20003):

image

image

But it does work with "Show browser" ticked and debugging a test.

@mxschmitt
Copy link
Member

How do you get a browser window if you have "Show browser" unticked? Do you manually set headless: false inside your playwright.config? I think its then as designed, since "Show browser" is the recommended way of getting a headed instance.

@segevfiner
Copy link
Contributor Author

"Debug test" mode (Debugging a test with the VS Code debugger) pops up a browser even with "Show browser" unticked, and I remember reading that that's intended.

@mxschmitt
Copy link
Member

I was able to reproduce. Reason is that that we use a reused browser which does not know about the PWDEBUG=console env var.

Will think about a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants