@appium/base-driver 8.3.1 → 8.4.0

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 (115) hide show
  1. package/build/lib/basedriver/capabilities.d.ts +80 -0
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -0
  3. package/build/lib/basedriver/capabilities.js +11 -10
  4. package/build/lib/basedriver/commands/event.d.ts +9 -0
  5. package/build/lib/basedriver/commands/event.d.ts.map +1 -0
  6. package/build/lib/basedriver/commands/event.js +21 -21
  7. package/build/lib/basedriver/commands/find.d.ts +11 -0
  8. package/build/lib/basedriver/commands/find.d.ts.map +1 -0
  9. package/build/lib/basedriver/commands/find.js +44 -37
  10. package/build/lib/basedriver/commands/index.d.ts +8 -0
  11. package/build/lib/basedriver/commands/index.d.ts.map +1 -0
  12. package/build/lib/basedriver/commands/index.js +17 -14
  13. package/build/lib/basedriver/commands/log.d.ts +12 -0
  14. package/build/lib/basedriver/commands/log.d.ts.map +1 -0
  15. package/build/lib/basedriver/commands/log.js +24 -26
  16. package/build/lib/basedriver/commands/session.d.ts +11 -0
  17. package/build/lib/basedriver/commands/session.d.ts.map +1 -0
  18. package/build/lib/basedriver/commands/session.js +21 -147
  19. package/build/lib/basedriver/commands/settings.d.ts +10 -0
  20. package/build/lib/basedriver/commands/settings.d.ts.map +1 -0
  21. package/build/lib/basedriver/commands/settings.js +19 -17
  22. package/build/lib/basedriver/commands/timeout.d.ts +8 -0
  23. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -0
  24. package/build/lib/basedriver/commands/timeout.js +118 -137
  25. package/build/lib/basedriver/core.d.ts +235 -0
  26. package/build/lib/basedriver/core.d.ts.map +1 -0
  27. package/build/lib/basedriver/core.js +283 -0
  28. package/build/lib/basedriver/desired-caps.d.ts +5 -0
  29. package/build/lib/basedriver/desired-caps.d.ts.map +1 -0
  30. package/build/lib/basedriver/desired-caps.js +1 -1
  31. package/build/lib/basedriver/device-settings.d.ts +32 -0
  32. package/build/lib/basedriver/device-settings.d.ts.map +1 -0
  33. package/build/lib/basedriver/device-settings.js +19 -11
  34. package/build/lib/basedriver/driver.d.ts +83 -0
  35. package/build/lib/basedriver/driver.d.ts.map +1 -0
  36. package/build/lib/basedriver/driver.js +100 -266
  37. package/build/lib/basedriver/helpers.d.ts +132 -0
  38. package/build/lib/basedriver/helpers.d.ts.map +1 -0
  39. package/build/lib/basedriver/helpers.js +17 -1
  40. package/build/lib/basedriver/logger.d.ts +3 -0
  41. package/build/lib/basedriver/logger.d.ts.map +1 -0
  42. package/build/lib/constants.d.ts +9 -0
  43. package/build/lib/constants.d.ts.map +1 -0
  44. package/build/lib/express/crash.d.ts +3 -0
  45. package/build/lib/express/crash.d.ts.map +1 -0
  46. package/build/lib/express/express-logging.d.ts +3 -0
  47. package/build/lib/express/express-logging.d.ts.map +1 -0
  48. package/build/lib/express/idempotency.d.ts +2 -0
  49. package/build/lib/express/idempotency.d.ts.map +1 -0
  50. package/build/lib/express/logger.d.ts +3 -0
  51. package/build/lib/express/logger.d.ts.map +1 -0
  52. package/build/lib/express/middleware.d.ts +9 -0
  53. package/build/lib/express/middleware.d.ts.map +1 -0
  54. package/build/lib/express/server.d.ts +10 -0
  55. package/build/lib/express/server.d.ts.map +1 -0
  56. package/build/lib/express/static.d.ts +6 -0
  57. package/build/lib/express/static.d.ts.map +1 -0
  58. package/build/lib/express/websocket.d.ts +64 -0
  59. package/build/lib/express/websocket.d.ts.map +1 -0
  60. package/build/lib/helpers/capabilities.d.ts +13 -0
  61. package/build/lib/helpers/capabilities.d.ts.map +1 -0
  62. package/build/lib/helpers/capabilities.js +41 -1
  63. package/build/lib/index.d.ts +183 -0
  64. package/build/lib/index.d.ts.map +1 -0
  65. package/build/lib/index.js +40 -20
  66. package/build/lib/jsonwp-proxy/protocol-converter.d.ts +48 -0
  67. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -0
  68. package/build/lib/jsonwp-proxy/proxy.d.ts +41 -0
  69. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -0
  70. package/build/lib/jsonwp-status/status.d.ts +159 -0
  71. package/build/lib/jsonwp-status/status.d.ts.map +1 -0
  72. package/build/lib/protocol/errors.d.ts +310 -0
  73. package/build/lib/protocol/errors.d.ts.map +1 -0
  74. package/build/lib/protocol/errors.js +81 -2
  75. package/build/lib/protocol/helpers.d.ts +22 -0
  76. package/build/lib/protocol/helpers.d.ts.map +1 -0
  77. package/build/lib/protocol/index.d.ts +16 -0
  78. package/build/lib/protocol/index.d.ts.map +1 -0
  79. package/build/lib/protocol/index.js +7 -7
  80. package/build/lib/protocol/protocol.d.ts +11 -0
  81. package/build/lib/protocol/protocol.d.ts.map +1 -0
  82. package/build/lib/protocol/protocol.js +2 -6
  83. package/build/lib/protocol/routes.d.ts +6 -0
  84. package/build/lib/protocol/routes.d.ts.map +1 -0
  85. package/build/lib/protocol/routes.js +17 -1
  86. package/build/lib/protocol/validators.d.ts +8 -0
  87. package/build/lib/protocol/validators.d.ts.map +1 -0
  88. package/build/test/basedriver/driver-tests.js +30 -3
  89. package/build/test/unit/basedriver/commands/event.spec.js +7 -7
  90. package/build/test/unit/basedriver/commands/log.spec.js +31 -24
  91. package/build/test/unit/basedriver/timeout.spec.js +1 -1
  92. package/build/test/unit/protocol/routes.spec.js +2 -2
  93. package/build/tsconfig.tsbuildinfo +1 -0
  94. package/lib/basedriver/capabilities.js +49 -10
  95. package/lib/basedriver/commands/event.js +49 -31
  96. package/lib/basedriver/commands/find.js +108 -43
  97. package/lib/basedriver/commands/index.js +25 -19
  98. package/lib/basedriver/commands/log.js +60 -33
  99. package/lib/basedriver/commands/session.js +39 -141
  100. package/lib/basedriver/commands/settings.js +33 -13
  101. package/lib/basedriver/commands/timeout.js +153 -153
  102. package/lib/basedriver/core.js +497 -0
  103. package/lib/basedriver/desired-caps.js +1 -1
  104. package/lib/basedriver/device-settings.js +47 -12
  105. package/lib/basedriver/driver.js +273 -395
  106. package/lib/basedriver/helpers.js +18 -2
  107. package/lib/helpers/capabilities.js +60 -1
  108. package/lib/index.js +16 -12
  109. package/lib/protocol/errors.js +42 -42
  110. package/lib/protocol/index.js +4 -4
  111. package/lib/protocol/protocol.js +1 -3
  112. package/lib/protocol/routes.js +9 -0
  113. package/package.json +10 -9
  114. package/test/basedriver/driver-tests.js +31 -2
  115. package/index.d.ts +0 -386
@@ -1,167 +1,167 @@
1
- import { waitForCondition } from 'asyncbox';
1
+ // @ts-check
2
+
3
+ /* eslint-disable no-unused-vars */
4
+ /* eslint-disable require-await */
5
+ import {waitForCondition} from 'asyncbox';
2
6
  import _ from 'lodash';
3
- import { util } from '@appium/support';
4
- import { errors } from '../../protocol';
7
+ import {util} from '@appium/support';
8
+ import {errors} from '../../protocol';
5
9
 
10
+ const MIN_TIMEOUT = 0;
6
11
 
7
- let commands = {}, helpers = {}, extensions = {};
12
+ /**
13
+ * @param {import('../driver').BaseDriverBase} Base
14
+ * @returns {TimeoutBase}
15
+ */
16
+ export function TimeoutMixin (Base) {
17
+
18
+ /**
19
+ * @implements {ITimeoutCommands}
20
+ */
21
+ class TimeoutCommands extends Base {
22
+ async timeouts (type, ms, script, pageLoad, implicit) {
23
+ if (util.hasValue(type) && util.hasValue(ms)) {
24
+ this.log.debug(
25
+ `MJSONWP timeout arguments: ${JSON.stringify({type, ms})}}`,
26
+ );
27
+
28
+ switch (type) {
29
+ case 'command':
30
+ await this.newCommandTimeout(ms);
31
+ return;
32
+ case 'implicit':
33
+ await this.implicitWaitMJSONWP(ms);
34
+ return;
35
+ case 'page load':
36
+ await this.pageLoadTimeoutMJSONWP(ms);
37
+ return;
38
+ case 'script':
39
+ await this.scriptTimeoutMJSONWP(ms);
40
+ return;
41
+ default:
42
+ throw new Error(
43
+ `'${type}' type is not supported for MJSONWP timeout`,
44
+ );
45
+ }
46
+ }
8
47
 
9
- const MIN_TIMEOUT = 0;
48
+ // Otherwise assume it is W3C protocol
49
+ this.log.debug(
50
+ `W3C timeout argument: ${JSON.stringify({
51
+ script,
52
+ pageLoad,
53
+ implicit,
54
+ })}}`,
55
+ );
56
+ if (util.hasValue(script)) {
57
+ await this.scriptTimeoutW3C(script);
58
+ }
59
+ if (util.hasValue(pageLoad)) {
60
+ await this.pageLoadTimeoutW3C(pageLoad);
61
+ }
62
+ if (util.hasValue(implicit)) {
63
+ await this.implicitWaitW3C(implicit);
64
+ }
65
+ }
10
66
 
11
- commands.timeouts = async function timeouts (type, ms, script, pageLoad, implicit) {
12
- if (util.hasValue(type) && util.hasValue(ms)) {
13
- this.log.debug(`MJSONWP timeout arguments: ${JSON.stringify({type, ms})}}`);
14
-
15
- switch (type) {
16
- case 'command':
17
- await this.newCommandTimeout(ms);
18
- return;
19
- case 'implicit':
20
- await this.implicitWaitMJSONWP(ms);
21
- return;
22
- case 'page load':
23
- await this.pageLoadTimeoutMJSONWP(ms);
24
- return;
25
- case 'script':
26
- await this.scriptTimeoutMJSONWP(ms);
27
- return;
28
- default:
29
- throw new Error(`'${type}' type is not supported for MJSONWP timeout`);
67
+ async getTimeouts () {
68
+ return {
69
+ command: this.newCommandTimeoutMs,
70
+ implicit: this.implicitWaitMs,
71
+ };
30
72
  }
31
- }
32
73
 
33
- // Otherwise assume it is W3C protocol
34
- this.log.debug(`W3C timeout argument: ${JSON.stringify({script, pageLoad, implicit})}}`);
35
- if (util.hasValue(script)) {
36
- await this.scriptTimeoutW3C(script);
37
- }
38
- if (util.hasValue(pageLoad)) {
39
- await this.pageLoadTimeoutW3C(pageLoad);
40
- }
41
- if (util.hasValue(implicit)) {
42
- await this.implicitWaitW3C(implicit);
43
- }
44
- };
45
-
46
- commands.getTimeouts = async function getTimeouts () { // eslint-disable-line require-await
47
- return {
48
- command: this.newCommandTimeoutMs,
49
- implicit: this.implicitWaitMs,
50
- };
51
- };
52
-
53
- // implicit
54
- commands.implicitWaitW3C = async function implicitWaitW3C (ms) {
55
- await this.implicitWait(ms);
56
- };
57
-
58
- commands.implicitWaitMJSONWP = async function implicitWaitMJSONWP (ms) {
59
- await this.implicitWait(ms);
60
- };
61
-
62
- commands.implicitWait = async function implicitWait (ms) {
63
- await this.setImplicitWait(this.parseTimeoutArgument(ms));
64
- };
65
-
66
- helpers.setImplicitWait = function setImplicitWait (ms) { // eslint-disable-line require-await
67
- this.implicitWaitMs = ms;
68
- this.log.debug(`Set implicit wait to ${ms}ms`);
69
- if (this.managedDrivers && this.managedDrivers.length) {
70
- this.log.debug('Setting implicit wait on managed drivers');
71
- for (let driver of this.managedDrivers) {
72
- if (_.isFunction(driver.setImplicitWait)) {
73
- driver.setImplicitWait(ms);
74
+ // implicit
75
+ async implicitWaitW3C (ms) {
76
+ await this.implicitWait(ms);
77
+ }
78
+
79
+ async implicitWaitMJSONWP (ms) {
80
+ await this.implicitWait(ms);
81
+ }
82
+
83
+ async implicitWait (ms) {
84
+ await this.setImplicitWait(this.parseTimeoutArgument(ms));
85
+ }
86
+
87
+ // pageLoad
88
+ async pageLoadTimeoutW3C (ms) {
89
+ throw new errors.NotImplementedError('Not implemented yet for pageLoad.');
90
+ }
91
+
92
+ async pageLoadTimeoutMJSONWP (ms) {
93
+ throw new errors.NotImplementedError('Not implemented yet for pageLoad.');
94
+ }
95
+
96
+ // script
97
+ async scriptTimeoutW3C (ms) {
98
+ throw new errors.NotImplementedError('Not implemented yet for script.');
99
+ }
100
+
101
+ async scriptTimeoutMJSONWP (ms) {
102
+ throw new errors.NotImplementedError('Not implemented yet for script.');
103
+ }
104
+
105
+ // command
106
+ async newCommandTimeout (ms) {
107
+ this.setNewCommandTimeout(this.parseTimeoutArgument(ms));
108
+ }
109
+
110
+ setImplicitWait (ms) {
111
+ // eslint-disable-line require-await
112
+ this.implicitWaitMs = ms;
113
+ this.log.debug(`Set implicit wait to ${ms}ms`);
114
+ if (this.managedDrivers && this.managedDrivers.length) {
115
+ this.log.debug('Setting implicit wait on managed drivers');
116
+ for (let driver of this.managedDrivers) {
117
+ if (_.isFunction(driver.setImplicitWait)) {
118
+ driver.setImplicitWait(ms);
119
+ }
120
+ }
74
121
  }
75
122
  }
76
- }
77
- };
78
-
79
- // pageLoad
80
- // eslint-disable-next-line no-unused-vars
81
- commands.pageLoadTimeoutW3C = async function pageLoadTimeoutW3C (ms) { // eslint-disable-line require-await
82
- throw new errors.NotImplementedError('Not implemented yet for pageLoad.');
83
- };
84
-
85
- // eslint-disable-next-line no-unused-vars
86
- commands.pageLoadTimeoutMJSONWP = async function pageLoadTimeoutMJSONWP (ms) { // eslint-disable-line require-await
87
- throw new errors.NotImplementedError('Not implemented yet for pageLoad.');
88
- };
89
-
90
- // script
91
- // eslint-disable-next-line no-unused-vars
92
- commands.scriptTimeoutW3C = async function scriptTimeoutW3C (ms) { // eslint-disable-line require-await
93
- throw new errors.NotImplementedError('Not implemented yet for script.');
94
- };
95
-
96
- // eslint-disable-next-line no-unused-vars
97
- commands.scriptTimeoutMJSONWP = async function scriptTimeoutMJSONWP (ms) { // eslint-disable-line require-await
98
- throw new errors.NotImplementedError('Not implemented yet for script.');
99
- };
100
-
101
- // command
102
- commands.newCommandTimeout = async function newCommandTimeout (ms) { // eslint-disable-line require-await
103
- this.setNewCommandTimeout(this.parseTimeoutArgument(ms));
104
- };
105
-
106
- helpers.setNewCommandTimeout = function setNewCommandTimeout (ms) {
107
- this.newCommandTimeoutMs = ms;
108
- this.log.debug(`Set new command timeout to ${ms}ms`);
109
- if (this.managedDrivers && this.managedDrivers.length) {
110
- this.log.debug('Setting new command timeout on managed drivers');
111
- for (let driver of this.managedDrivers) {
112
- if (_.isFunction(driver.setNewCommandTimeout)) {
113
- driver.setNewCommandTimeout(ms);
123
+
124
+ setNewCommandTimeout (ms) {
125
+ this.newCommandTimeoutMs = ms;
126
+ this.log.debug(`Set new command timeout to ${ms}ms`);
127
+ if (this.managedDrivers && this.managedDrivers.length) {
128
+ this.log.debug('Setting new command timeout on managed drivers');
129
+ for (let driver of this.managedDrivers) {
130
+ if (_.isFunction(driver.setNewCommandTimeout)) {
131
+ driver.setNewCommandTimeout(ms);
132
+ }
133
+ }
114
134
  }
115
135
  }
116
- }
117
- };
118
136
 
119
- helpers.clearNewCommandTimeout = function clearNewCommandTimeout () {
120
- if (this.noCommandTimer) {
121
- clearTimeout(this.noCommandTimer);
122
- this.noCommandTimer = null;
123
- }
124
- };
125
-
126
- helpers.startNewCommandTimeout = function startNewCommandTimeout () {
127
- // make sure there are no rogue timeouts
128
- this.clearNewCommandTimeout();
129
-
130
- // if command timeout is 0, it is disabled
131
- if (!this.newCommandTimeoutMs) return; // eslint-disable-line curly
132
-
133
- this.noCommandTimer = setTimeout(async () => {
134
- this.log.warn(`Shutting down because we waited ` +
135
- `${this.newCommandTimeoutMs / 1000.0} seconds for a command`);
136
- const errorMessage = `New Command Timeout of ` +
137
- `${this.newCommandTimeoutMs / 1000.0} seconds ` +
138
- `expired. Try customizing the timeout using the ` +
139
- `'newCommandTimeout' desired capability`;
140
- await this.startUnexpectedShutdown(new Error(errorMessage));
141
- }, this.newCommandTimeoutMs);
142
- };
143
-
144
- helpers.implicitWaitForCondition = async function implicitWaitForCondition (condFn) {
145
- this.log.debug(`Waiting up to ${this.implicitWaitMs} ms for condition`);
146
- let wrappedCondFn = async (...args) => {
147
- // reset command timeout
148
- this.clearNewCommandTimeout();
149
-
150
- return await condFn(...args);
151
- };
152
- return await waitForCondition(wrappedCondFn, {
153
- waitMs: this.implicitWaitMs, intervalMs: 500, logger: this.log
154
- });
155
- };
156
-
157
- helpers.parseTimeoutArgument = function parseTimeoutArgument (ms) {
158
- let duration = parseInt(ms, 10);
159
- if (_.isNaN(duration) || duration < MIN_TIMEOUT) {
160
- throw new errors.UnknownError(`Invalid timeout value '${ms}'`);
137
+ async implicitWaitForCondition (condFn) {
138
+ this.log.debug(`Waiting up to ${this.implicitWaitMs} ms for condition`);
139
+ let wrappedCondFn = async (...args) => {
140
+ // reset command timeout
141
+ await this.clearNewCommandTimeout();
142
+
143
+ return await condFn(...args);
144
+ };
145
+ return await waitForCondition(wrappedCondFn, {
146
+ waitMs: this.implicitWaitMs,
147
+ intervalMs: 500,
148
+ logger: this.log,
149
+ });
150
+ }
151
+
152
+ parseTimeoutArgument (ms) {
153
+ let duration = parseInt(ms, 10);
154
+ if (_.isNaN(duration) || duration < MIN_TIMEOUT) {
155
+ throw new errors.UnknownError(`Invalid timeout value '${ms}'`);
156
+ }
157
+ return duration;
158
+ }
161
159
  }
162
- return duration;
163
- };
164
160
 
165
- Object.assign(extensions, commands, helpers);
166
- export { commands, helpers };
167
- export default extensions;
161
+ return TimeoutCommands;
162
+ }
163
+
164
+ /**
165
+ * @typedef {import('@appium/types').TimeoutCommands} ITimeoutCommands
166
+ * @typedef {import('../driver').BaseDriverBase<ITimeoutCommands>} TimeoutBase
167
+ */