Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 50 additions & 55 deletions docs/src/aria-snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ await page.goto('https://playwright.dev/');
await expect(page.getByRole('banner')).toMatchAriaSnapshot(`
- banner:
- heading /Playwright enables reliable end-to-end/ [level=1]
- link "Get started"
- link "Star microsoft/playwright on GitHub"
- link "Get started":
- /url: /docs/intro
- link "Star microsoft/playwright on GitHub":
- /url: https://github.com/microsoft/playwright
- link /[\\d]+k\\+ stargazers on GitHub/
`);
```
Expand All @@ -24,8 +26,10 @@ page.goto('https://playwright.dev/')
expect(page.query_selector('banner')).to_match_aria_snapshot("""
- banner:
- heading /Playwright enables reliable end-to-end/ [level=1]
- link "Get started"
- link "Star microsoft/playwright on GitHub"
- link "Get started":
- /url: /docs/intro
- link "Star microsoft/playwright on GitHub":
- /url: https://github.com/microsoft/playwright
- link /[\\d]+k\\+ stargazers on GitHub/
""")
```
Expand All @@ -35,8 +39,10 @@ await page.goto('https://playwright.dev/')
await expect(page.query_selector('banner')).to_match_aria_snapshot("""
- banner:
- heading /Playwright enables reliable end-to-end/ [level=1]
- link "Get started"
- link "Star microsoft/playwright on GitHub"
- link "Get started":
- /url: /docs/intro
- link "Star microsoft/playwright on GitHub":
- /url: https://github.com/microsoft/playwright
- link /[\\d]+k\\+ stargazers on GitHub/
""")
```
Expand All @@ -46,8 +52,10 @@ page.navigate("https://playwright.dev/");
assertThat(page.locator("banner")).matchesAriaSnapshot("""
- banner:
- heading /Playwright enables reliable end-to-end/ [level=1]
- link "Get started"
- link "Star microsoft/playwright on GitHub"
- link "Get started":
- /url: /docs/intro
- link "Star microsoft/playwright on GitHub":
- /url: https://github.com/microsoft/playwright
- link /[\\d]+k\\+ stargazers on GitHub/
""");
```
Expand All @@ -57,8 +65,10 @@ await page.GotoAsync("https://playwright.dev/");
await Expect(page.Locator("banner")).ToMatchAriaSnapshotAsync(@"
- banner:
- heading ""Playwright enables reliable end-to-end testing for modern web apps."" [level=1]
- link ""Get started""
- link ""Star microsoft/playwright on GitHub""
- link ""Get started"":
- /url: /docs/intro
- link ""Star microsoft/playwright on GitHub"":
- /url: https://github.com/microsoft/playwright
- link /[\\d]+k\\+ stargazers on GitHub/
");
```
Expand Down Expand Up @@ -215,9 +225,7 @@ attributes.
<button>Submit</button>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- button
```

Expand All @@ -233,9 +241,7 @@ focusing solely on role and hierarchy.
<input type="checkbox" checked>
```

*aria snapshot for partial match*

```yaml
```yaml title="aria snapshot (partial match)"
- checkbox
```

Expand All @@ -253,9 +259,7 @@ Similarly, you can partially match children in lists or groups by omitting speci
</ul>
```

*aria snapshot for partial match*

```yaml
```yaml title="aria snapshot (partial match)"
- list
- listitem: Feature B
```
Expand All @@ -275,9 +279,7 @@ By default, a template containing the subset of children will be matched:
</ul>
```

*aria snapshot for partial match*

```yaml
```yaml title="aria snapshot (partial match)"
- list
- listitem: Feature B
```
Expand All @@ -296,9 +298,9 @@ The `/children` property can be used to control how child elements are matched:
</ul>
```

*aria snapshot will fail due to Feature C not being in the template*
Following snapshot will fail due to Feature C not being in the template:

```yaml
```yaml title="aria snapshot"
- list
- /children: equal
- listitem: Feature A
Expand All @@ -314,9 +316,7 @@ support regex patterns.
<h1>Issues 12</h1>
```

*aria snapshot with regular expression*

```yaml
```yaml title="aria snapshot"
- heading /Issues \d+/
```

Expand Down Expand Up @@ -445,9 +445,7 @@ Headings can include a `level` attribute indicating their heading level.
<h2>Subtitle</h2>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- heading "Title" [level=1]
- heading "Subtitle" [level=2]
```
Expand All @@ -460,9 +458,7 @@ Standalone or descriptive text elements appear as text nodes.
<div>Sample accessible name</div>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- text: Sample accessible name
```

Expand All @@ -474,24 +470,33 @@ Multiline text, such as paragraphs, is normalized in the aria snapshot.
<p>Line 1<br>Line 2</p>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- paragraph: Line 1 Line 2
```

### Links

Links display their text or composed content from pseudo-elements.
Links display their text or composed content from pseudo-elements. The link’s destination may be matched using the
`/url` property.

```html
<a href="#more-info">Read more about Accessibility</a>
```

*aria snapshot*
```yaml title="aria snapshot"
- link "Read more about Accessibility":
- /url: "#more-info"
```

```yaml
- link "Read more about Accessibility"
The value of `/url` may also be a regular expression:

```html
<a href="https://www.youtube.com/channel/UC46Zj8pDH5tDosqm1gd7WTg">YouTube channel</a>
```

```yaml title="aria snapshot"
- link:
- /url: /https://www.youtube.com/channel/.*/
```

### Text boxes
Expand All @@ -502,9 +507,7 @@ Input elements of type `text` show their `value` attribute content.
<input type="text" value="Enter your name">
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- textbox: Enter your name
```

Expand All @@ -519,9 +522,7 @@ Ordered and unordered lists include their list items.
</ul>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- list "Main Features":
- listitem: Feature 1
- listitem: Feature 2
Expand All @@ -538,9 +539,7 @@ Groups capture nested elements, such as `<details>` elements with summary conten
</details>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- group: Summary
```

Expand All @@ -555,9 +554,7 @@ control states.
<input type="checkbox" checked>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- checkbox [checked]
```

Expand All @@ -567,8 +564,6 @@ control states.
<button aria-pressed="true">Toggle</button>
```

*aria snapshot*

```yaml
```yaml title="aria snapshot"
- button "Toggle" [pressed=true]
```
2 changes: 1 addition & 1 deletion docs/src/release-notes-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ This version was also tested against the following stable channels:
await Expect(Page.GetByRole(AriaRole.Listitem, new() { Name = "Ship v1.52" })).ToContainClassAsync("done");
```

- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and `/url` for links.
- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and [`/url`](./aria-snapshots.md#links) for links.

```csharp
await Expect(locator).ToMatchAriaSnapshotAsync(@"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/release-notes-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ This version was also tested against the following stable channels:
assertThat(page.getByRole(AriaRole.LISTITEM, new Page.GetByRoleOptions().setName("Ship v1.52"))).containsClass("done");
```

- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and `/url` for links.
- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and [`/url`](./aria-snapshots.md#links) for links.

```java
assertThat(locator).toMatchAriaSnapshot("""
Expand Down
2 changes: 1 addition & 1 deletion docs/src/release-notes-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ This version was also tested against the following stable channels:
await expect(page.getByRole('listitem', { name: 'Ship v1.52' })).toContainClass('done');
```

- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and `/url` for links.
- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and [`/url`](./aria-snapshots.md#links) for links.

```ts
await expect(locator).toMatchAriaSnapshot(`
Expand Down
2 changes: 1 addition & 1 deletion docs/src/release-notes-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ This version was also tested against the following stable channels:
expect(page.get_by_role('listitem', name='Ship v1.52')).to_contain_class('done')
```

- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and `/url` for links.
- [Aria Snapshots](./aria-snapshots.md) got two new properties: [`/children`](./aria-snapshots.md#strict-matching) for strict matching and [`/url`](./aria-snapshots.md#links) for links.

```python
expect(locator).to_match_aria_snapshot("""
Expand Down
3 changes: 3 additions & 0 deletions packages/playwright/src/mcp/browser/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type CLIOptions = {
caps?: string[];
cdpEndpoint?: string;
cdpHeader?: Record<string, string>;
cdpTimeout?: number;
codegen?: 'typescript' | 'none';
config?: string;
consoleLevel?: 'error' | 'warning' | 'info' | 'debug';
Expand Down Expand Up @@ -276,6 +277,7 @@ export function configFromCLIOptions(cliOptions: CLIOptions): Config & { configF
contextOptions,
cdpEndpoint: cliOptions.cdpEndpoint,
cdpHeaders: cliOptions.cdpHeader,
cdpTimeout: cliOptions.cdpTimeout,
initPage: cliOptions.initPage,
initScript: cliOptions.initScript,
},
Expand Down Expand Up @@ -325,6 +327,7 @@ function configFromEnv(): Config & { configFile?: string } {
options.caps = commaSeparatedList(process.env.PLAYWRIGHT_MCP_CAPS);
options.cdpEndpoint = envToString(process.env.PLAYWRIGHT_MCP_CDP_ENDPOINT);
options.cdpHeader = headerParser(process.env.PLAYWRIGHT_MCP_CDP_HEADERS, {});
options.cdpTimeout = numberParser(process.env.PLAYWRIGHT_MCP_CDP_TIMEOUT);
options.config = envToString(process.env.PLAYWRIGHT_MCP_CONFIG);
if (process.env.PLAYWRIGHT_MCP_CONSOLE_LEVEL)
options.consoleLevel = enumParser<'error' | 'warning' | 'info' | 'debug'>('--console-level', ['error', 'warning', 'info', 'debug'], process.env.PLAYWRIGHT_MCP_CONSOLE_LEVEL);
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright/src/mcp/browser/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import common from './tools/common';
import config from './tools/config';
import console from './tools/console';
import cookies from './tools/cookies';
import dialogs from './tools/dialogs';
Expand Down Expand Up @@ -44,6 +45,7 @@ import type { FullConfig } from './config';

export const browserTools: Tool<any>[] = [
...common,
...config,
...console,
...cookies,
...dialogs,
Expand Down
38 changes: 38 additions & 0 deletions packages/playwright/src/mcp/browser/tools/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { z } from 'playwright-core/lib/mcpBundle';
import { defineTool } from './tool';

const configShow = defineTool({
capability: 'config',

schema: {
name: 'browser_get_config',
title: 'Get config',
description: 'Get the final resolved config after merging CLI options, environment variables and config file.',
inputSchema: z.object({}),
type: 'readOnly',
},

handle: async (context, params, response) => {
response.addTextResult(JSON.stringify(context.config, null, 2));
},
});

export default [
configShow,
];
1 change: 1 addition & 0 deletions packages/playwright/src/mcp/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import type * as playwright from 'playwright-core';

export type ToolCapability =
'config' |
'core' |
'core-navigation' |
'core-tabs' |
Expand Down
1 change: 1 addition & 0 deletions packages/playwright/src/mcp/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function decorateCommand(command: Command, version: string) {
.option('--caps <caps>', 'comma-separated list of additional capabilities to enable, possible values: vision, pdf, devtools.', commaSeparatedList)
.option('--cdp-endpoint <endpoint>', 'CDP endpoint to connect to.')
.option('--cdp-header <headers...>', 'CDP headers to send with the connect request, multiple can be specified.', headerParser)
.option('--cdp-timeout <timeout>', 'timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms', numberParser)
.option('--codegen <lang>', 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', enumParser.bind(null, '--codegen', ['none', 'typescript']))
.option('--config <path>', 'path to the configuration file.')
.option('--console-level <level>', 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', enumParser.bind(null, '--console-level', ['error', 'warning', 'info', 'debug']))
Expand Down
1 change: 1 addition & 0 deletions packages/playwright/src/mcp/terminal/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type CommandSchema<Args extends zodType.ZodTypeAny, Options extends zodTy
name: string;
category: Category;
description: string;
hidden?: boolean;
args?: Args;
options?: Options;
toolName: string | ((args: zodType.infer<Args> & zodType.infer<Options>) => string);
Expand Down
Loading
Loading