Skip to content
Open
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
42 changes: 41 additions & 1 deletion playwright-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,44 @@
* limitations under the License.
*/

require('playwright/lib/cli/client/program');
const args = process.argv.slice(2);
const command = args.find(a => !a.startsWith('-'));

if (command === 'install-browser') {
const minimist = require('minimist');
const parsed = minimist(args, { string: ['_', 'browser'], boolean: ['help', 'h'] });

if (parsed.help || parsed.h) {
console.log(
'playwright-cli install-browser [browser]\n\n' +
'Install browser\n\n' +
'Arguments:\n' +
' [browser] browser to install: chromium, firefox, webkit, chrome, msedge\n' +
'Options:\n' +
' --browser browser to install (alternative to positional argument)'
);
process.exit(0);
}

const browserName = parsed._[1] || parsed.browser;
if (!browserName) {
console.error('Browser name is required. Usage: playwright-cli install-browser <browser>\nPossible values: chromium, firefox, webkit, chrome, msedge');
process.exit(1);
}

import('playwright-core/lib/server/registry/index').then(({ registry }) => {
const executable = registry.findExecutable(browserName);
if (!executable) {
console.error(`Unknown browser: "${browserName}". Possible values: chromium, firefox, webkit, chrome, msedge`);
process.exit(1);
}
registry.install([executable]).then(() => {
console.log(`Browser "${browserName}" installed successfully.`);
}).catch(e => {
console.error(e.message);
process.exit(1);
});
});
} else {
require('playwright/lib/cli/client/program');
}
24 changes: 24 additions & 0 deletions tests/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ async function runCli(...args: string[]): Promise<CliResult> {
});
}

test('install-browser installs successfully', async ({}) => {
const result = await runCli('install-browser', 'chromium');
expect(result.exitCode).toBe(0);
expect(result.output).toContain('installed successfully');
});

test('install-browser with --browser flag', async ({}) => {
const result = await runCli('install-browser', '--browser=chromium');
expect(result.exitCode).toBe(0);
expect(result.output).toContain('installed successfully');
});

test('install-browser fails for unknown browser', async ({}) => {
const result = await runCli('install-browser', 'bogus');
expect(result.exitCode).toBe(1);
expect(result.error).toContain('Unknown browser');
});

test('install-browser fails without browser name', async ({}) => {
const result = await runCli('install-browser');
expect(result.exitCode).toBe(1);
expect(result.error).toContain('Browser name is required');
});

test('open data URL', async ({}) => {
expect(await runCli('open', 'data:text/html,hello', '--persistent')).toEqual(expect.objectContaining({
output: expect.stringContaining('hello'),
Expand Down