Giter Site home page Giter Site logo

microsoft / playwright-vscode Goto Github PK

View Code? Open in Web Editor NEW
313.0 15.0 55.0 1.94 MB

Playwright Test Visual Studio Code integration

Home Page: https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright

License: Apache License 2.0

JavaScript 1.70% TypeScript 97.85% CSS 0.45%
playwright vscode vscode-extension testing typescript

playwright-vscode's Introduction

Playwright Test for VS Code

This extension integrates Playwright into your VS Code workflow. Here is what it can do:

example test in vs code

Requirements

This extension works with Playwright version v1.19+ or newer.

If you are looking for the old extension that supported Playwright v1.14+, switch to v0.0.9 of this extension manually. Having said that, we highly recommend using the latest version of [Playwright Test]!

Install Playwright

If you don't have the Playwright NPM package installed in your project, or if you are starting with a new testing project, the "Install Playwright" action from the command panel will help you get started.

Install Playwright

Pick the browsers you'd like to use by default, don't worry, you'll be able to change them later to add or configure the browsers used. You can also choose to add a GitHub Action so that you can easily run tests on Continuous Integration on every pull request or push.

Choose browsers

The extension automatically detects if you have Playwright installed and loads the browsers, known as Playwright projects, into Visual Studio Code. By default it will select the first project as a run profile. Inside the test explorer in VS Code you can change this behavior to run a single test in multiple or different browsers.

select-profile

Run tests with a single click

Click the green triangle next to the test you want to run. You can also run the test from the testing sidebar by clicking the grey triangle next to the test name.

runtest

Run Multiple Tests

You can use the Testing sidebar to run a single test or a group of tests with a single click. While tests are running, the execution line is highlighted. Once the line has completed, the duration of each step of the test is shown.

runtests


Show browsers

Check the "show browsers" checkbox to run tests with the browser open so that you can visually see what is happening while your test is running. Click on "close all browsers" to close the browsers.

show-browser


Pick locators

Click the "pick locator" button and hover over the browser to see the locators available. Clicking an element will store it in the locators box in VS Code. Pressing enter will save it to the clip board so you can easily paste it into your code or press the escape key to cancel.

pick-locator


Debug step-by-step, explore locators

Right click and start breakpoint debugging. Set a breakpoint and hover over a value. When your cursor is on some Playwright action or a locator, the corresponding element (or elements) are highlighted in the browser.

debugging


Tune locators

You can edit the source code to fine-tune locators while on a breakpoint. Test out different locators and see them highlighted in the browser.

edit-locators


Record new tests

Record new tests by clicking on the "record tests" button in the testing sidebar. This will open a browser window where you can navigate to a URL and perform actions on the page which will be recorded to a new test file in VS Code.

record-new2


Record at cursor

This generates actions into the existing test at the current cursor position. You can run the test, position the cursor at the end of the test and continue generating the test.

playwright-vscode's People

Contributors

aslushnikov avatar badeball avatar chasestarr avatar csbun avatar debs-obrien avatar dependabot[bot] avatar dgozman avatar erwin-faceit avatar f3n67u avatar fflaten avatar jfgreffier avatar kalinkrustev avatar kumaraditya303 avatar marcusfelling avatar microsoft-github-operations[bot] avatar microsoftopensource avatar mskelton avatar mxschmitt avatar pavelfeldman avatar tyriar avatar yury-s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

playwright-vscode's Issues

Overly eager in detecting Spec files

Extension is detecting files that are NOT spec-containing files such as Page Object and/or Config modules.

Expectation is that spec detection should only detect (and show) modules that contains specs.

PlaywrightTestExtension_DetectingNonSpecs

trouble to start tests with example project

When try to start tests in example project i have this picture:

image

In Debug mode i have error:

image

In output i have this:

image

Playwirhght Test For VSCode v0.0.2

VSCode
Version: 1.59.0 (user setup)
Commit: 379476f0e13988d90fab105c5c19e7abc8b1dea8
Date: 2021-08-04T23:13:12.822Z
Electron: 13.1.7
Chrome: 91.0.4472.124
Node.js: 14.16.0
V8: 9.1.269.36-electron.0
OS: Windows_NT x64 10.0.19042

Electron failed to launch

When attempting to run tests using Electron 17.0.1 it appears that playwright is unable to start Electron returning a "electron.launch: Process failed to launch" error message. When I run the tests via the command line using npx playwright test Electron loads up as expected.

VSCode: 1.64.2
Extension Version: 0.1.0
NodeJS: v14.18.3
NPM: 6.14.16
Playwright: 1.19.1
Playwright/Test: 1.19.1
OS: Windows 10 21H1

Refactoring suggestions

Here is the high level code review:

Show stoppers

  • Test run should be selectable and should show test output for given run
  • There should be a way to start tests from the regular file tree, not from test results
  • There should be a one-click action to re-start last tests

UX

  • Current test tree UX forces us to discover tests via 'Testing' perspective. I don't think users would do that, they would rather run tests off folders in main tree or from source (play button). We could experiment with only showing results in that perspective.

Bugs

  • Only create one testController, not test controller per project
  • It looks like persist: false is not respected
  • Keep folder / file / suite tree items canResolveChildren = true so that UI did not expand them on load, but when resolveHandler is called, don't run playwright - you already have all the information.
  • Spawn npx instead of node + cli.js, explicitly use workspaceFolder for cwd. Don't run Node, don't assume cwd, that way we know we use workspace node and playwright.
  • Use vscode.workspace.findFiles('playwright.config.*') to locate configs, after that map configs to vscode.workspace.workspaceFolders, that's how you know where to run npx for these configs.
  • Pressing a button should be same as npx playwright filter. I.e. parallel, bulk, not one-by-one. You would need to create your own reporter --reporter=vsCodeExtensionReport.js.

Extension does not appear in the UI

Extension version: v0.0.9
Playwright version: 1.18.0
VS Code: 1.63.2

One package.json in the root. Tests are in root/tests folder named with pattern of *.ts
The extension does not appear in the UI. Is there any way to solve this?

Screenshot at Feb 09 12-09-38

[internal] support env vars

inside the config:

				"playwright.env": {
					"type": "object",
					"description": "Object with environment variables that will be added to the Playwright Test process.",
					"additionalProperties": {
						"type": [
							"string"
						]
					}
				}

Playwright Test for VSCode only reads environment variables on installation

Steps to reproduce:

  • Install Playwright for VSCode
  • Add environment variables
    "playwright.env": { "baseUrl": "<url here>", "proxyUser": "<username here>", "proxyPass": "password here" },

expected result:
Playwright for VsCode will use the environment variables in the following test processes

Observed result:
Playwright for VsCode does not use the environment variables in the following test processes.

It seems Playwright for VsCode only loads the environment variables when you install the extension. If you have the extension and you change a variable, you'll have to reinstall the extension in order to get it picked up.

Multi folder workspace support

My workspace has a bunch of folders. Would love to see playwright support it.

Here's what I get today:
image

azsdke2e
azsdke2e2

Add Playwright Test version validation

Requirements:

  • VSCode 1.59+ (enforced via the extension manifest)
  • Playwright Test 1.14.0+ (to be confirmed - we should add verification)
  • Operating system (mac/Windows/Linux) should all work and is tested
  • Test-file names for activation: using the *.spec.{js,ts}, *.test.{js,ts} naming, we might should make this more flexible?

Can't figure out how to see why a test failed

I have a failing test.

I only see the red X

I do not see the details as to why it failed.

I right clicked on all the places I could find.

I checked the outputs...

I was expecting it in the Playwright Test output window.

azsdke2e
azsdke2e2

Specifying the `webServer` in the config seems to partially initiate it

I have the webServer configuration specified in my playwright.config.ts file which is setup to run my local webpack dev server. I'm noticing that when my webpack dev server has open: true set, opening the project or expanding a group of Playwright tests will open the URL in my browser. This leads me to believe that the extension is partially initiating the web server when listing tests. This also seems to negatively impact performance of the extension due to it doing something with the server.

Config in subfolder places test results in the wrong location

I'm not sure exactly if this is an extension or playwright core issue, but I'm noticing that when running with VS Code, the test-results folder is placed at the root of my repository but when running with the CLI it is placed in my e2efolder. My project is setup with e2e/playwright.config.ts which I have configured for VS Code like so:

{
  "playwright.configs": ["e2e/playwright.config.ts"]
}

When running with the CLI, it places the test results in the right place when I'm in the e2e directory or if I run yarn workspace e2e test. This leads me to believe it is probably the extension.

My playwright.config.ts file contents:

import { expect, PlaywrightTestConfig } from '@playwright/test'

const config: PlaywrightTestConfig = {
  forbidOnly: !!process.env.CI,
  projects: [
    { name: 'A11y', testDir: 'spec/a11y' },
    // three others that look the same
  ],
  retries: process.env.CI ? 2 : 0,
  use: {
    screenshot: 'only-on-failure',
    trace: 'on-first-retry',
  },
}

export default config

Make it work for parameterized tests

I'm using a for loop to iterate over an array with test data to run the same test multiple times and it's detected properly by the test runner extension. But starting the test run it exponentially - for every test that is detected in the loop it runs all the test in the loop

Add Playwright Inspector integration

VSCode has two types of tests:
a) normal tests
-> there we want the inspector if the user enables it
b) debug tests
-> there we don't want the inspector, DEBUG=pw:api should be enough
-> because the VSCode debugger is attached

[Bug] v2 doesn't discover tests in nested folders

Extension activates, but it doesn't discover any tests. My workspace with dir one level deep (tests/test.spec.ts) works, my workspace with dir 2 levels deep does not (ToDoMVC/tests/test.spec.ts)

Monorepo unable to discover playwright tests

I have a monorepo with .net core backend, react spa

├── backend
│   ├── ...
├── frontend
│   ├── e2e
│   │   ├── tests
|   |   |    ├── test.spec.ts
|   |   |    ├── ..
|   |   ├──..
│   │   ├── ..
│   ├── ..
└── .gitignore

2022-02-16T02:53:23.200Z Error: Could not locate Playwright Test. Is it installed? 'npm install -D @playwright/test'

I open workspace @ containing folder of backend & frontend, when i use test explorer, i can only see my backend tests

Add color to error output

Not sure if this is a VS Code issue or an issue with this extension, but having colors in the error output would be nice.

Current test results:

Screen Shot 2021-09-07 at 9 12 26 AM

While the CLI produces a nicer output:

Screen Shot 2021-09-07 at 9 13 41 AM

Path should be regex escaped

The help states that arguments will be used to filter test files, and "each argument is treated as a regular expression". At the moment the path is passed as argument, which (on Windows at least) is not a valid regular expression. This results in

=================
 no tests found.
=================

I think the path passed on the lines below (line 109 specific) should be escaped to be regular expression safe. In my case, if I replace all backslashes with double backslashes, the test is executed correctly.

const args = [
...this._buildBaseArgs(config, projectName),
'--reporter=list',
`${path}:${line}`
];

I think the same goes for

const proc = await this._executePlaywrightTestCommand(config, projectName, [`${path}:${line}`], {

Finally, on line 47 a shortcut is used replaceAll('\\', '\\\\'), but I think this should be a method which escapes all regex characters instead.

const proc = await this._executePlaywrightTestCommand(config, projectName, ['--list', fileOrFolder.replaceAll('\\', '\\\\')]);

[BUG] VS Code extension not working

Context:

  • Playwright Version: 1.15.2
  • Extension version: v0.0.7
    image

Describe the bug
Test explorer does not appear when viewing test files with extension *.spec.ts

Output window log
image

image

debugging doesn't work

when attempting to debug, it just outputs this to the debug console and does nothing:

image
image

main.spec.ts

import { expect, test } from '@playwright/test'

test('basic test', async ({ page }) => {
    await page.goto('https://google.com/')
    const title = page.locator('.navbar__inner .navbar__title')
    await expect(title).toHaveText('Playwright')
})

playwright.config.ts

import { PlaywrightTestConfig } from '@playwright/test'

const config: PlaywrightTestConfig = {
    projects: [
        {
            name: 'Chrome Stable',
            use: {
                browserName: 'chromium',
                // Test against Chrome Stable channel.
                channel: 'chrome',
            },
        },
    ],
}
export default config

playwright test output

2021-09-21T05:07:05.236Z Executing command: node_modules\@playwright\test\lib\cli\cli.js test --retries=0 --reporter=json --list \. 
2021-09-21T05:07:10.458Z Creating test controller: Playwright TestChrome Stable 
2021-09-21T05:07:10.459Z Executing command: node_modules\@playwright\test\lib\cli\cli.js test --retries=0 --project=Chrome Stable --reporter=json --list c:\\Users\\user\\playwright-demo\\tests\\main\.spec\.ts 
2021-09-21T05:07:12.926Z TestFile._updateFromDisk default and Chrome Stable 
2021-09-21T05:07:23.871Z Running test basic test [Chrome Stable] debug=true 

Split tests in the tree based on their folder structure

At the moment all test files are shown as a list in the root of the tree, but this results in many similar entries if you have a bunch of files in the same folder.
I think it would make much more sense if the tests were structured by their folder structure. That way it would be much easier to find a specific test, and it would be very easy to run all tests in a specific folder.
I believe this how the jest vscode extension handles it as well.

[Bug] v2 doesn't work with nested playwright-core module

npm 6 installed playwright-core module inside @playwright/test (thinks there is a conflict for some reason?), as a result, extension is not activated. Upgrading npm to 7.24.2 adds playwright-core to root, fixing the issue.

command 'python.refreshTests' not found

When I try to refresh tests (would be great if the list auto-refreshes btw), I get this error:

command 'python.refreshTests' not found

How can I fix this?

Adopt status bar name

If you give the status bar item a name it will have a nice label here:

image

I think without a name hiding this will also hide all status bar entries for the extension.

[Question] Is it possible to print the test results in the terminal?

First of all, I'd like to thank you for the brilliant plugin

Now the output of the test results in the terminal is just simple text of Running and Completed spec files.

But, as a user, I'd like to see the test results in the terminal in the selected reporter style (e.g dot or list ), which I selected in the configuration file.

Actual:

image

Expected:

image

Does not work with pnpm workspace

I have a root pnpm workspace that includes a folder ./e2e-tests with a default Playwright setup.
The test runner says : "No tests have been found in this workspace yet."
I tried to set dotnet-test-explorer.testProjectPath with no luck.

Using pnpm in a non-workspace setup works fine,

All Playwrite setups are done with the default npm init playwright new-project command.

Any ideas how to fix that?

Add a changelog

You're using GH releases right now but the way to get the changelog integrated into VS Code and the marketplace is by adding a CHANGELOG.md file to the root of the extension folder.

Detect Playwright configs in subfolders out of the box

Many of the projects I work on have Playwright tests in a dedicated subdirectory (e.g. e2e) separate from the main project which might be in app or src. The extension by default only looks for a playwright.config.ts file in the root so this requires that I set e2e/playwright.config.ts in my settings to make the tests discoverable.

This issue could of course also apply for monorepos with multiple test projects, but this is probably a first step towards that if others have a use case for multiple Playwright projects in a single repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.