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
67.12k stars 3.69k forks source link

[Bug]: #33642

Closed machineghost closed 5 days ago

machineghost commented 5 days ago

Version

1.44.0

Steps to reproduce

Repro repo: https://github.com/machineghost/playwright-repro

  1. Run tests at the command line
  2. Tests run fine
  3. Run test inside VS Code using the extension
  4. I get an error about my storage state file path, Error: Error reading storage state from .auth/user.json:

Expected behavior

I should be able to use the VS Code extension

Actual behavior

In the VS Code "Test Results" tab:

Running 1 test using 1 worker
  1) [chromium] › system.spec.ts:5:3 › Create › Can create a system ────────────────────────────────

    Error: Error reading storage state from .auth/user.json:
    ENOENT: no such file or directory, open '.auth/user.json'

  1 failed
    [chromium] › system.spec.ts:5:3 › Create › Can create a system ─────────────────────────────────

Additional context

In my auth.setup.ts file, if I change this line:

const authFile = ".auth/user.json";

to:

const authFile = "../.auth/user.json";

I still get the (exact same) error. If I instead change my playwright.config.ts from:

use: { /* ... */storageState: ".auth/user.json",

to:

use: { /* ... */storageState: "../.auth/user.json",

I get almost the same error, but with the ../:

 Error: Error reading storage state from ../.auth/user.json

Those are the only two references to that file, so it seems clear that that the problem is with the Playwright config file.

However, I have no idea how to fix it, as adding a ../ didn't help, and the path is perfectly correct for non-VS-Code-based test runs.

Environment

System:
    OS: Linux 5.15 Linux Mint 21.3 (Virginia)
    CPU: (8) x64 Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
    Memory: 15.88 GB / 23.38 GB
    Container: Yes
  Binaries:
    Node: 20.3.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.6.7 - /usr/local/bin/npm
  IDEs:
    VSCode: 1.95.3 - /usr/bin/code
  Languages:
    Bash: 5.1.16 - /usr/bin/bash
  npmPackages:
    @playwright/test: ^1.44.0 => 1.44.0
pavelfeldman commented 5 days ago

You can't use relative names because they are resolved relative to cwd in Node that you don't control in case of VSCode. Always resolve relative file paths.