selenium-webdriver 4.0.0-alpha.4 → 4.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.eslintrc.js +27 -0
  2. package/.prettierrc +4 -0
  3. package/CHANGES.md +22 -1
  4. package/README.md +4 -4
  5. package/chrome.js +72 -590
  6. package/chromium.js +1024 -0
  7. package/devtools/CDPConnection.js +37 -0
  8. package/devtools/generator/protocol-dts-generator.js +429 -0
  9. package/edge.js +124 -86
  10. package/firefox.js +201 -202
  11. package/http/index.js +131 -115
  12. package/http/util.js +56 -64
  13. package/ie.js +180 -104
  14. package/index.js +246 -199
  15. package/io/exec.js +34 -39
  16. package/io/index.js +141 -151
  17. package/io/zip.js +75 -65
  18. package/lib/README +5 -0
  19. package/lib/actions.js +138 -121
  20. package/lib/atoms/find-elements.js +123 -0
  21. package/lib/atoms/get-attribute.js +79 -60
  22. package/lib/atoms/is-displayed.js +72 -73
  23. package/{example/chrome_mobile_emulation.js → lib/atoms/make-atoms-module.js} +16 -23
  24. package/lib/by.js +192 -65
  25. package/lib/capabilities.js +82 -78
  26. package/lib/command.js +18 -20
  27. package/lib/error.js +134 -168
  28. package/lib/http.js +324 -230
  29. package/lib/input.js +325 -302
  30. package/lib/logging.js +127 -138
  31. package/lib/promise.js +60 -66
  32. package/lib/proxy.js +31 -41
  33. package/lib/session.js +12 -15
  34. package/lib/symbols.js +3 -4
  35. package/lib/until.js +162 -162
  36. package/lib/webdriver.js +733 -522
  37. package/net/index.js +30 -36
  38. package/net/portprober.js +31 -144
  39. package/opera.js +406 -0
  40. package/package.json +18 -11
  41. package/proxy.js +2 -2
  42. package/remote/index.js +190 -187
  43. package/safari.js +40 -49
  44. package/LICENSE +0 -202
  45. package/NOTICE +0 -2
  46. package/example/chrome_android.js +0 -42
  47. package/example/firefox_channels.js +0 -77
  48. package/example/google_search.js +0 -50
  49. package/example/google_search_test.js +0 -72
  50. package/example/headless.js +0 -55
  51. package/example/logging.js +0 -68
  52. package/testing/index.js +0 -498
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Licensed to the Software Freedom Conservancy (SFC) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The SFC licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ class CDPConnection {
21
+ constructor(wsConnection) {
22
+ this._wsConnection = wsConnection
23
+ }
24
+
25
+ execute(method, id, params, callback) {
26
+ const message = {
27
+ method,
28
+ id: id,
29
+ }
30
+
31
+ const mergedMessage = Object.assign({ params: params }, message)
32
+
33
+ this._wsConnection.send(JSON.stringify(mergedMessage), callback)
34
+ }
35
+ }
36
+
37
+ exports.CdpConnection = CDPConnection
@@ -0,0 +1,429 @@
1
+ 'use strict'
2
+ var __spreadArrays =
3
+ (this && this.__spreadArrays) ||
4
+ function () {
5
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++)
6
+ s += arguments[i].length
7
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
8
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
9
+ r[k] = a[j]
10
+ return r
11
+ }
12
+ exports.__esModule = true
13
+ var fs = require('fs')
14
+ var path = require('path')
15
+ console.log(process.argv)
16
+ // TODO: @noj validate this via https://github.com/andischerer/typescript-json-typesafe against protocol-schema.d.ts
17
+ var jsProtocol = JSON.parse(fs.readFileSync(process.argv[3]))
18
+ var browserProtocol = JSON.parse(fs.readFileSync(process.argv[2]))
19
+ var protocolDomains = jsProtocol.domains.concat(browserProtocol.domains)
20
+ var numIndents = 0
21
+ var emitStr = ''
22
+ var emit = function (str) {
23
+ emitStr += str
24
+ }
25
+ var getIndent = function () {
26
+ return ' '.repeat(numIndents)
27
+ } // 4 spaced indents
28
+ var emitIndent = function () {
29
+ emitStr += getIndent()
30
+ }
31
+ var emitLine = function (str) {
32
+ if (str) {
33
+ emitIndent()
34
+ emit(str + '\n')
35
+ } else {
36
+ emit('\n')
37
+ }
38
+ }
39
+ var emitOpenBlock = function (str, openChar) {
40
+ if (openChar === void 0) {
41
+ openChar = ' {'
42
+ }
43
+ emitLine('' + str + openChar)
44
+ numIndents++
45
+ }
46
+ var emitCloseBlock = function (closeChar) {
47
+ if (closeChar === void 0) {
48
+ closeChar = '}'
49
+ }
50
+ numIndents--
51
+ emitLine(closeChar)
52
+ }
53
+ var emitHeaderComments = function () {
54
+ emitLine(
55
+ '/**********************************************************************'
56
+ )
57
+ emitLine(
58
+ ' * Auto-generated by protocol-dts-generator.ts, do not edit manually. *'
59
+ )
60
+ emitLine(
61
+ ' **********************************************************************/'
62
+ )
63
+ emitLine()
64
+ }
65
+ var fixCamelCase = function (name) {
66
+ var prefix = ''
67
+ var result = name
68
+ if (name[0] === '-') {
69
+ prefix = 'Negative'
70
+ result = name.substring(1)
71
+ }
72
+ var refined = result.split('-').map(toTitleCase).join('')
73
+ return (
74
+ prefix +
75
+ refined.replace(/HTML|XML|WML|API/i, function (match) {
76
+ return match.toUpperCase()
77
+ })
78
+ )
79
+ }
80
+ var emitEnum = function (enumName, enumValues) {
81
+ emitOpenBlock('export const enum ' + enumName)
82
+ enumValues.forEach(function (value) {
83
+ emitLine(fixCamelCase(value) + " = '" + value + "',")
84
+ })
85
+ emitCloseBlock()
86
+ }
87
+ var emitModule = function (moduleName, domains) {
88
+ moduleName = toTitleCase(moduleName)
89
+ emitHeaderComments()
90
+ emitOpenBlock('export namespace ' + moduleName)
91
+ emitGlobalTypeDefs()
92
+ domains.forEach(emitDomain)
93
+ emitCloseBlock()
94
+ emitLine()
95
+ emitLine('export default ' + moduleName + ';')
96
+ }
97
+ var emitGlobalTypeDefs = function () {
98
+ emitLine()
99
+ emitLine('export type integer = number')
100
+ }
101
+ var emitDomain = function (domain) {
102
+ var domainName = toTitleCase(domain.domain)
103
+ emitLine()
104
+ emitDescription(domain.description)
105
+ emitOpenBlock('export namespace ' + domainName)
106
+ if (domain.types) domain.types.forEach(emitDomainType)
107
+ if (domain.commands) domain.commands.forEach(emitCommand)
108
+ if (domain.events) domain.events.forEach(emitEvent)
109
+ emitCloseBlock()
110
+ }
111
+ var getCommentLines = function (description) {
112
+ var lines = description.split(/\r?\n/g).map(function (line) {
113
+ return ' * ' + line
114
+ })
115
+ return __spreadArrays(['/**'], lines, [' */'])
116
+ }
117
+ var emitDescription = function (description) {
118
+ if (description)
119
+ getCommentLines(description).map(function (l) {
120
+ return emitLine(l)
121
+ })
122
+ }
123
+ var isPropertyInlineEnum = function (prop) {
124
+ if ('$ref' in prop) {
125
+ return false
126
+ }
127
+ return (
128
+ prop.type === 'string' &&
129
+ prop['enum'] !== null &&
130
+ prop['enum'] !== undefined
131
+ )
132
+ }
133
+ var getPropertyDef = function (interfaceName, prop) {
134
+ // Quote key if it has a . in it.
135
+ var propName = prop.name.includes('.') ? "'" + prop.name + "'" : prop.name
136
+ var type = getPropertyType(interfaceName, prop)
137
+ return '' + propName + (prop.optional ? '?' : '') + ': ' + type
138
+ }
139
+ var getPropertyType = function (interfaceName, prop) {
140
+ if ('$ref' in prop) return prop.$ref
141
+ else if (prop.type === 'array')
142
+ return getPropertyType(interfaceName, prop.items) + '[]'
143
+ else if (prop.type === 'object')
144
+ if (!prop.properties) {
145
+ // TODO: actually 'any'? or can use generic '[key: string]: string'?
146
+ return 'any'
147
+ } else {
148
+ // hack: access indent, \n directly
149
+ var objStr = '{\n'
150
+ numIndents++
151
+ objStr += prop.properties
152
+ .map(function (p) {
153
+ return '' + getIndent() + getPropertyDef(interfaceName, p) + ';\n'
154
+ })
155
+ .join('')
156
+ numIndents--
157
+ objStr += getIndent() + '}'
158
+ return objStr
159
+ }
160
+ else if (prop.type === 'string' && prop['enum'])
161
+ return (
162
+ '(' +
163
+ prop['enum']
164
+ .map(function (v) {
165
+ return "'" + v + "'"
166
+ })
167
+ .join(' | ') +
168
+ ')'
169
+ )
170
+ return prop.type
171
+ }
172
+ var emitProperty = function (interfaceName, prop) {
173
+ var description = prop.description
174
+ if (isPropertyInlineEnum(prop)) {
175
+ var enumName = interfaceName + toTitleCase(prop.name)
176
+ description = (description || '') + ' (' + enumName + ' enum)'
177
+ }
178
+ emitDescription(description)
179
+ emitLine(getPropertyDef(interfaceName, prop) + ';')
180
+ }
181
+ var emitInlineEnumForDomainType = function (type) {
182
+ if (type.type === 'object') {
183
+ emitInlineEnums(type.id, type.properties)
184
+ }
185
+ }
186
+ var emitInlineEnumsForCommands = function (command) {
187
+ emitInlineEnums(toCmdRequestName(command.name), command.parameters)
188
+ emitInlineEnums(toCmdResponseName(command.name), command.returns)
189
+ }
190
+ var emitInlineEnumsForEvents = function (event) {
191
+ emitInlineEnums(toEventPayloadName(event.name), event.parameters)
192
+ }
193
+ var emitInlineEnums = function (prefix, propertyTypes) {
194
+ if (!propertyTypes) {
195
+ return
196
+ }
197
+ for (
198
+ var _i = 0, propertyTypes_1 = propertyTypes;
199
+ _i < propertyTypes_1.length;
200
+ _i++
201
+ ) {
202
+ var type = propertyTypes_1[_i]
203
+ if (isPropertyInlineEnum(type)) {
204
+ emitLine()
205
+ var enumName = prefix + toTitleCase(type.name)
206
+ emitEnum(enumName, type['enum'] || [])
207
+ }
208
+ }
209
+ }
210
+ var emitInterface = function (interfaceName, props) {
211
+ emitOpenBlock('export interface ' + interfaceName)
212
+ props
213
+ ? props.forEach(function (prop) {
214
+ return emitProperty(interfaceName, prop)
215
+ })
216
+ : emitLine('[key: string]: string;')
217
+ emitCloseBlock()
218
+ }
219
+ var emitDomainType = function (type) {
220
+ emitInlineEnumForDomainType(type)
221
+ emitLine()
222
+ emitDescription(type.description)
223
+ if (type.type === 'object') {
224
+ emitInterface(type.id, type.properties)
225
+ } else {
226
+ emitLine(
227
+ 'export type ' + type.id + ' = ' + getPropertyType(type.id, type) + ';'
228
+ )
229
+ }
230
+ }
231
+ var toTitleCase = function (str) {
232
+ return str[0].toUpperCase() + str.substr(1)
233
+ }
234
+ var toCmdRequestName = function (commandName) {
235
+ return toTitleCase(commandName) + 'Request'
236
+ }
237
+ var toCmdResponseName = function (commandName) {
238
+ return toTitleCase(commandName) + 'Response'
239
+ }
240
+ var emitCommand = function (command) {
241
+ emitInlineEnumsForCommands(command)
242
+ // TODO(bckenny): should description be emitted for params and return types?
243
+ if (command.parameters) {
244
+ emitLine()
245
+ emitInterface(toCmdRequestName(command.name), command.parameters)
246
+ }
247
+ if (command.returns) {
248
+ emitLine()
249
+ emitInterface(toCmdResponseName(command.name), command.returns)
250
+ }
251
+ }
252
+ var toEventPayloadName = function (eventName) {
253
+ return toTitleCase(eventName) + 'Event'
254
+ }
255
+ var emitEvent = function (event) {
256
+ if (!event.parameters) {
257
+ return
258
+ }
259
+ emitInlineEnumsForEvents(event)
260
+ emitLine()
261
+ emitDescription(event.description)
262
+ emitInterface(toEventPayloadName(event.name), event.parameters)
263
+ }
264
+ var getEventMapping = function (event, domainName, modulePrefix) {
265
+ // Use TS3.0+ tuples
266
+ var payloadType = event.parameters
267
+ ? '[' +
268
+ modulePrefix +
269
+ '.' +
270
+ domainName +
271
+ '.' +
272
+ toEventPayloadName(event.name) +
273
+ ']'
274
+ : '[]'
275
+ return {
276
+ // domain-prefixed name since it will be used outside of the module.
277
+ name: domainName + '.' + event.name,
278
+ description: event.description,
279
+ $ref: payloadType,
280
+ }
281
+ }
282
+ var isWeakInterface = function (params) {
283
+ return params.every(function (p) {
284
+ return !!p.optional
285
+ })
286
+ }
287
+ var getCommandMapping = function (command, domainName, modulePrefix) {
288
+ var prefix = modulePrefix + '.' + domainName + '.'
289
+ // Use TS3.0+ tuples for paramsType
290
+ var requestType = '[]'
291
+ if (command.parameters) {
292
+ var optional = isWeakInterface(command.parameters) ? '?' : ''
293
+ requestType = '[' + prefix + toCmdRequestName(command.name) + optional + ']'
294
+ }
295
+ var responseType = command.returns
296
+ ? prefix + toCmdResponseName(command.name)
297
+ : 'void'
298
+ return {
299
+ type: 'object',
300
+ name: domainName + '.' + command.name,
301
+ description: command.description,
302
+ properties: [
303
+ {
304
+ name: 'paramsType',
305
+ $ref: requestType,
306
+ },
307
+ {
308
+ name: 'returnType',
309
+ $ref: responseType,
310
+ },
311
+ ],
312
+ }
313
+ }
314
+ var flatten = function (arr) {
315
+ var _a
316
+ return (_a = []).concat.apply(_a, arr)
317
+ }
318
+ var emitMapping = function (moduleName, protocolModuleName, domains) {
319
+ moduleName = toTitleCase(moduleName)
320
+ emitHeaderComments()
321
+ emitLine("import Protocol from './" + protocolModuleName + "'")
322
+ emitLine()
323
+ emitDescription(
324
+ 'Mappings from protocol event and command names to the types required for them.'
325
+ )
326
+ emitOpenBlock('export namespace ' + moduleName)
327
+ var protocolModulePrefix = toTitleCase(protocolModuleName)
328
+ var eventDefs = flatten(
329
+ domains.map(function (d) {
330
+ var domainName = toTitleCase(d.domain)
331
+ return (d.events || []).map(function (e) {
332
+ return getEventMapping(e, domainName, protocolModulePrefix)
333
+ })
334
+ })
335
+ )
336
+ emitInterface('Events', eventDefs)
337
+ emitLine()
338
+ var commandDefs = flatten(
339
+ domains.map(function (d) {
340
+ var domainName = toTitleCase(d.domain)
341
+ return (d.commands || []).map(function (c) {
342
+ return getCommandMapping(c, domainName, protocolModulePrefix)
343
+ })
344
+ })
345
+ )
346
+ emitInterface('Commands', commandDefs)
347
+ emitCloseBlock()
348
+ emitLine()
349
+ emitLine('export default ' + moduleName + ';')
350
+ }
351
+ var emitApiCommand = function (command, domainName, modulePrefix) {
352
+ var prefix = modulePrefix + '.' + domainName + '.'
353
+ emitDescription(command.description)
354
+ var params = command.parameters
355
+ ? 'params: ' + prefix + toCmdRequestName(command.name)
356
+ : ''
357
+ var response = command.returns
358
+ ? '' + prefix + toCmdResponseName(command.name)
359
+ : 'void'
360
+ emitLine(command.name + '(' + params + '): Promise<' + response + '>;')
361
+ emitLine()
362
+ }
363
+ var emitApiEvent = function (event, domainName, modulePrefix) {
364
+ var prefix = modulePrefix + '.' + domainName + '.'
365
+ emitDescription(event.description)
366
+ var params = event.parameters
367
+ ? 'params: ' + prefix + toEventPayloadName(event.name)
368
+ : ''
369
+ emitLine(
370
+ "on(event: '" + event.name + "', listener: (" + params + ') => void): void;'
371
+ )
372
+ emitLine()
373
+ }
374
+ var emitDomainApi = function (domain, modulePrefix) {
375
+ emitLine()
376
+ var domainName = toTitleCase(domain.domain)
377
+ emitOpenBlock('export interface ' + domainName + 'Api')
378
+ if (domain.commands)
379
+ domain.commands.forEach(function (c) {
380
+ return emitApiCommand(c, domainName, modulePrefix)
381
+ })
382
+ if (domain.events)
383
+ domain.events.forEach(function (e) {
384
+ return emitApiEvent(e, domainName, modulePrefix)
385
+ })
386
+ emitCloseBlock()
387
+ }
388
+ var emitApi = function (moduleName, protocolModuleName, domains) {
389
+ moduleName = toTitleCase(moduleName)
390
+ emitHeaderComments()
391
+ emitLine("import Protocol from './" + protocolModuleName + "'")
392
+ emitLine()
393
+ emitDescription('API generated from Protocol commands and events.')
394
+ emitOpenBlock('export namespace ' + moduleName)
395
+ emitLine()
396
+ emitOpenBlock('export interface ProtocolApi')
397
+ domains.forEach(function (d) {
398
+ emitLine(d.domain + ': ' + d.domain + 'Api;')
399
+ emitLine()
400
+ })
401
+ emitCloseBlock()
402
+ emitLine()
403
+ var protocolModulePrefix = toTitleCase(protocolModuleName)
404
+ domains.forEach(function (d) {
405
+ return emitDomainApi(d, protocolModulePrefix)
406
+ })
407
+ emitCloseBlock()
408
+ emitLine()
409
+ emitLine('export default ' + moduleName + ';')
410
+ }
411
+ var flushEmitToFile = function (path) {
412
+ console.log('Writing to ' + path)
413
+ fs.writeFileSync(path, emitStr, { encoding: 'utf-8' })
414
+ numIndents = 0
415
+ emitStr = ''
416
+ }
417
+ // Main
418
+ var destProtocolFilePath = process.argv[4]
419
+ var protocolModuleName = path.basename(destProtocolFilePath, '.d.js')
420
+ emitModule(protocolModuleName, protocolDomains)
421
+ flushEmitToFile(destProtocolFilePath)
422
+ var destMappingFilePath = process.argv[5]
423
+ var mappingModuleName = 'ProtocolMapping'
424
+ emitMapping(mappingModuleName, protocolModuleName, protocolDomains)
425
+ flushEmitToFile(destMappingFilePath)
426
+ var destApiFilePath = process.argv[6]
427
+ var apiModuleName = 'ProtocolProxyApi'
428
+ emitApi(apiModuleName, protocolModuleName, protocolDomains)
429
+ flushEmitToFile(destApiFilePath)