Skip to content

Commit f154a82

Browse files
authored
feat(inspector): send api names along with metainfo (#5518)
1 parent 46c8c29 commit f154a82

17 files changed

+354
-347
lines changed

src/client/android.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export class Android extends ChannelOwner<channels.AndroidChannel, channels.Andr
5050
}
5151

5252
async devices(): Promise<AndroidDevice[]> {
53-
return this._wrapApiCall('android.devices', async () => {
54-
const { devices } = await this._channel.devices();
53+
return this._wrapApiCall('android.devices', async (channel: channels.AndroidChannel) => {
54+
const { devices } = await channel.devices();
5555
return devices.map(d => AndroidDevice.from(d));
5656
});
5757
}
@@ -116,14 +116,14 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c
116116
}
117117

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

124124
async fill(selector: api.AndroidSelector, text: string, options?: types.TimeoutOptions) {
125-
await this._wrapApiCall('androidDevice.fill', async () => {
126-
await this._channel.fill({ selector: toSelectorChannel(selector), text, ...options });
125+
await this._wrapApiCall('androidDevice.fill', async (channel: channels.AndroidDeviceChannel) => {
126+
await channel.fill({ selector: toSelectorChannel(selector), text, ...options });
127127
});
128128
}
129129

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

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

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

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

153153
async longTap(selector: api.AndroidSelector, options?: types.TimeoutOptions) {
154-
await this._wrapApiCall('androidDevice.longTap', async () => {
155-
await this._channel.longTap({ selector: toSelectorChannel(selector), ...options });
154+
await this._wrapApiCall('androidDevice.longTap', async (channel: channels.AndroidDeviceChannel) => {
155+
await channel.longTap({ selector: toSelectorChannel(selector), ...options });
156156
});
157157
}
158158

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

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

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

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

183183
async info(selector: api.AndroidSelector): Promise<api.AndroidElementInfo> {
184-
return await this._wrapApiCall('androidDevice.info', async () => {
185-
return (await this._channel.info({ selector: toSelectorChannel(selector) })).info;
184+
return await this._wrapApiCall('androidDevice.info', async (channel: channels.AndroidDeviceChannel) => {
185+
return (await channel.info({ selector: toSelectorChannel(selector) })).info;
186186
});
187187
}
188188

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

199199
async close() {
200-
return this._wrapApiCall('androidDevice.close', async () => {
201-
await this._channel.close();
200+
return this._wrapApiCall('androidDevice.close', async (channel: channels.AndroidDeviceChannel) => {
201+
await channel.close();
202202
this.emit(Events.AndroidDevice.Close);
203203
});
204204
}
205205

206206
async shell(command: string): Promise<Buffer> {
207-
return this._wrapApiCall('androidDevice.shell', async () => {
208-
const { result } = await this._channel.shell({ command });
207+
return this._wrapApiCall('androidDevice.shell', async (channel: channels.AndroidDeviceChannel) => {
208+
const { result } = await channel.shell({ command });
209209
return Buffer.from(result, 'base64');
210210
});
211211
}
212212

213213
async open(command: string): Promise<AndroidSocket> {
214-
return this._wrapApiCall('androidDevice.open', async () => {
215-
return AndroidSocket.from((await this._channel.open({ command })).socket);
214+
return this._wrapApiCall('androidDevice.open', async (channel: channels.AndroidDeviceChannel) => {
215+
return AndroidSocket.from((await channel.open({ command })).socket);
216216
});
217217
}
218218

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

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

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

263263
async write(data: Buffer): Promise<void> {
264-
return this._wrapApiCall('androidDevice.write', async () => {
265-
await this._channel.write({ data: data.toString('base64') });
264+
return this._wrapApiCall('androidDevice.write', async (channel: channels.AndroidSocketChannel) => {
265+
await channel.write({ data: data.toString('base64') });
266266
});
267267
}
268268

269269
async close(): Promise<void> {
270-
return this._wrapApiCall('androidDevice.close', async () => {
271-
await this._channel.close();
270+
return this._wrapApiCall('androidDevice.close', async (channel: channels.AndroidSocketChannel) => {
271+
await channel.close();
272272
});
273273
}
274274
}
@@ -287,32 +287,32 @@ export class AndroidInput implements api.AndroidInput {
287287
}
288288

289289
async type(text: string) {
290-
return this._device._wrapApiCall('androidDevice.inputType', async () => {
291-
await this._device._channel.inputType({ text });
290+
return this._device._wrapApiCall('androidDevice.inputType', async (channel: channels.AndroidDeviceChannel) => {
291+
await channel.inputType({ text });
292292
});
293293
}
294294

295295
async press(key: api.AndroidKey) {
296-
return this._device._wrapApiCall('androidDevice.inputPress', async () => {
297-
await this._device._channel.inputPress({ key });
296+
return this._device._wrapApiCall('androidDevice.inputPress', async (channel: channels.AndroidDeviceChannel) => {
297+
await channel.inputPress({ key });
298298
});
299299
}
300300

301301
async tap(point: types.Point) {
302-
return this._device._wrapApiCall('androidDevice.inputTap', async () => {
303-
await this._device._channel.inputTap({ point });
302+
return this._device._wrapApiCall('androidDevice.inputTap', async (channel: channels.AndroidDeviceChannel) => {
303+
await channel.inputTap({ point });
304304
});
305305
}
306306

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

313313
async drag(from: types.Point, to: types.Point, steps: number) {
314-
return this._device._wrapApiCall('androidDevice.inputDragAndDrop', async () => {
315-
await this._device._channel.inputDrag({ from, to, steps });
314+
return this._device._wrapApiCall('androidDevice.inputDragAndDrop', async (channel: channels.AndroidDeviceChannel) => {
315+
await channel.inputDrag({ from, to, steps });
316316
});
317317
}
318318
}
@@ -393,8 +393,8 @@ export class AndroidWebView extends EventEmitter implements api.AndroidWebView {
393393
}
394394

395395
private async _fetchPage(): Promise<Page> {
396-
return this._device._wrapApiCall('androidWebView.page', async () => {
397-
const { context } = await this._device._channel.connectToWebView({ pid: this._data.pid, sdkLanguage: 'javascript' });
396+
return this._device._wrapApiCall('androidWebView.page', async (channel: channels.AndroidDeviceChannel) => {
397+
const { context } = await channel.connectToWebView({ pid: this._data.pid, sdkLanguage: 'javascript' });
398398
return BrowserContext.from(context).pages()[0];
399399
});
400400
}

src/client/browser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ export class Browser extends ChannelOwner<channels.BrowserChannel, channels.Brow
4444
}
4545

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

7979
async close(): Promise<void> {
8080
try {
81-
await this._wrapApiCall('browser.close', async () => {
82-
await this._channel.close();
81+
await this._wrapApiCall('browser.close', async (channel: channels.BrowserChannel) => {
82+
await channel.close();
8383
await this._closedPromise;
8484
});
8585
} catch (e) {

0 commit comments

Comments
 (0)