Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test(mcp): cover --sandbox at the config resolution level (#42339)
Yury Semikhatsky36f4da000e70
diff --git a/tests/mcp/config-resolve.spec.ts b/tests/mcp/config-resolve.spec.tsindex 25c0910252..c30ce7a31e 100644--- a/tests/mcp/config-resolve.spec.ts+++ b/tests/mcp/config-resolve.spec.ts@@ -18,12 +18,24 @@ import fs from 'fs';import os from 'os';import path from 'path';+import { Command } from 'commander';+import { test, expect } from './fixtures';import { tools } from '../../packages/playwright-core/lib/coreBundle';import type { Config } from '../../packages/playwright-core/src/tools/mcp/config.d';-const { resolveCLIConfigForCLI, resolveCLIConfigForMCP, isSystemDirectory, outputDir } = tools;+const { decorateMCPCommand, resolveCLIConfigForCLI, resolveCLIConfigForMCP, isSystemDirectory, outputDir } = tools;++// Parses the command line the same way the mcp server entry point does, without starting the server.+async function parseCLIOptions(argv: string[]): Promise<any> {+ const command = new Command();+ decorateMCPCommand(command);+ let options: any;+ command.action(o => { options = o; });+ await command.parseAsync(argv, { from: 'user' });+ return options;+}// Empty env to isolate tests from the host environment.const emptyEnv = {};@@ -159,6 +171,22 @@ test.describe('sandbox', () => {const config = await resolveCLIConfigForMCP({ browser: 'chrome', sandbox: false }, emptyEnv);expect(config.browser.launchOptions.chromiumSandbox).toBe(false);});++ test('--sandbox on the command line enables the sandbox', async () => {+ const config = await resolveCLIConfigForMCP(await parseCLIOptions(['--browser=chromium', '--sandbox']), emptyEnv);+ expect(config.browser.launchOptions.channel).toBe('chrome-for-testing');+ expect(config.browser.launchOptions.chromiumSandbox).toBe(true);+ });++ test('--no-sandbox on the command line disables the sandbox', async () => {+ const config = await resolveCLIConfigForMCP(await parseCLIOptions(['--browser=chrome', '--no-sandbox']), emptyEnv);+ expect(config.browser.launchOptions.chromiumSandbox).toBe(false);+ });++ test('no sandbox flag on the command line leaves the value unset', async () => {+ const options = await parseCLIOptions(['--browser=chrome']);+ expect(options.sandbox).toBeUndefined();+ });});// ---------------------------------------------------------------------------diff --git a/tests/mcp/config.spec.ts b/tests/mcp/config.spec.tsindex dcb4f83c17..c042e50d21 100644--- a/tests/mcp/config.spec.ts+++ b/tests/mcp/config.spec.ts@@ -199,14 +199,4 @@ test.describe('chromiumSandbox', () => {const config = JSON.parse(parseResponse(await client.callTool({ name: 'browser_get_config' })).result);expect(config.browser.launchOptions.chromiumSandbox).toBe(false);});-- test('--sandbox enables the sandbox', async ({ startClient }) => {- const { client } = await startClient({- config: { capabilities: ['config'] },- args: ['--browser=chromium', '--sandbox'],- });- const config = JSON.parse(parseResponse(await client.callTool({ name: 'browser_get_config' })).result);- expect(config.browser.launchOptions.channel).toBe('chrome-for-testing');- expect(config.browser.launchOptions.chromiumSandbox).toBe(true);- });});