add --list and npm run list
This commit is contained in:
parent
6179b5b1d7
commit
27b5ad546d
|
|
@ -45,7 +45,8 @@
|
|||
"roll": "node utils/roll_browser.js",
|
||||
"check-deps": "node utils/check_deps.js",
|
||||
"build-android-driver": "./utils/build_android_driver.sh",
|
||||
"innerloop": "playwright run-server --reuse-browser"
|
||||
"innerloop": "playwright run-server --reuse-browser",
|
||||
"list": "playwright install --list"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@ program
|
|||
.command('mark-docker-image [dockerImageNameTemplate]', { hidden: true })
|
||||
.description('mark docker image')
|
||||
.allowUnknownOption(true)
|
||||
.action(function(dockerImageNameTemplate) {
|
||||
.action(function (dockerImageNameTemplate) {
|
||||
assert(dockerImageNameTemplate, 'dockerImageNameTemplate is required');
|
||||
writeDockerVersion(dockerImageNameTemplate).catch(logErrorAndExit);
|
||||
});
|
||||
|
||||
commandWithOpenOptions('open [url]', 'open page in browser specified via -b, --browser', [])
|
||||
.action(function(url, options) {
|
||||
.action(function (url, options) {
|
||||
open(options, url, codegenId()).catch(logErrorAndExit);
|
||||
})
|
||||
.addHelpText('afterAll', `
|
||||
|
|
@ -67,9 +67,9 @@ commandWithOpenOptions('codegen [url]', 'open page and generate code for user ac
|
|||
['--target <language>', `language to generate, one of javascript, playwright-test, python, python-async, python-pytest, csharp, csharp-mstest, csharp-nunit, java, java-junit`, codegenId()],
|
||||
['--save-trace <filename>', 'record a trace for the session and save it to a file'],
|
||||
['--test-id-attribute <attributeName>', 'use the specified attribute to generate data test ID selectors'],
|
||||
]).action(function(url, options) {
|
||||
]).action(function (url, options) {
|
||||
codegen(options, url).catch(logErrorAndExit);
|
||||
}).addHelpText('afterAll', `
|
||||
}).addHelpText('afterAll', `
|
||||
Examples:
|
||||
|
||||
$ codegen
|
||||
|
|
@ -133,7 +133,7 @@ program
|
|||
.option('--force', 'force reinstall of stable browser channels')
|
||||
.option('--only-shell', 'only install headless shell when installing chromium')
|
||||
.option('--no-shell', 'do not install chromium headless shell')
|
||||
.action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean }) {
|
||||
.action(async function (args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean }) {
|
||||
// For '--no-shell' option, commander sets `shell: false` instead.
|
||||
if (options.shell === false)
|
||||
options.noShell = true;
|
||||
|
|
@ -214,7 +214,7 @@ program
|
|||
.command('install-deps [browser...]')
|
||||
.description('install dependencies necessary to run browsers (will ask for sudo permissions)')
|
||||
.option('--dry-run', 'Do not execute installation commands, only print them')
|
||||
.action(async function(args: string[], options: { dryRun?: boolean }) {
|
||||
.action(async function (args: string[], options: { dryRun?: boolean }) {
|
||||
try {
|
||||
if (!args.length)
|
||||
await registry.installDeps(defaultBrowsersToInstall({}), !!options.dryRun);
|
||||
|
|
@ -232,6 +232,39 @@ Examples:
|
|||
- $ install-deps chrome firefox
|
||||
Install dependencies for specific browsers, supports ${suggestedBrowsersToInstall()}.`);
|
||||
|
||||
program
|
||||
.command('show-browsers') // Changed from 'install --list' to avoid conflicts
|
||||
.alias('list-browsers') // Added alias for convenience
|
||||
.description('lists installed browsers and their paths')
|
||||
.action(async function () {
|
||||
try {
|
||||
const browsers = new Set();
|
||||
// Filter once instead of twice
|
||||
const installableBrowsers = registry.executables().filter(e =>
|
||||
e.installType !== 'none' &&
|
||||
e.type !== 'tool'
|
||||
);
|
||||
|
||||
if (installableBrowsers.length === 0) {
|
||||
console.log('No browsers installed. To install them use: npx playwright install');
|
||||
return;
|
||||
}
|
||||
|
||||
for (const executable of installableBrowsers) {
|
||||
try {
|
||||
const version = executable.browserVersion ? `v${executable.browserVersion}` : '';
|
||||
const location = executable.directory || '<system>';
|
||||
console.log(`${executable.name} ${version ? version + ' ' : ''}${location ? `(${location})` : ''}`);
|
||||
browsers.add(executable.name);
|
||||
} catch (e) {
|
||||
console.error(`Failed to get info for browser ${executable.name}:`, e);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logErrorAndExit(e);
|
||||
}
|
||||
});
|
||||
|
||||
const browsers = [
|
||||
{ alias: 'cr', name: 'Chromium', type: 'chromium' },
|
||||
{ alias: 'ff', name: 'Firefox', type: 'firefox' },
|
||||
|
|
@ -240,7 +273,7 @@ const browsers = [
|
|||
|
||||
for (const { alias, name, type } of browsers) {
|
||||
commandWithOpenOptions(`${alias} [url]`, `open page in ${name}`, [])
|
||||
.action(function(url, options) {
|
||||
.action(function (url, options) {
|
||||
open({ ...options, browser: type }, url, options.target).catch(logErrorAndExit);
|
||||
}).addHelpText('afterAll', `
|
||||
Examples:
|
||||
|
|
@ -253,9 +286,9 @@ commandWithOpenOptions('screenshot <url> <filename>', 'capture a page screenshot
|
|||
['--wait-for-selector <selector>', 'wait for selector before taking a screenshot'],
|
||||
['--wait-for-timeout <timeout>', 'wait for timeout in milliseconds before taking a screenshot'],
|
||||
['--full-page', 'whether to take a full page screenshot (entire scrollable area)'],
|
||||
]).action(function(url, filename, command) {
|
||||
]).action(function (url, filename, command) {
|
||||
screenshot(command, command, url, filename).catch(logErrorAndExit);
|
||||
}).addHelpText('afterAll', `
|
||||
}).addHelpText('afterAll', `
|
||||
Examples:
|
||||
|
||||
$ screenshot -b webkit https://example.com example.png`);
|
||||
|
|
@ -264,16 +297,16 @@ commandWithOpenOptions('pdf <url> <filename>', 'save page as pdf',
|
|||
[
|
||||
['--wait-for-selector <selector>', 'wait for given selector before saving as pdf'],
|
||||
['--wait-for-timeout <timeout>', 'wait for given timeout in milliseconds before saving as pdf'],
|
||||
]).action(function(url, filename, options) {
|
||||
]).action(function (url, filename, options) {
|
||||
pdf(options, options, url, filename).catch(logErrorAndExit);
|
||||
}).addHelpText('afterAll', `
|
||||
}).addHelpText('afterAll', `
|
||||
Examples:
|
||||
|
||||
$ pdf https://example.com example.pdf`);
|
||||
|
||||
program
|
||||
.command('run-driver', { hidden: true })
|
||||
.action(function(options) {
|
||||
.action(function (options) {
|
||||
runDriver();
|
||||
});
|
||||
|
||||
|
|
@ -284,7 +317,7 @@ program
|
|||
.option('--path <path>', 'Endpoint Path', '/')
|
||||
.option('--max-clients <maxClients>', 'Maximum clients')
|
||||
.option('--mode <mode>', 'Server mode, either "default" or "extension"')
|
||||
.action(function(options) {
|
||||
.action(function (options) {
|
||||
runServer({
|
||||
port: options.port ? +options.port : undefined,
|
||||
host: options.host,
|
||||
|
|
@ -296,7 +329,7 @@ program
|
|||
|
||||
program
|
||||
.command('print-api-json', { hidden: true })
|
||||
.action(function(options) {
|
||||
.action(function (options) {
|
||||
printApiJson();
|
||||
});
|
||||
|
||||
|
|
@ -304,7 +337,7 @@ program
|
|||
.command('launch-server', { hidden: true })
|
||||
.requiredOption('--browser <browserName>', 'Browser name, one of "chromium", "firefox" or "webkit"')
|
||||
.option('--config <path-to-config-file>', 'JSON file with launchServer options')
|
||||
.action(function(options) {
|
||||
.action(function (options) {
|
||||
launchBrowserServer(options.browser, options.config);
|
||||
});
|
||||
|
||||
|
|
@ -315,7 +348,7 @@ program
|
|||
.option('-p, --port <port>', 'Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab')
|
||||
.option('--stdin', 'Accept trace URLs over stdin to update the viewer')
|
||||
.description('show trace viewer')
|
||||
.action(function(traces, options) {
|
||||
.action(function (traces, options) {
|
||||
if (options.browser === 'cr')
|
||||
options.browser = 'chromium';
|
||||
if (options.browser === 'ff')
|
||||
|
|
@ -518,13 +551,13 @@ async function launchContext(options: Options, extraOptions: LaunchOptions): Pro
|
|||
}
|
||||
|
||||
context.on('page', page => {
|
||||
page.on('dialog', () => {}); // Prevent dialogs from being automatically dismissed.
|
||||
page.on('dialog', () => { }); // Prevent dialogs from being automatically dismissed.
|
||||
page.on('close', () => {
|
||||
const hasPage = browser.contexts().some(context => context.pages().length > 0);
|
||||
if (hasPage)
|
||||
return;
|
||||
// Avoid the error when the last page is closed because the browser has been closed.
|
||||
closeBrowser().catch(() => {});
|
||||
closeBrowser().catch(() => { });
|
||||
});
|
||||
});
|
||||
process.on('SIGINT', async () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue