Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick(release-1.9): launch-server command (#5713) #5719

Merged
merged 1 commit into from
Mar 4, 2021
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
4 changes: 3 additions & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import path from 'path';
import program from 'commander';
import os from 'os';
import fs from 'fs';
import { runServer, printApiJson, installBrowsers } from './driver';
import { runServer, printApiJson, launchBrowserServer, installBrowsers } from './driver';
import { showTraceViewer } from './traceViewer/traceViewer';
import * as playwright from '../..';
import { BrowserContext } from '../client/browserContext';
Expand Down Expand Up @@ -162,6 +162,8 @@ if (process.argv[2] === 'run-driver')
runServer();
else if (process.argv[2] === 'print-api-json')
printApiJson();
else if (process.argv[2] === 'launch-server')
launchBrowserServer(process.argv[3], process.argv[4]);
else
program.parse(process.argv);

Expand Down
12 changes: 12 additions & 0 deletions src/cli/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import fs from 'fs';
import path from 'path';
import * as playwright from '../..';
import { BrowserType } from '../client/browserType';
import { LaunchServerOptions } from '../client/types';
import { DispatcherConnection } from '../dispatchers/dispatcher';
import { PlaywrightDispatcher } from '../dispatchers/playwrightDispatcher';
import { installBrowsersWithProgressBar } from '../install/installer';
Expand Down Expand Up @@ -53,6 +56,15 @@ export function runServer() {
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
}

export async function launchBrowserServer(browserName: string, configFile?: string) {
let options: LaunchServerOptions = {};
if (configFile)
options = JSON.parse(fs.readFileSync(configFile).toString());
const browserType = (playwright as any)[browserName] as BrowserType;
const server = await browserType.launchServer(options);
console.log(server.wsEndpoint());
}

export async function installBrowsers(browserNames?: BrowserName[]) {
await installBrowsersWithProgressBar(browserNames);
}