MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / generateClass

Function generateClass

javascript/selenium-webdriver/generate_bidi.mjs:892–934  ·  view source on GitHub ↗
({ className, commands, events, enhancement })

Source from the content-addressed store, hash-verified

890}
891
892function generateClass({ className, commands, events, enhancement }) {
893 const lines = []
894
895 lines.push(`export class ${className} {`)
896 lines.push(` private constructor(private readonly bidi: BidiConnection) {}`)
897 lines.push('')
898 lines.push(` static async create(driver: unknown): Promise<${className}> {`)
899 lines.push(
900 ` const caps = await (driver as { getCapabilities(): Promise<{ get(key: string): unknown }> }).getCapabilities()`,
901 )
902 lines.push(` if (!caps.get('webSocketUrl')) {`)
903 lines.push(` throw new Error('WebDriver instance must support BiDi protocol')`)
904 lines.push(` }`)
905 lines.push(` const bidi = await (driver as { getBidi(): Promise<BidiConnection> }).getBidi()`)
906 lines.push(` return new ${className}(bidi)`)
907 lines.push(` }`)
908
909 for (const cmd of commands) {
910 const override = enhancement.extraMethods?.[cmd.methodName]
911 lines.push('')
912 lines.push(override ?? generateCommandMethod(cmd))
913 }
914
915 for (const evt of events) {
916 const override = enhancement.extraMethods?.[evt.onMethodName]
917 lines.push('')
918 lines.push(override ?? generateEventMethod(evt))
919 }
920
921 if (enhancement.extraMethods) {
922 const knownNames = new Set([...commands.map((c) => c.methodName), ...events.map((e) => e.onMethodName)])
923 for (const [name, body] of Object.entries(enhancement.extraMethods)) {
924 if (!knownNames.has(name)) {
925 // Purely additive method not tied to a command or event.
926 lines.push('')
927 lines.push(body)
928 }
929 }
930 }
931
932 lines.push(`}`)
933 return lines.join('\n')
934}
935
936function generateCommandMethod(cmd) {
937 const { methodName, methodStr, paramsTypeName, hasParams, resultTypeName } = cmd

Callers 1

generateDomainFileFunction · 0.85

Calls 5

generateCommandMethodFunction · 0.85
generateEventMethodFunction · 0.85
joinMethod · 0.80
mapMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected