Skip to content

Commit ab3b8a1

Browse files
authored
cherry-pick(release-1.9): launch-server command (#5713) (#5719)
1 parent 4e317b3 commit ab3b8a1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/cli/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import path from 'path';
2222
import program from 'commander';
2323
import os from 'os';
2424
import fs from 'fs';
25-
import { runServer, printApiJson, installBrowsers } from './driver';
25+
import { runServer, printApiJson, launchBrowserServer, installBrowsers } from './driver';
2626
import { showTraceViewer } from './traceViewer/traceViewer';
2727
import * as playwright from '../..';
2828
import { BrowserContext } from '../client/browserContext';
@@ -162,6 +162,8 @@ if (process.argv[2] === 'run-driver')
162162
runServer();
163163
else if (process.argv[2] === 'print-api-json')
164164
printApiJson();
165+
else if (process.argv[2] === 'launch-server')
166+
launchBrowserServer(process.argv[3], process.argv[4]);
165167
else
166168
program.parse(process.argv);
167169

src/cli/driver.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import fs from 'fs';
2020
import path from 'path';
21+
import * as playwright from '../..';
22+
import { BrowserType } from '../client/browserType';
23+
import { LaunchServerOptions } from '../client/types';
2124
import { DispatcherConnection } from '../dispatchers/dispatcher';
2225
import { PlaywrightDispatcher } from '../dispatchers/playwrightDispatcher';
2326
import { installBrowsersWithProgressBar } from '../install/installer';
@@ -53,6 +56,15 @@ export function runServer() {
5356
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
5457
}
5558

59+
export async function launchBrowserServer(browserName: string, configFile?: string) {
60+
let options: LaunchServerOptions = {};
61+
if (configFile)
62+
options = JSON.parse(fs.readFileSync(configFile).toString());
63+
const browserType = (playwright as any)[browserName] as BrowserType;
64+
const server = await browserType.launchServer(options);
65+
console.log(server.wsEndpoint());
66+
}
67+
5668
export async function installBrowsers(browserNames?: BrowserName[]) {
5769
await installBrowsersWithProgressBar(browserNames);
5870
}

0 commit comments

Comments
 (0)