Skip to content

Commit

Permalink
feat(inspector): send api names along with metainfo (#5518)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Feb 20, 2021
1 parent 46c8c29 commit f154a82
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 347 deletions.
108 changes: 54 additions & 54 deletions src/client/android.ts
Expand Up @@ -50,8 +50,8 @@ export class Android extends ChannelOwner<channels.AndroidChannel, channels.Andr
}

async devices(): Promise<AndroidDevice[]> {
return this._wrapApiCall('android.devices', async () => {
const { devices } = await this._channel.devices();
return this._wrapApiCall('android.devices', async (channel: channels.AndroidChannel) => {
const { devices } = await channel.devices();
return devices.map(d => AndroidDevice.from(d));
});
}
Expand Down Expand Up @@ -116,14 +116,14 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c
}

async wait(selector: api.AndroidSelector, options?: { state?: 'gone' } & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.wait', async () => {
await this._channel.wait({ selector: toSelectorChannel(selector), ...options });
await this._wrapApiCall('androidDevice.wait', async (channel: channels.AndroidDeviceChannel) => {
await channel.wait({ selector: toSelectorChannel(selector), ...options });
});
}

async fill(selector: api.AndroidSelector, text: string, options?: types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.fill', async () => {
await this._channel.fill({ selector: toSelectorChannel(selector), text, ...options });
await this._wrapApiCall('androidDevice.fill', async (channel: channels.AndroidDeviceChannel) => {
await channel.fill({ selector: toSelectorChannel(selector), text, ...options });
});
}

Expand All @@ -133,62 +133,62 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c
}

async tap(selector: api.AndroidSelector, options?: { duration?: number } & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.tap', async () => {
await this._channel.tap({ selector: toSelectorChannel(selector), ...options });
await this._wrapApiCall('androidDevice.tap', async (channel: channels.AndroidDeviceChannel) => {
await channel.tap({ selector: toSelectorChannel(selector), ...options });
});
}

async drag(selector: api.AndroidSelector, dest: types.Point, options?: SpeedOptions & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.drag', async () => {
await this._channel.drag({ selector: toSelectorChannel(selector), dest, ...options });
await this._wrapApiCall('androidDevice.drag', async (channel: channels.AndroidDeviceChannel) => {
await channel.drag({ selector: toSelectorChannel(selector), dest, ...options });
});
}

async fling(selector: api.AndroidSelector, direction: Direction, options?: SpeedOptions & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.fling', async () => {
await this._channel.fling({ selector: toSelectorChannel(selector), direction, ...options });
await this._wrapApiCall('androidDevice.fling', async (channel: channels.AndroidDeviceChannel) => {
await channel.fling({ selector: toSelectorChannel(selector), direction, ...options });
});
}

async longTap(selector: api.AndroidSelector, options?: types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.longTap', async () => {
await this._channel.longTap({ selector: toSelectorChannel(selector), ...options });
await this._wrapApiCall('androidDevice.longTap', async (channel: channels.AndroidDeviceChannel) => {
await channel.longTap({ selector: toSelectorChannel(selector), ...options });
});
}

async pinchClose(selector: api.AndroidSelector, percent: number, options?: SpeedOptions & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.pinchClose', async () => {
await this._channel.pinchClose({ selector: toSelectorChannel(selector), percent, ...options });
await this._wrapApiCall('androidDevice.pinchClose', async (channel: channels.AndroidDeviceChannel) => {
await channel.pinchClose({ selector: toSelectorChannel(selector), percent, ...options });
});
}

async pinchOpen(selector: api.AndroidSelector, percent: number, options?: SpeedOptions & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.pinchOpen', async () => {
await this._channel.pinchOpen({ selector: toSelectorChannel(selector), percent, ...options });
await this._wrapApiCall('androidDevice.pinchOpen', async (channel: channels.AndroidDeviceChannel) => {
await channel.pinchOpen({ selector: toSelectorChannel(selector), percent, ...options });
});
}

async scroll(selector: api.AndroidSelector, direction: Direction, percent: number, options?: SpeedOptions & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.scroll', async () => {
await this._channel.scroll({ selector: toSelectorChannel(selector), direction, percent, ...options });
await this._wrapApiCall('androidDevice.scroll', async (channel: channels.AndroidDeviceChannel) => {
await channel.scroll({ selector: toSelectorChannel(selector), direction, percent, ...options });
});
}

async swipe(selector: api.AndroidSelector, direction: Direction, percent: number, options?: SpeedOptions & types.TimeoutOptions) {
await this._wrapApiCall('androidDevice.swipe', async () => {
await this._channel.swipe({ selector: toSelectorChannel(selector), direction, percent, ...options });
await this._wrapApiCall('androidDevice.swipe', async (channel: channels.AndroidDeviceChannel) => {
await channel.swipe({ selector: toSelectorChannel(selector), direction, percent, ...options });
});
}

async info(selector: api.AndroidSelector): Promise<api.AndroidElementInfo> {
return await this._wrapApiCall('androidDevice.info', async () => {
return (await this._channel.info({ selector: toSelectorChannel(selector) })).info;
return await this._wrapApiCall('androidDevice.info', async (channel: channels.AndroidDeviceChannel) => {
return (await channel.info({ selector: toSelectorChannel(selector) })).info;
});
}

async screenshot(options: { path?: string } = {}): Promise<Buffer> {
return await this._wrapApiCall('androidDevice.screenshot', async () => {
const { binary } = await this._channel.screenshot();
return await this._wrapApiCall('androidDevice.screenshot', async (channel: channels.AndroidDeviceChannel) => {
const { binary } = await channel.screenshot();
const buffer = Buffer.from(binary, 'base64');
if (options.path)
await util.promisify(fs.writeFile)(options.path, buffer);
Expand All @@ -197,41 +197,41 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c
}

async close() {
return this._wrapApiCall('androidDevice.close', async () => {
await this._channel.close();
return this._wrapApiCall('androidDevice.close', async (channel: channels.AndroidDeviceChannel) => {
await channel.close();
this.emit(Events.AndroidDevice.Close);
});
}

async shell(command: string): Promise<Buffer> {
return this._wrapApiCall('androidDevice.shell', async () => {
const { result } = await this._channel.shell({ command });
return this._wrapApiCall('androidDevice.shell', async (channel: channels.AndroidDeviceChannel) => {
const { result } = await channel.shell({ command });
return Buffer.from(result, 'base64');
});
}

async open(command: string): Promise<AndroidSocket> {
return this._wrapApiCall('androidDevice.open', async () => {
return AndroidSocket.from((await this._channel.open({ command })).socket);
return this._wrapApiCall('androidDevice.open', async (channel: channels.AndroidDeviceChannel) => {
return AndroidSocket.from((await channel.open({ command })).socket);
});
}

async installApk(file: string | Buffer, options?: { args: string[] }): Promise<void> {
return this._wrapApiCall('androidDevice.installApk', async () => {
await this._channel.installApk({ file: await loadFile(file), args: options && options.args });
return this._wrapApiCall('androidDevice.installApk', async (channel: channels.AndroidDeviceChannel) => {
await channel.installApk({ file: await loadFile(file), args: options && options.args });
});
}

async push(file: string | Buffer, path: string, options?: { mode: number }): Promise<void> {
return this._wrapApiCall('androidDevice.push', async () => {
await this._channel.push({ file: await loadFile(file), path, mode: options ? options.mode : undefined });
return this._wrapApiCall('androidDevice.push', async (channel: channels.AndroidDeviceChannel) => {
await channel.push({ file: await loadFile(file), path, mode: options ? options.mode : undefined });
});
}

async launchBrowser(options: types.BrowserContextOptions & { pkg?: string } = {}): Promise<ChromiumBrowserContext> {
return this._wrapApiCall('androidDevice.launchBrowser', async () => {
return this._wrapApiCall('androidDevice.launchBrowser', async (channel: channels.AndroidDeviceChannel) => {
const contextOptions = await prepareBrowserContextParams(options);
const { context } = await this._channel.launchBrowser(contextOptions);
const { context } = await channel.launchBrowser(contextOptions);
return BrowserContext.from(context) as ChromiumBrowserContext;
});
}
Expand Down Expand Up @@ -261,14 +261,14 @@ export class AndroidSocket extends ChannelOwner<channels.AndroidSocketChannel, c
}

async write(data: Buffer): Promise<void> {
return this._wrapApiCall('androidDevice.write', async () => {
await this._channel.write({ data: data.toString('base64') });
return this._wrapApiCall('androidDevice.write', async (channel: channels.AndroidSocketChannel) => {
await channel.write({ data: data.toString('base64') });
});
}

async close(): Promise<void> {
return this._wrapApiCall('androidDevice.close', async () => {
await this._channel.close();
return this._wrapApiCall('androidDevice.close', async (channel: channels.AndroidSocketChannel) => {
await channel.close();
});
}
}
Expand All @@ -287,32 +287,32 @@ export class AndroidInput implements api.AndroidInput {
}

async type(text: string) {
return this._device._wrapApiCall('androidDevice.inputType', async () => {
await this._device._channel.inputType({ text });
return this._device._wrapApiCall('androidDevice.inputType', async (channel: channels.AndroidDeviceChannel) => {
await channel.inputType({ text });
});
}

async press(key: api.AndroidKey) {
return this._device._wrapApiCall('androidDevice.inputPress', async () => {
await this._device._channel.inputPress({ key });
return this._device._wrapApiCall('androidDevice.inputPress', async (channel: channels.AndroidDeviceChannel) => {
await channel.inputPress({ key });
});
}

async tap(point: types.Point) {
return this._device._wrapApiCall('androidDevice.inputTap', async () => {
await this._device._channel.inputTap({ point });
return this._device._wrapApiCall('androidDevice.inputTap', async (channel: channels.AndroidDeviceChannel) => {
await channel.inputTap({ point });
});
}

async swipe(from: types.Point, segments: types.Point[], steps: number) {
return this._device._wrapApiCall('androidDevice.inputSwipe', async () => {
await this._device._channel.inputSwipe({ segments, steps });
return this._device._wrapApiCall('androidDevice.inputSwipe', async (channel: channels.AndroidDeviceChannel) => {
await channel.inputSwipe({ segments, steps });
});
}

async drag(from: types.Point, to: types.Point, steps: number) {
return this._device._wrapApiCall('androidDevice.inputDragAndDrop', async () => {
await this._device._channel.inputDrag({ from, to, steps });
return this._device._wrapApiCall('androidDevice.inputDragAndDrop', async (channel: channels.AndroidDeviceChannel) => {
await channel.inputDrag({ from, to, steps });
});
}
}
Expand Down Expand Up @@ -393,8 +393,8 @@ export class AndroidWebView extends EventEmitter implements api.AndroidWebView {
}

private async _fetchPage(): Promise<Page> {
return this._device._wrapApiCall('androidWebView.page', async () => {
const { context } = await this._device._channel.connectToWebView({ pid: this._data.pid, sdkLanguage: 'javascript' });
return this._device._wrapApiCall('androidWebView.page', async (channel: channels.AndroidDeviceChannel) => {
const { context } = await channel.connectToWebView({ pid: this._data.pid, sdkLanguage: 'javascript' });
return BrowserContext.from(context).pages()[0];
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/client/browser.ts
Expand Up @@ -44,11 +44,11 @@ export class Browser extends ChannelOwner<channels.BrowserChannel, channels.Brow
}

async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {
return this._wrapApiCall('browser.newContext', async () => {
return this._wrapApiCall('browser.newContext', async (channel: channels.BrowserChannel) => {
if (this._isRemote && options._traceDir)
throw new Error(`"_traceDir" is not supported in connected browser`);
const contextOptions = await prepareBrowserContextParams(options);
const context = BrowserContext.from((await this._channel.newContext(contextOptions)).context);
const context = BrowserContext.from((await channel.newContext(contextOptions)).context);
context._options = contextOptions;
this._contexts.add(context);
context._logger = options.logger || this._logger;
Expand Down Expand Up @@ -78,8 +78,8 @@ export class Browser extends ChannelOwner<channels.BrowserChannel, channels.Brow

async close(): Promise<void> {
try {
await this._wrapApiCall('browser.close', async () => {
await this._channel.close();
await this._wrapApiCall('browser.close', async (channel: channels.BrowserChannel) => {
await channel.close();
await this._closedPromise;
});
} catch (e) {
Expand Down

0 comments on commit f154a82

Please sign in to comment.