playwright: [Bug]: playwright tests do not show in test tab in vscode, no errors, cli works

Edit from maintainers

Please read the comment in https://github.com/microsoft/playwright/issues/30390#issuecomment-2635028325 for debugging extension issues. Thank you!


Version

1.43.1

Steps to reproduce

  1. I suspect, either have a playwright.config.ts in a sub-folder. Or have some possible problem with the config file. Not sure the exact way to reproduce since the problem seems to be with reporting some problem, I don’t know what that problem is…
  2. In vscode, open the testing tab.
  3. It shows no extensions loaded. (playwright extension IS installed and at latest version) Hit reload it tries to load playwright for a second then goes away.

Opening up developer tools (help > toggle developer tools) I see this:

  log.ts:439   ERR Cannot read properties of undefined (reading 'line'): TypeError: Cannot read properties of undefined (reading 'line')
    at $e._updateDiagnostics (/Users/ata224/.vscode/extensions/ms-playwright.playwright-1.0.22/out/extension.js:97:1287)
    at $e._reportConfigErrorsToUser (/Users/ata224/.vscode/extensions/ms-playwright.playwright-1.0.22/out/extension.js:93:6859)
    at $e._rebuildModel (/Users/ata224/.vscode/extensions/ms-playwright.playwright-1.0.22/out/extension.js:93:6794)
    at r.$refreshTests (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:8490)

Judging from context in the trace dump, it sounds like it is trying to report a problem with the config file, but that the error data is undefined for some reason.

Expected behavior

I expect to see an error saying why playwright could not load. Or that some problem happened. Any error at all (outside of the developer window where no one looks).

Actual behavior

It quietly acts like the extension is not there, no errors or anything.

Additional context

So even if this is caused by config error, it should have graceful failure to tell me that. Thinking back, I don’t know that I’ve ever seen an error from playwright extension, it just plain worked or did not work. For example, we also use vitest (extension disabled to eliminate some bug with interaction) - if we have it set up wrong somehow, it tells you in an error as soon as you open the test tab. I have not seen that from playwright.

Also note that I had it working with this project probably a few weeks ago (last time I tried using the extension). Since then we’ve updated playwright versions, updated node versions on the project, not sure if that is related.

Note: I had to cd into tests/ folder to run npx envinfo --preset playwright it did not find it in base folder.

Environment

System:
    OS: macOS 14.4.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 1.41 GB / 32.00 GB
  Binaries:
    Node: 18.20.1 - ~/.nvm/versions/node/v18.20.1/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v18.20.1/bin/npm
    pnpm: 9.0.1 - /usr/local/bin/pnpm
  IDEs:
    VSCode: 1.88.1 - /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @playwright/test: ^1.43.1 => 1.43.1 
    playwright-bdd: ^6.2.0 => 6.2.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 23 (5 by maintainers)

Most upvoted comments

Side note, I was getting the same “No tests have been found in this workspace yet.”

Turns out I had accidentally un-ticked chromium (firefox and webkit) from the PROJECTS section under PLAYWRIGHT in the nav.

So with no browser engine selected we also get this mysterious error. Maybe the error could suggest this as a possible issue when no PROJECTS are selected?

I am not seeing anything under projects section sadly. image

If anyone finds this issue from searching, the issue for me was the node version.

In the OUTER directory (top-level project directory, not where my playwright project is contained), my default node version was being used (in my case, node 12). So, opening code . in that directory was using that node version, and the VS Code extension was NOT working - playwright extension could not find any tests, and complained Internal error: unable to connect to the test server.

In my INNER playwright directory, node 20 was being used. If I opened code . in that directory, nvm was auto-switching the node version due to my project having .nvmrc or .node-version file present. The VS Code extension was working.

If I switched to node 20 in the OUTER directory (like nvm use 20), then opened code (code .), the extension finally worked from the top-level directory.

cc @yury-s since I browsed several threads about this issue and saw you in them all 😃

Side note, I was getting the same “No tests have been found in this workspace yet.”

Turns out I had accidentally un-ticked chromium (firefox and webkit) from the PROJECTS section under PLAYWRIGHT in the nav.

So with no browser engine selected we also get this mysterious error. Maybe the error could suggest this as a possible issue when no PROJECTS are selected?

Holy smokes, this completely solved it for me too. What a trek across the internet just to discover one problematically unchecked checkbox. Thank you @wolispace! 🫶🏽

I figured it out! And I know how to reproduce!

How to Reproduce

  1. In your environment, use NVM to set up your default node to version 20.6.1 - change the alias for default to that version (maybe you are familiar and know where this is going?)
  2. Start up vscode. Verify it is using 20.6.1 by looking at “about vscode”.
  3. Open the test tab. It will not find tests. Also will not give any clues as to why, no errors in the console, output window, debug window… And using very very latest version in main, you don’t even see any in the developer debug window. (Maybe the latest version of main did fix something because that other error did go away, but things still didn’t work)

Story time! feel free to skip down if you want, I won’t be sad. Not too sad anyways… 🥺

So there I was, tracking down where it loaded files in the extension, and tracked it to:

https://github.com/microsoft/playwright-vscode/blob/bc096a5c26e1bcec1bbb802c8ff362bb11e1939a/src/playwrightTestCLI.ts#L50-L56

(weird it doesn’t show preview, thought github showed code preview even across repos? oh well)…

Anyways, I added a console log on output there and it had

{
"error": "TypeError [ERR_INVALID_ARG_TYPE]: The \"parentURL\" argument must be of type string or an instance of URL. Received an instance of Object"
}

That’s odd, I had to console log it, I guess the main extension just quietly eats the error instead of trying to report it. Maybe it assumes “any error” or maybe anything not expected, means no tests were found or something? I didn’t bother following the code past that to see why though.

Anyways, now I had something to google! And I came across this issue about the exact same error happening with playwright running on the command line. It is closed, with problem being the node version and solution to upgrade node.

So I opened “about vscode”, and sure enough, it was using that same buggy node version 20.6.1. After more googling, I found vscode uses whatever node it finds in the path. So in nvm I updated the default to use the latest lts/iron (currently 20.12.2), then quit VSCode and re-started, and 🎉 it works!!

Suggestion of Solution (bug/feature fix request?)

Why anything at all? This is very hard to troubleshoot. There is 0 clue at all, no errors or anything. And playwright runs just fine on the command line because I’m using nvm and a .nvmrc file that makes it use a specific version of node when I’m in this folder. But the problem was internally vscode just uses whatever node it finds in the path.

Sure normally if it doesn’t work on the command line people would get that working before trying to get the extension working. But in this case, like I said it did work. And I would doubt that I am the only one with this setup, this is a common practice to pin a project to a specific node version by using .nvmrc. So I’m saying this is likely a problem for others as well, but perhaps like me they just run it on the command line when the extension is being finicky. (and miss out on all the awesome extra stuff the extension can do for you!)

Anyways that’s my spiel, sorry if you were already convinced, you hopefully skipped down to my suggestion:

Suggestion: When there is some error / unexpected result from the command line, echo that out, even if it is sent to somewhere like the output window. If that were done I would have seen it, googled the error, and came to that issue I pointed to and figured out how to fix. As it is, nothing gets to somewhere visible to the end user, it just quietly eats the error and says it can’t find any tests.

I do see how it does the this._log(... “for tests”, maybe it could do something like that for the result as well but use whatever mechanism you use to get it showing in the “output” window… For some reason playwright doesn’t show up in the dropdown in the “output” window. Maybe it should start so it can print out sometimes useful info like this.