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
fix(cli): parse negative numbers as arguments (#42333)
Yury Semikhatskyc0554485aa89
diff --git a/packages/playwright-core/src/tools/cli-client/minimist.ts b/packages/playwright-core/src/tools/cli-client/minimist.tsindex 28e6f75257..ecb1f7c1c9 100644--- a/packages/playwright-core/src/tools/cli-client/minimist.ts+++ b/packages/playwright-core/src/tools/cli-client/minimist.ts@@ -94,7 +94,8 @@ export function minimist(args: string[], opts?: MinimistOptions): MinimistArgs {} else {setArg(key, strings[key] ? '' : true);}- } else if ((/^-[^-]+/).test(arg)) {+ } else if ((/^-[A-Za-z]/).test(arg)) {+ // Short flags are letters, so '-100' and '-.5' are arguments, not flags.const letters = arg.slice(1, -1).split('');let broken = false;diff --git a/tests/mcp/cli-parsing.spec.ts b/tests/mcp/cli-parsing.spec.tsindex 8b65fbcba8..947da89cb2 100644--- a/tests/mcp/cli-parsing.spec.ts+++ b/tests/mcp/cli-parsing.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { test, expect } from './cli-fixtures';+import { test, expect, eventsPage } from './cli-fixtures';test('unknown option', async ({ cli, server }) => {const { error, exitCode } = await cli('open', '--some-option', 'value', 'about:blank');@@ -73,6 +73,18 @@ test('wrong argument type', async ({ cli, server }) => {expect(press.exitCode).toBe(0);});+test('negative number arguments', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42321' } }, async ({ cli, server }) => {+ server.setContent('/', eventsPage, 'text/html');+ await cli('open', server.PREFIX);+ await cli('mousemove', '50', '50');++ expect((await cli('mousewheel', '0', '-100')).exitCode).toBe(0);+ await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel 0 -100');++ const { error } = await cli('mousewheel', '-.5');+ expect(error).toContain(`error: 'dy' argument: expected number, received 'undefined'`);+});+test('should preserve leading zeros in string arguments', async ({ cli, server }) => {server.setContent('/', `<input type=text>`, 'text/html');await cli('open', server.PREFIX);