mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: make Android host option configurable (#13685)
This commit is contained in:
parent
8c4fc62e8f
commit
4a3180aca9
@ -82,10 +82,15 @@ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
|
||||
|
||||
Returns the list of detected Android devices.
|
||||
|
||||
### option: Android.devices.host
|
||||
- `host` <[string]>
|
||||
|
||||
Optional host to establish ADB server connection. Default to `127.0.0.1`.
|
||||
|
||||
### option: Android.devices.port
|
||||
- `port` <[int]>
|
||||
|
||||
Optional port to establish ADB server connection.
|
||||
Optional port to establish ADB server connection. Default to `5037`.
|
||||
|
||||
### option: Android.devices.omitDriverInstall
|
||||
- `omitDriverInstall` <[boolean]>
|
||||
|
||||
@ -3697,10 +3697,12 @@ export interface AndroidChannel extends AndroidEventTarget, Channel {
|
||||
setDefaultTimeoutNoReply(params: AndroidSetDefaultTimeoutNoReplyParams, metadata?: Metadata): Promise<AndroidSetDefaultTimeoutNoReplyResult>;
|
||||
}
|
||||
export type AndroidDevicesParams = {
|
||||
host?: string,
|
||||
port?: number,
|
||||
omitDriverInstall?: boolean,
|
||||
};
|
||||
export type AndroidDevicesOptions = {
|
||||
host?: string,
|
||||
port?: number,
|
||||
omitDriverInstall?: boolean,
|
||||
};
|
||||
|
||||
@ -2852,6 +2852,7 @@ Android:
|
||||
|
||||
devices:
|
||||
parameters:
|
||||
host: string?
|
||||
port: number?
|
||||
omitDriverInstall: boolean?
|
||||
returns:
|
||||
|
||||
@ -1308,6 +1308,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||
});
|
||||
scheme.ElectronApplicationCloseParams = tOptional(tObject({}));
|
||||
scheme.AndroidDevicesParams = tObject({
|
||||
host: tOptional(tString),
|
||||
port: tOptional(tNumber),
|
||||
omitDriverInstall: tOptional(tBoolean),
|
||||
});
|
||||
|
||||
@ -23,18 +23,27 @@ import { assert, createGuid } from '../../utils';
|
||||
|
||||
export class AdbBackend implements Backend {
|
||||
async devices(options: types.AndroidDeviceOptions = {}): Promise<DeviceBackend[]> {
|
||||
const port = options.port ? options.port : 5037;
|
||||
const result = await runCommand('host:devices', port);
|
||||
const result = await runCommand('host:devices', options.host, options.port);
|
||||
const lines = result.toString().trim().split('\n');
|
||||
return lines.map(line => {
|
||||
const [serial, status] = line.trim().split('\t');
|
||||
return new AdbDevice(serial, status, port);
|
||||
return new AdbDevice(serial, status, options.host, options.port);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class AdbDevice implements DeviceBackend {
|
||||
constructor(readonly serial: string, readonly status: string, readonly port: number) { }
|
||||
serial: string;
|
||||
status: string;
|
||||
host: string | undefined;
|
||||
port: number | undefined;
|
||||
|
||||
constructor(serial: string, status: string, host?: string, port?: number) {
|
||||
this.serial = serial;
|
||||
this.status = status;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
async init() {
|
||||
}
|
||||
@ -43,19 +52,19 @@ class AdbDevice implements DeviceBackend {
|
||||
}
|
||||
|
||||
runCommand(command: string): Promise<Buffer> {
|
||||
return runCommand(command, this.port, this.serial);
|
||||
return runCommand(command, this.host, this.port, this.serial);
|
||||
}
|
||||
|
||||
async open(command: string): Promise<SocketBackend> {
|
||||
const result = await open(command, this.port, this.serial);
|
||||
const result = await open(command, this.host, this.port, this.serial);
|
||||
result.becomeSocket();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
async function runCommand(command: string, port: number = 5037, serial?: string): Promise<Buffer> {
|
||||
async function runCommand(command: string, host: string = '127.0.0.1', port: number = 5037, serial?: string): Promise<Buffer> {
|
||||
debug('pw:adb:runCommand')(command, serial);
|
||||
const socket = new BufferedSocketWrapper(command, net.createConnection({ port }));
|
||||
const socket = new BufferedSocketWrapper(command, net.createConnection({ host, port }));
|
||||
if (serial) {
|
||||
await socket.write(encodeMessage(`host:transport:${serial}`));
|
||||
const status = await socket.read(4);
|
||||
@ -75,8 +84,8 @@ async function runCommand(command: string, port: number = 5037, serial?: string)
|
||||
return commandOutput;
|
||||
}
|
||||
|
||||
async function open(command: string, port: number = 5037, serial?: string): Promise<BufferedSocketWrapper> {
|
||||
const socket = new BufferedSocketWrapper(command, net.createConnection({ port }));
|
||||
async function open(command: string, host: string = '127.0.0.1', port: number = 5037, serial?: string): Promise<BufferedSocketWrapper> {
|
||||
const socket = new BufferedSocketWrapper(command, net.createConnection({ host, port }));
|
||||
if (serial) {
|
||||
await socket.write(encodeMessage(`host:transport:${serial}`));
|
||||
const status = await socket.read(4);
|
||||
|
||||
@ -369,6 +369,7 @@ export type APIResponse = {
|
||||
};
|
||||
|
||||
export type AndroidDeviceOptions = {
|
||||
host?: string,
|
||||
port?: number,
|
||||
omitDriverInstall?: boolean,
|
||||
};
|
||||
|
||||
7
packages/playwright-core/types/types.d.ts
vendored
7
packages/playwright-core/types/types.d.ts
vendored
@ -11108,13 +11108,18 @@ export interface Android {
|
||||
* @param options
|
||||
*/
|
||||
devices(options?: {
|
||||
/**
|
||||
* Optional host to establish ADB server connection. Default to `127.0.0.1`.
|
||||
*/
|
||||
host?: string;
|
||||
|
||||
/**
|
||||
* Prevents automatic playwright driver installation on attach. Assumes that the drivers have been installed already.
|
||||
*/
|
||||
omitDriverInstall?: boolean;
|
||||
|
||||
/**
|
||||
* Optional port to establish ADB server connection.
|
||||
* Optional port to establish ADB server connection. Default to `5037`.
|
||||
*/
|
||||
port?: number;
|
||||
}): Promise<Array<AndroidDevice>>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user