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
6 changes: 5 additions & 1 deletion docs/src/api/class-apiresponseassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def test_navigates_to_login_page(page: Page) -> None:
* langs: java, js, csharp
- returns: <[APIResponseAssertions]>

Makes the assertion check for the opposite condition. For example, this code tests that the response status is not successful:
Makes the assertion check for the opposite condition.

**Usage**

For example, this code tests that the response status is not successful:

```js
await expect(response).not.toBeOK();
Expand Down
6 changes: 5 additions & 1 deletion docs/src/api/class-genericassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ test('assert a value', async ({ page }) => {
* since: v1.9
- returns: <[GenericAssertions]>

Makes the assertion check for the opposite condition. For example, the following code passes:
Makes the assertion check for the opposite condition.

**Usage**

For example, the following code passes:

```js
const value = 1;
Expand Down
6 changes: 5 additions & 1 deletion docs/src/api/class-locatorassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public class ExampleTests : PageTest
* langs: java, js, csharp
- returns: <[LocatorAssertions]>

Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain text `"error"`:
Makes the assertion check for the opposite condition.

**Usage**

For example, this code tests that the Locator doesn't contain text `"error"`:

```js
await expect(locator).not.toContainText('error');
Expand Down
6 changes: 5 additions & 1 deletion docs/src/api/class-pageassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public class ExampleTests : PageTest
* langs: java, js, csharp
- returns: <[PageAssertions]>

Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain `"error"`:
Makes the assertion check for the opposite condition.

**Usage**

For example, this code tests that the page URL doesn't contain `"error"`:

```js
await expect(page).not.toHaveURL('error');
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
{
"name": "webkit",
"revision": "2253",
"revision": "2255",
"installByDefault": true,
"revisionOverrides": {
"mac14": "2251",
Expand Down
8 changes: 7 additions & 1 deletion packages/playwright-core/src/server/bidi/bidiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ export class BidiPage implements PageDelegate {
}

async requestGC(): Promise<void> {
throw new Error('Method not implemented.');
const result = await this._session.send('script.evaluate', {
expression: 'TestUtils.gc()',
target: { context: this._session.sessionId },
awaitPromise: true,
});
if (result.type === 'exception')
throw new Error('Method not implemented.');
}

private async _onScriptMessage(event: bidi.Script.MessageParameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ function defaultProfilePreferences(

// Prevent starting into safe mode after application crashes
'toolkit.startup.max_resumed_crashes': -1,

// Enable TestUtils
'dom.testing.testutils.enabled': true,
};

return Object.assign(defaultPrefs, extraPrefs);
Expand Down
5 changes: 4 additions & 1 deletion packages/playwright/src/mcp/browser/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export async function resolveCLIConfig(cliOptions: CLIOptions): Promise<FullConf
const configInFile = await loadConfig(configFile);

let result = defaultConfig;
// Daemon session is always headless by default.
if (cliOptions.daemonSession)
result.browser.launchOptions.headless = true;
result = mergeConfig(result, configInFile);
result = mergeConfig(result, daemonOverrides);
result = mergeConfig(result, envOverrides);
Expand Down Expand Up @@ -368,7 +371,7 @@ async function configForDaemonSession(cliOptions: CLIOptions): Promise<Config &
config: sessionConfig.cli.config,
browser: sessionConfig.cli.browser,
isolated: sessionConfig.cli.isolated,
headless: !sessionConfig.cli.headed,
headless: sessionConfig.cli.headed ? false : undefined,
extension: sessionConfig.cli.extension,
outputMode: 'file',
snapshotMode: 'full',
Expand Down
5 changes: 5 additions & 0 deletions packages/playwright/src/mcp/browser/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ function allRootPaths(clientInfo: ClientInfo): string[] {


function originOrHostGlob(originOrHost: string) {
// Support wildcard port patterns like "http://localhost:*" or "https://example.com:*"
const wildcardPortMatch = originOrHost.match(/^(https?:\/\/[^/:]+):\*$/);
if (wildcardPortMatch)
return `${wildcardPortMatch[1]}:*/**`;

try {
const url = new URL(originOrHost);
// localhost:1234 will parse as protocol 'localhost:' and 'null' origin.
Expand Down
14 changes: 13 additions & 1 deletion packages/playwright/src/mcp/browser/logFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import fs from 'fs';
import path from 'path';

import { logUnhandledError } from '../log';

Expand Down Expand Up @@ -59,7 +60,18 @@ export class LogFile {
this._stopped = true;
}

async take(): Promise<LogChunk | undefined> {
async take(relativeTo?: string): Promise<string | undefined> {
const logChunk = await this._take();
if (!logChunk)
return undefined;
const logFilePath = relativeTo ? path.relative(relativeTo, logChunk.file) : logChunk.file;
const lineRange = logChunk.fromLine === logChunk.toLine
? `#L${logChunk.fromLine}`
: `#L${logChunk.fromLine}-L${logChunk.toLine}`;
return `${logFilePath}${lineRange}`;
}

private async _take(): Promise<LogChunk | undefined> {
await this._writeChain;
if (!this._file || this._entries === this._lastEntries)
return undefined;
Expand Down
22 changes: 6 additions & 16 deletions packages/playwright/src/mcp/browser/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { renderModalStates, shouldIncludeMessage } from './tab';
import { scaleImageToFitMessage } from './tools/screenshot';

import type { TabHeader } from './tab';
import type { LogChunk } from './logFile';
import type { CallToolResult, ImageContent, TextContent } from '@modelcontextprotocol/sdk/types.js';
import type { Context, FilenameTemplate } from './context';

Expand Down Expand Up @@ -186,7 +185,7 @@ export class Response {
addSection('Ran Playwright code', this._code, 'js');

// Render tab titles upon changes or when more than one tab.
const tabSnapshot = this._context.currentTab() ? await this._context.currentTabOrDie().captureSnapshot() : undefined;
const tabSnapshot = this._context.currentTab() ? await this._context.currentTabOrDie().captureSnapshot(this._clientWorkspace) : undefined;
const tabHeaders = await Promise.all(this._context.tabs().map(tab => tab.headerSnapshot()));
if (this._includeSnapshot !== 'none' || tabHeaders.some(header => header.changed)) {
if (tabHeaders.length !== 1)
Expand All @@ -211,7 +210,9 @@ export class Response {
}

// Handle tab log
const text: string[] = tabSnapshot?.logs?.map(log => renderLogChunk(log, log.type, file => this._computRelativeTo(file))).flat() ?? [];
const text: string[] = [];
if (tabSnapshot?.consoleLink)
text.push(`- New console entries: ${tabSnapshot.consoleLink}`);
if (tabSnapshot?.events.filter(event => event.type !== 'request').length) {
for (const event of tabSnapshot.events) {
if (event.type === 'console' && this._context.config.outputMode !== 'file') {
Expand All @@ -234,6 +235,8 @@ export function renderTabMarkdown(tab: TabHeader): string[] {
const lines = [`- Page URL: ${tab.url}`];
if (tab.title)
lines.push(`- Page Title: ${tab.title}`);
if (tab.console.errors || tab.console.warnings)
lines.push(`- Console: ${tab.console.errors} errors, ${tab.console.warnings} warnings`);
return lines;
}

Expand All @@ -250,19 +253,6 @@ export function renderTabsMarkdown(tabs: TabHeader[]): string[] {
return lines;
}

function renderLogChunk(logChunk: LogChunk | undefined, type: string, relativeTo: (fileName: string) => string): string[] {
if (!logChunk)
return [];
const lines: string[] = [];
const logFilePath = relativeTo(logChunk.file);
const entryWord = logChunk.entryCount === 1 ? 'entry' : 'entries';
const lineRange = logChunk.fromLine === logChunk.toLine
? `#L${logChunk.fromLine}`
: `#L${logChunk.fromLine}-L${logChunk.toLine}`;
lines.push(`- ${logChunk.entryCount} new ${type} ${entryWord} in "${logFilePath}${lineRange}"`);
return lines;
}

function trimMiddle(text: string, maxLength: number) {
if (text.length <= maxLength)
return text;
Expand Down
Loading
Loading