DEV Community

Cover image for Playwright VS Code Extension, projects and global setup
Debbie O'Brien for Playwright end to end Testing

Posted on • Updated on

Playwright VS Code Extension, projects and global setup

With the latest release of the VS Code Extension, you can now easily select which projects to run your tests on as well as choose to run your setup tests only once. Make sure you have the latest version of the extension installed, which is v1.1.* as well as the latest version of Playwright which is v1.44.*.

To update to the latest version of Playwright, run the following command:

npm install -D @playwright/test@latest
Enter fullscreen mode Exit fullscreen mode

Also download new browser binaries and their dependencies:

npx playwright install --with-deps
Enter fullscreen mode Exit fullscreen mode

Opening the testing sidebar

The testing sidebar can be opened by clicking on the testing icon in the activity bar. This will give you access to the test explorer, which will show you all the tests in your project as well as the Playwright sidebar which includes projects, settings, tools and setup.

Testing Sidebar

Running tests on multiple projects

The first section in the Playwright sidebar is the projects section. Here you can see all your projects as defined in your Playwright config file. The default config when installing Playwright gives you 3 projects, Chromium, Firefox and WebKit. The first project is selected by default.

Projects section in VS Code extension

To run tests on multiple projects, select each project by checking the checkboxes next to the project name. Then when you run your tests from the sidebar or by pressing the play button next to the test name, the tests will run on all the selected projects.

Selecting projects to run tests on

You can also individually run a test on a specific project by clicking the grey play button next to the project name of the test.

Running a test on a specific project

Multiple configurations

If your project contains more than one playwright configuration file, you can switch between them by first clicking on the gear icon in the top right corner of the Playwright sidebar. This will show you all the configuration files in your project. Select the configuration files you want to use by checking the checkbox next to each one and clicking on the 'ok' button.

Selecting a configuration file

You will now have access to all your tests in the test explorer. To run a test click on the grey triangle next to the file or project name.

Switching between configuration files

To run all tests from all configurations click on the grey triangle at the top of the test explorer.

Running all tests from all configurations

To choose a configuration file to work with simply toggle between them by clicking on the configuration file name in the Playwright sidebar. Now when you use the tools, such as Record a test, it will record a test for the selected configuration file.

Recording a test for a specific configuration file

You can easily toggle back and forth between configurations by clicking on the configuration file name in the Playwright sidebar.

Project Dependencies

You can use project dependencies to run tests that depend on other tests. This is useful for setup tests such as logging in to a website.

Running setup tests

To run your setup tests select the setup project, as defined in your configuration file, from the project section in the Playwright sidebar. This will give you access to the setup tests in the test explorer.

setup tests in vscode

When you run a test that depends on the setup tests, the setup test will run first. Each time you run the test, the setup test will run again.

running setup tests in vscode

Running setup tests only once

To run the setup test only once, deselect it from the projects section in the Playwright sidebar. The setup test is now removed from the test explorer. When you run a test that depends on the setup test, it will no longer run the setup test, making it much faster and therefore a much better developer experience.

deselecting setup tests in vscode

Global Setup

Global setup tests are run when you execute your first test. This runs only once and is useful for setting up a database or starting a server. You can manually run a global setup test by clicking the Run global setup option from the Setup section in the Playwright sidebar. You can also run global teardown tests by clicking the Run global teardown option.

Global setup will re-run when you debug tests as this ensures an isolated environment and dedicated setup for the test.

running global setup

Check out the video

Useful links

Top comments (0)