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

[Feature]: Playwright vscode plugin run not default playwright command #34311

Open
yonatanai opened this issue Jan 13, 2025 · 5 comments
Open

Comments

@yonatanai
Copy link

🚀 Feature Request

Hi, I would like to know if there is a way to update the playwright vscode plugin so that it can execute different commands when running the tests.
We have a script to run Playwright, which initializes different environmental stuff conditionally before running the Playwright command, and then we use it in our Playwright configuration.
So, when using the plugin, it does not execute our command, which causes problems with our tests.
So i wonder if we could define which command to run when executing the tests.

Example

"scripts": {
"test:e2e": "node ./setup-env.js && npx playwright test"
}

in vscode playwright plugin config
"test-command": "test:e2e"

Motivation

This would help us to define custom scripts and executions for our tests in our organization. Everything works fine executing the tests with the regular playwright commands, but the vscode extension is not working that way.

@davidizac
Copy link
Contributor

I would love to have this feature as well!!

@yury-s
Copy link
Member

yury-s commented Jan 13, 2025

Can the setup code run as part of globalSetup instead?

@yonatanai
Copy link
Author

Thanks for the response, @yury-s!
Specifically, we wrapped the playwright CLI with a custom one to have a more opinionated and custom in-house experience ( it's still in development. We are migrating the old system to a new one, which will be mainly based on Playwright ).
The idea was first to make it as backward compatible as possible because we have different flags and commands from the legacy system that change the flows and how the tests should be executed.

Unfortunately, it worked well until we understood it would not work with the playwright vscode plugin.

It may be a very uncommon use case, and we should not use the CLI like this, although it helps with our developer experience, quick setup, backward compatibility, etc.

Part of our goal in this migration was to improve the developer experience. This is why we want the plugin to work, and we want to know if it's possible to customize the commands it executes or if it's something that is not supported.

( BTW, it might be nice also for users that have different scripts that execute the playwright command with other flags )

@yonatanai
Copy link
Author

I see in the implementation that it searches for the CLI command and executes it.
https://github.com/microsoft/playwright-vscode/blob/main/src/playwrightFinder.ts#L41
https://github.com/microsoft/playwright-vscode/blob/179f19d556cc59751b56cc27a779bb6cd233f04d/src/playwrightTestCLI.ts#L116
Theoretically, it would work for our custom CLI with some tweaks, but executing scripts will require more changes to the current implementation.

@yury-s
Copy link
Member

yury-s commented Jan 14, 2025

Can you tell us a bit more about what the wrapper script does before calling npx playwright test?

We don't support custom playwright command in VSCode extension, but there are multiple ways to extend playwright itself where you can call the code that initializes the environment (you'll need extract it into a separate script or something, so that it does not call npx playwright test when already called by playwright):

  • You can call the setup logic from globalSetup
  • You can call an arbitrary shell command as a webServer
  • If those don't work for some reason, you can add corresponding javascript code to playwright.config.ts and run shell commands from there if need be. Just make sure that you only run it when process.env.TEST_WORKER_INDEX === undefined; to avoid running it in the test workers.

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

No branches or pull requests

3 participants