MCPcopy Index your code
hub / github.com/microsoft/playwright / JavaCodeGen

Class JavaCodeGen

packages/trace-viewer/src/ui/codegen.ts:262–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262class JavaCodeGen implements APIRequestCodegen {
263 generatePlaywrightRequestCall(request: har.Request, body: string | undefined): string {
264 const url = new URL(request.url);
265 const params = [`"${url.origin}${url.pathname}"`];
266
267 const options: string[] = [];
268
269 let method = request.method.toLowerCase();
270 if (!['delete', 'get', 'head', 'post', 'put', 'patch'].includes(method)) {
271 options.push(`setMethod("${method}")`);
272 method = 'fetch';
273 }
274
275 for (const [key, value] of url.searchParams)
276 options.push(`setQueryParam(${this.stringLiteral(key)}, ${this.stringLiteral(value)})`);
277 if (body)
278 options.push(`setData(${this.stringLiteral(body)})`);
279 for (const header of request.headers)
280 options.push(`setHeader(${this.stringLiteral(header.name)}, ${this.stringLiteral(header.value)})`);
281
282 if (options.length > 0)
283 params.push(`RequestOptions.create()\n .${options.join('\n .')}\n`);
284 return `request.${method}(${params.join(', ')});`;
285 }
286
287 private stringLiteral(v: string): string {
288 return JSON.stringify(v);
289 }
290}
291
292export function getAPIRequestCodeGen(language: Language): APIRequestCodegen {
293 if (language === 'javascript')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…