appium-xcuitest-driver 10.3.0 → 10.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 (252) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/lib/commands/active-app-info.d.ts +9 -0
  3. package/build/lib/commands/active-app-info.d.ts.map +1 -0
  4. package/build/lib/commands/active-app-info.js +14 -0
  5. package/build/lib/commands/active-app-info.js.map +1 -0
  6. package/build/lib/commands/alert.d.ts +42 -45
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +66 -62
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +150 -153
  11. package/build/lib/commands/app-management.d.ts.map +1 -1
  12. package/build/lib/commands/app-management.js +300 -286
  13. package/build/lib/commands/app-management.js.map +1 -1
  14. package/build/lib/commands/app-strings.d.ts +14 -17
  15. package/build/lib/commands/app-strings.d.ts.map +1 -1
  16. package/build/lib/commands/app-strings.js +23 -24
  17. package/build/lib/commands/app-strings.js.map +1 -1
  18. package/build/lib/commands/appearance.d.ts +19 -22
  19. package/build/lib/commands/appearance.d.ts.map +1 -1
  20. package/build/lib/commands/appearance.js +56 -56
  21. package/build/lib/commands/appearance.js.map +1 -1
  22. package/build/lib/commands/audit.d.ts +22 -17
  23. package/build/lib/commands/audit.d.ts.map +1 -1
  24. package/build/lib/commands/audit.js +17 -18
  25. package/build/lib/commands/audit.js.map +1 -1
  26. package/build/lib/commands/battery.d.ts +11 -14
  27. package/build/lib/commands/battery.d.ts.map +1 -1
  28. package/build/lib/commands/battery.js +36 -37
  29. package/build/lib/commands/battery.js.map +1 -1
  30. package/build/lib/commands/biometric.d.ts +30 -33
  31. package/build/lib/commands/biometric.d.ts.map +1 -1
  32. package/build/lib/commands/biometric.js +42 -41
  33. package/build/lib/commands/biometric.js.map +1 -1
  34. package/build/lib/commands/certificate.d.ts +48 -45
  35. package/build/lib/commands/certificate.d.ts.map +1 -1
  36. package/build/lib/commands/certificate.js +218 -205
  37. package/build/lib/commands/certificate.js.map +1 -1
  38. package/build/lib/commands/clipboard.d.ts +19 -22
  39. package/build/lib/commands/clipboard.d.ts.map +1 -1
  40. package/build/lib/commands/clipboard.js +30 -30
  41. package/build/lib/commands/clipboard.js.map +1 -1
  42. package/build/lib/commands/condition.d.ts +49 -26
  43. package/build/lib/commands/condition.d.ts.map +1 -1
  44. package/build/lib/commands/condition.js +87 -86
  45. package/build/lib/commands/condition.js.map +1 -1
  46. package/build/lib/commands/content-size.d.ts +26 -29
  47. package/build/lib/commands/content-size.d.ts.map +1 -1
  48. package/build/lib/commands/content-size.js +36 -36
  49. package/build/lib/commands/content-size.js.map +1 -1
  50. package/build/lib/commands/context.d.ts +161 -108
  51. package/build/lib/commands/context.d.ts.map +1 -1
  52. package/build/lib/commands/context.js +530 -517
  53. package/build/lib/commands/context.js.map +1 -1
  54. package/build/lib/commands/deviceInfo.d.ts +9 -12
  55. package/build/lib/commands/deviceInfo.d.ts.map +1 -1
  56. package/build/lib/commands/deviceInfo.js +17 -18
  57. package/build/lib/commands/deviceInfo.js.map +1 -1
  58. package/build/lib/commands/element.d.ts +102 -105
  59. package/build/lib/commands/element.d.ts.map +1 -1
  60. package/build/lib/commands/element.js +337 -323
  61. package/build/lib/commands/element.js.map +1 -1
  62. package/build/lib/commands/execute.d.ts +24 -19
  63. package/build/lib/commands/execute.d.ts.map +1 -1
  64. package/build/lib/commands/execute.js +63 -62
  65. package/build/lib/commands/execute.js.map +1 -1
  66. package/build/lib/commands/file-movement.d.ts +77 -80
  67. package/build/lib/commands/file-movement.d.ts.map +1 -1
  68. package/build/lib/commands/file-movement.js +130 -124
  69. package/build/lib/commands/file-movement.js.map +1 -1
  70. package/build/lib/commands/find.d.ts +18 -21
  71. package/build/lib/commands/find.d.ts.map +1 -1
  72. package/build/lib/commands/find.js +158 -156
  73. package/build/lib/commands/find.js.map +1 -1
  74. package/build/lib/commands/general.d.ts +124 -116
  75. package/build/lib/commands/general.d.ts.map +1 -1
  76. package/build/lib/commands/general.js +248 -232
  77. package/build/lib/commands/general.js.map +1 -1
  78. package/build/lib/commands/geolocation.d.ts +43 -46
  79. package/build/lib/commands/geolocation.d.ts.map +1 -1
  80. package/build/lib/commands/geolocation.js +10 -11
  81. package/build/lib/commands/geolocation.js.map +1 -1
  82. package/build/lib/commands/gesture.d.ts +273 -276
  83. package/build/lib/commands/gesture.d.ts.map +1 -1
  84. package/build/lib/commands/gesture.js +506 -492
  85. package/build/lib/commands/gesture.js.map +1 -1
  86. package/build/lib/commands/increase-contrast.d.ts +20 -23
  87. package/build/lib/commands/increase-contrast.d.ts.map +1 -1
  88. package/build/lib/commands/increase-contrast.js +30 -30
  89. package/build/lib/commands/increase-contrast.js.map +1 -1
  90. package/build/lib/commands/iohid.d.ts +1370 -1373
  91. package/build/lib/commands/iohid.d.ts.map +1 -1
  92. package/build/lib/commands/iohid.js +30 -31
  93. package/build/lib/commands/iohid.js.map +1 -1
  94. package/build/lib/commands/keyboard.d.ts +29 -32
  95. package/build/lib/commands/keyboard.d.ts.map +1 -1
  96. package/build/lib/commands/keyboard.js +53 -51
  97. package/build/lib/commands/keyboard.js.map +1 -1
  98. package/build/lib/commands/keychains.d.ts +9 -12
  99. package/build/lib/commands/keychains.d.ts.map +1 -1
  100. package/build/lib/commands/keychains.js +13 -14
  101. package/build/lib/commands/keychains.js.map +1 -1
  102. package/build/lib/commands/localization.d.ts +16 -19
  103. package/build/lib/commands/localization.d.ts.map +1 -1
  104. package/build/lib/commands/localization.js +25 -26
  105. package/build/lib/commands/localization.js.map +1 -1
  106. package/build/lib/commands/location.d.ts +36 -39
  107. package/build/lib/commands/location.d.ts.map +1 -1
  108. package/build/lib/commands/location.js +99 -98
  109. package/build/lib/commands/location.js.map +1 -1
  110. package/build/lib/commands/lock.d.ts +21 -24
  111. package/build/lib/commands/lock.d.ts.map +1 -1
  112. package/build/lib/commands/lock.js +39 -38
  113. package/build/lib/commands/lock.js.map +1 -1
  114. package/build/lib/commands/log.d.ts +43 -37
  115. package/build/lib/commands/log.d.ts.map +1 -1
  116. package/build/lib/commands/log.js +174 -171
  117. package/build/lib/commands/log.js.map +1 -1
  118. package/build/lib/commands/memory.d.ts +9 -12
  119. package/build/lib/commands/memory.d.ts.map +1 -1
  120. package/build/lib/commands/memory.js +37 -38
  121. package/build/lib/commands/memory.js.map +1 -1
  122. package/build/lib/commands/navigation.d.ts +30 -33
  123. package/build/lib/commands/navigation.d.ts.map +1 -1
  124. package/build/lib/commands/navigation.js +92 -92
  125. package/build/lib/commands/navigation.js.map +1 -1
  126. package/build/lib/commands/notifications.d.ts +26 -29
  127. package/build/lib/commands/notifications.d.ts.map +1 -1
  128. package/build/lib/commands/notifications.js +53 -53
  129. package/build/lib/commands/notifications.js.map +1 -1
  130. package/build/lib/commands/pasteboard.d.ts +21 -24
  131. package/build/lib/commands/pasteboard.d.ts.map +1 -1
  132. package/build/lib/commands/pasteboard.js +37 -37
  133. package/build/lib/commands/pasteboard.js.map +1 -1
  134. package/build/lib/commands/pcap.d.ts +39 -26
  135. package/build/lib/commands/pcap.d.ts.map +1 -1
  136. package/build/lib/commands/pcap.js +81 -81
  137. package/build/lib/commands/pcap.js.map +1 -1
  138. package/build/lib/commands/performance.d.ts +63 -44
  139. package/build/lib/commands/performance.d.ts.map +1 -1
  140. package/build/lib/commands/performance.js +105 -105
  141. package/build/lib/commands/performance.js.map +1 -1
  142. package/build/lib/commands/permissions.d.ts +33 -36
  143. package/build/lib/commands/permissions.d.ts.map +1 -1
  144. package/build/lib/commands/permissions.js +66 -65
  145. package/build/lib/commands/permissions.js.map +1 -1
  146. package/build/lib/commands/proxy-helper.d.ts +12 -15
  147. package/build/lib/commands/proxy-helper.d.ts.map +1 -1
  148. package/build/lib/commands/proxy-helper.js +53 -54
  149. package/build/lib/commands/proxy-helper.js.map +1 -1
  150. package/build/lib/commands/record-audio.d.ts +49 -29
  151. package/build/lib/commands/record-audio.d.ts.map +1 -1
  152. package/build/lib/commands/record-audio.js +100 -104
  153. package/build/lib/commands/record-audio.js.map +1 -1
  154. package/build/lib/commands/recordscreen.d.ts +54 -18
  155. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  156. package/build/lib/commands/recordscreen.js +127 -129
  157. package/build/lib/commands/recordscreen.js.map +1 -1
  158. package/build/lib/commands/screenshots.d.ts +14 -17
  159. package/build/lib/commands/screenshots.d.ts.map +1 -1
  160. package/build/lib/commands/screenshots.js +108 -107
  161. package/build/lib/commands/screenshots.js.map +1 -1
  162. package/build/lib/commands/simctl.d.ts +11 -14
  163. package/build/lib/commands/simctl.d.ts.map +1 -1
  164. package/build/lib/commands/simctl.js +23 -26
  165. package/build/lib/commands/simctl.js.map +1 -1
  166. package/build/lib/commands/source.d.ts +14 -17
  167. package/build/lib/commands/source.d.ts.map +1 -1
  168. package/build/lib/commands/source.js +40 -43
  169. package/build/lib/commands/source.js.map +1 -1
  170. package/build/lib/commands/timeouts.d.ts +44 -33
  171. package/build/lib/commands/timeouts.d.ts.map +1 -1
  172. package/build/lib/commands/timeouts.js +65 -63
  173. package/build/lib/commands/timeouts.js.map +1 -1
  174. package/build/lib/commands/web.d.ts +247 -197
  175. package/build/lib/commands/web.d.ts.map +1 -1
  176. package/build/lib/commands/web.js +815 -786
  177. package/build/lib/commands/web.js.map +1 -1
  178. package/build/lib/commands/xctest-record-screen.d.ts +63 -66
  179. package/build/lib/commands/xctest-record-screen.d.ts.map +1 -1
  180. package/build/lib/commands/xctest-record-screen.js +103 -102
  181. package/build/lib/commands/xctest-record-screen.js.map +1 -1
  182. package/build/lib/commands/xctest.d.ts +55 -51
  183. package/build/lib/commands/xctest.d.ts.map +1 -1
  184. package/build/lib/commands/xctest.js +116 -117
  185. package/build/lib/commands/xctest.js.map +1 -1
  186. package/build/lib/driver.d.ts +278 -1597
  187. package/build/lib/driver.d.ts.map +1 -1
  188. package/build/lib/driver.js +319 -235
  189. package/build/lib/driver.js.map +1 -1
  190. package/build/lib/execute-method-map.d.ts.map +1 -1
  191. package/build/lib/execute-method-map.js +9 -0
  192. package/build/lib/execute-method-map.js.map +1 -1
  193. package/lib/commands/active-app-info.js +12 -0
  194. package/lib/commands/alert.js +68 -65
  195. package/lib/commands/app-management.js +308 -301
  196. package/lib/commands/app-strings.js +24 -26
  197. package/lib/commands/appearance.js +54 -56
  198. package/lib/commands/audit.js +18 -20
  199. package/lib/commands/battery.js +35 -37
  200. package/lib/commands/biometric.js +44 -46
  201. package/lib/commands/certificate.js +226 -215
  202. package/lib/commands/clipboard.js +30 -32
  203. package/lib/commands/condition.js +98 -100
  204. package/lib/commands/content-size.js +36 -38
  205. package/lib/commands/context.js +495 -490
  206. package/lib/commands/deviceInfo.js +19 -20
  207. package/lib/commands/element.js +367 -357
  208. package/lib/commands/execute.js +72 -72
  209. package/lib/commands/file-movement.js +132 -134
  210. package/lib/commands/find.js +160 -159
  211. package/lib/commands/general.js +238 -231
  212. package/lib/commands/geolocation.js +6 -14
  213. package/lib/commands/gesture.js +525 -515
  214. package/lib/commands/increase-contrast.js +30 -32
  215. package/lib/commands/iohid.js +32 -34
  216. package/lib/commands/keyboard.js +49 -51
  217. package/lib/commands/keychains.js +12 -14
  218. package/lib/commands/localization.js +24 -26
  219. package/lib/commands/location.js +102 -104
  220. package/lib/commands/lock.js +38 -38
  221. package/lib/commands/log.js +197 -198
  222. package/lib/commands/memory.js +40 -42
  223. package/lib/commands/navigation.js +96 -100
  224. package/lib/commands/notifications.js +57 -59
  225. package/lib/commands/pasteboard.js +37 -39
  226. package/lib/commands/pcap.js +84 -86
  227. package/lib/commands/performance.js +132 -133
  228. package/lib/commands/permissions.js +67 -69
  229. package/lib/commands/proxy-helper.js +60 -61
  230. package/lib/commands/record-audio.js +115 -120
  231. package/lib/commands/recordscreen.js +145 -149
  232. package/lib/commands/screenshots.js +116 -116
  233. package/lib/commands/simctl.js +25 -29
  234. package/lib/commands/source.js +42 -46
  235. package/lib/commands/timeouts.js +59 -63
  236. package/lib/commands/web.js +878 -858
  237. package/lib/commands/xctest-record-screen.js +103 -105
  238. package/lib/commands/xctest.js +134 -139
  239. package/lib/driver.js +287 -235
  240. package/lib/execute-method-map.ts +9 -0
  241. package/npm-shrinkwrap.json +2 -2
  242. package/package.json +1 -1
  243. package/build/lib/commands/activeAppInfo.d.ts +0 -12
  244. package/build/lib/commands/activeAppInfo.d.ts.map +0 -1
  245. package/build/lib/commands/activeAppInfo.js +0 -15
  246. package/build/lib/commands/activeAppInfo.js.map +0 -1
  247. package/build/lib/commands/index.d.ts +0 -96
  248. package/build/lib/commands/index.d.ts.map +0 -1
  249. package/build/lib/commands/index.js +0 -100
  250. package/build/lib/commands/index.js.map +0 -1
  251. package/lib/commands/activeAppInfo.js +0 -14
  252. package/lib/commands/index.js +0 -95
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AudioRecorder = void 0;
4
+ exports.startAudioRecording = startAudioRecording;
5
+ exports.stopAudioRecording = stopAudioRecording;
4
6
  const support_1 = require("appium/support");
5
7
  const teen_process_1 = require("teen_process");
6
8
  const utils_1 = require("../utils");
@@ -119,113 +121,107 @@ class AudioRecorder {
119
121
  }
120
122
  }
121
123
  exports.AudioRecorder = AudioRecorder;
122
- exports.default = {
123
- /**
124
- * @type {AudioRecorder|null}
125
- */
126
- _audioRecorder: null,
127
- /**
128
- * Records the given hardware audio input and saves it into an `.mp4` file.
129
- *
130
- * **To use this command, the `audio_record` security feature must be enabled _and_ [FFMpeg](https://ffmpeg.org/) must be installed on the Appium server.**
131
- *
132
- * @param {string|number} audioInput - The name of the corresponding audio input device to use for the capture. The full list of capture devices could be shown by executing `ffmpeg -f avfoundation -list_devices true -i ""`
133
- * @param {string|number} timeLimit - The maximum recording time, in seconds.
134
- * @param {string} audioCodec - The name of the audio codec.
135
- * @param {string} audioBitrate - The bitrate of the resulting audio stream.
136
- * @param {string|number} audioChannels - The count of audio channels in the resulting stream. Setting it to `1` will create a single channel (mono) audio stream.
137
- * @param {string|number} audioRate - The sampling rate of the resulting audio stream (in Hz).
138
- * @param {boolean} forceRestart - Whether to restart audio capture process forcefully when `mobile: startRecordingAudio` is called (`true`) or ignore the call until the current audio recording is completed (`false`).
139
- * @group Real Device Only
140
- * @this {XCUITestDriver}
141
- * @returns {Promise<void>}
142
- * @privateRemarks Using string literals for the default parameters makes better documentation.
143
- */
144
- async startAudioRecording(audioInput, timeLimit = 180, audioCodec = 'aac', audioBitrate = '128k', audioChannels = 2, audioRate = 44100, forceRestart = false) {
145
- if (!this.isFeatureEnabled(AUDIO_RECORD_FEAT_NAME)) {
146
- throw this.log.errorWithException(`Audio capture feature must be enabled on the server side. ` +
147
- `Please set '--relaxed-security' or '--allow-insecure' with '${AUDIO_RECORD_FEAT_NAME}' option. ` +
148
- `Read https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md for more details.`);
149
- }
150
- if (!audioInput) {
151
- throw this.log.errorWithException(`The mandatory audioInput option is not provided. Please set it ` +
152
- `to a correct value (e. g. ':1'). Use 'ffmpeg -f avfoundation -list_devices true -i ""' ` +
153
- `command to list available input sources`);
154
- }
155
- if (this._audioRecorder?.isRecording()) {
156
- this.log.info(`There is an active audio recording process`);
157
- if (forceRestart) {
158
- this.log.info(`Stopping it because 'forceRestart' option is set to true`);
159
- await this._audioRecorder.interrupt(true);
160
- }
161
- else {
162
- this.log.info(`Doing nothing. ` +
163
- `Set 'forceRestart' option to true if you'd like to start a new audio recording session`);
164
- return;
165
- }
166
- }
167
- if (this._audioRecorder) {
168
- await this._audioRecorder.cleanup();
169
- this._audioRecorder = null;
170
- }
171
- const audioPath = await support_1.tempDir.path({
172
- prefix: `appium_${support_1.util.uuidV4().substring(0, 8)}`,
173
- suffix: DEFAULT_EXT,
174
- });
175
- const audioRecorder = new AudioRecorder(audioInput, this.log, audioPath, {
176
- audioSource: DEFAULT_SOURCE,
177
- audioCodec,
178
- audioBitrate,
179
- audioChannels,
180
- audioRate,
181
- });
182
- const timeoutSeconds = parseInt(String(timeLimit), 10);
183
- if (isNaN(timeoutSeconds) || timeoutSeconds > MAX_RECORDING_TIME_SEC || timeoutSeconds <= 0) {
184
- throw this.log.errorWithException(`The timeLimit value must be in range [1, ${MAX_RECORDING_TIME_SEC}] seconds. ` +
185
- `The value of '${timeLimit}' has been passed instead.`);
186
- }
187
- try {
188
- await audioRecorder.start(timeoutSeconds);
189
- }
190
- catch (e) {
191
- await audioRecorder.interrupt(true);
192
- await audioRecorder.cleanup();
193
- throw e;
194
- }
195
- this._audioRecorder = audioRecorder;
196
- },
197
- /**
198
- * Stop recording of the audio input. If no audio recording process is running then
199
- * the endpoint will try to get the recently recorded file.
200
- * If no previously recorded file is found and no active audio recording
201
- * processes are running then the method returns an empty string.
202
- *
203
- * @returns {Promise<string>} Base64-encoded content of the recorded media file or an
204
- * empty string if no audio recording has been started before.
205
- * @throws {Error} If there was an error while getting the recorded file.
206
- * @this {XCUITestDriver}
207
- */
208
- async stopAudioRecording() {
209
- if (!this._audioRecorder) {
210
- this.log.info('Audio recording has not been started. There is nothing to stop');
211
- return '';
124
+ /**
125
+ * Records the given hardware audio input and saves it into an `.mp4` file.
126
+ *
127
+ * **To use this command, the `audio_record` security feature must be enabled _and_ [FFMpeg](https://ffmpeg.org/) must be installed on the Appium server.**
128
+ *
129
+ * @param {string|number} audioInput - The name of the corresponding audio input device to use for the capture. The full list of capture devices could be shown by executing `ffmpeg -f avfoundation -list_devices true -i ""`
130
+ * @param {string|number} timeLimit - The maximum recording time, in seconds.
131
+ * @param {string} audioCodec - The name of the audio codec.
132
+ * @param {string} audioBitrate - The bitrate of the resulting audio stream.
133
+ * @param {string|number} audioChannels - The count of audio channels in the resulting stream. Setting it to `1` will create a single channel (mono) audio stream.
134
+ * @param {string|number} audioRate - The sampling rate of the resulting audio stream (in Hz).
135
+ * @param {boolean} forceRestart - Whether to restart audio capture process forcefully when `mobile: startRecordingAudio` is called (`true`) or ignore the call until the current audio recording is completed (`false`).
136
+ * @group Real Device Only
137
+ * @this {XCUITestDriver}
138
+ * @returns {Promise<void>}
139
+ * @privateRemarks Using string literals for the default parameters makes better documentation.
140
+ */
141
+ async function startAudioRecording(audioInput, timeLimit = 180, audioCodec = 'aac', audioBitrate = '128k', audioChannels = 2, audioRate = 44100, forceRestart = false) {
142
+ if (!this.isFeatureEnabled(AUDIO_RECORD_FEAT_NAME)) {
143
+ throw this.log.errorWithException(`Audio capture feature must be enabled on the server side. ` +
144
+ `Please set '--relaxed-security' or '--allow-insecure' with '${AUDIO_RECORD_FEAT_NAME}' option. ` +
145
+ `Read https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md for more details.`);
146
+ }
147
+ if (!audioInput) {
148
+ throw this.log.errorWithException(`The mandatory audioInput option is not provided. Please set it ` +
149
+ `to a correct value (e. g. ':1'). Use 'ffmpeg -f avfoundation -list_devices true -i ""' ` +
150
+ `command to list available input sources`);
151
+ }
152
+ if (this._audioRecorder?.isRecording()) {
153
+ this.log.info(`There is an active audio recording process`);
154
+ if (forceRestart) {
155
+ this.log.info(`Stopping it because 'forceRestart' option is set to true`);
156
+ await this._audioRecorder.interrupt(true);
212
157
  }
213
- let resultPath;
214
- try {
215
- resultPath = await this._audioRecorder.finish();
216
- if (!(await support_1.fs.exists(resultPath))) {
217
- throw this.log.errorWithException(`${FFMPEG_BINARY} has failed ` + `to store the actual audio recording at '${resultPath}'`);
218
- }
158
+ else {
159
+ this.log.info(`Doing nothing. ` +
160
+ `Set 'forceRestart' option to true if you'd like to start a new audio recording session`);
161
+ return;
219
162
  }
220
- catch (e) {
221
- await this._audioRecorder.interrupt(true);
222
- await this._audioRecorder.cleanup();
223
- this._audioRecorder = null;
224
- throw e;
163
+ }
164
+ if (this._audioRecorder) {
165
+ await this._audioRecorder.cleanup();
166
+ this._audioRecorder = null;
167
+ }
168
+ const audioPath = await support_1.tempDir.path({
169
+ prefix: `appium_${support_1.util.uuidV4().substring(0, 8)}`,
170
+ suffix: DEFAULT_EXT,
171
+ });
172
+ const audioRecorder = new AudioRecorder(audioInput, this.log, audioPath, {
173
+ audioSource: DEFAULT_SOURCE,
174
+ audioCodec,
175
+ audioBitrate,
176
+ audioChannels,
177
+ audioRate,
178
+ });
179
+ const timeoutSeconds = parseInt(String(timeLimit), 10);
180
+ if (isNaN(timeoutSeconds) || timeoutSeconds > MAX_RECORDING_TIME_SEC || timeoutSeconds <= 0) {
181
+ throw this.log.errorWithException(`The timeLimit value must be in range [1, ${MAX_RECORDING_TIME_SEC}] seconds. ` +
182
+ `The value of '${timeLimit}' has been passed instead.`);
183
+ }
184
+ try {
185
+ await audioRecorder.start(timeoutSeconds);
186
+ }
187
+ catch (e) {
188
+ await audioRecorder.interrupt(true);
189
+ await audioRecorder.cleanup();
190
+ throw e;
191
+ }
192
+ this._audioRecorder = audioRecorder;
193
+ }
194
+ /**
195
+ * Stop recording of the audio input. If no audio recording process is running then
196
+ * the endpoint will try to get the recently recorded file.
197
+ * If no previously recorded file is found and no active audio recording
198
+ * processes are running then the method returns an empty string.
199
+ *
200
+ * @returns {Promise<string>} Base64-encoded content of the recorded media file or an
201
+ * empty string if no audio recording has been started before.
202
+ * @throws {Error} If there was an error while getting the recorded file.
203
+ * @this {XCUITestDriver}
204
+ */
205
+ async function stopAudioRecording() {
206
+ if (!this._audioRecorder) {
207
+ this.log.info('Audio recording has not been started. There is nothing to stop');
208
+ return '';
209
+ }
210
+ let resultPath;
211
+ try {
212
+ resultPath = await this._audioRecorder.finish();
213
+ if (!(await support_1.fs.exists(resultPath))) {
214
+ throw this.log.errorWithException(`${FFMPEG_BINARY} has failed ` + `to store the actual audio recording at '${resultPath}'`);
225
215
  }
226
- return await (0, utils_1.encodeBase64OrUpload)(resultPath);
227
- },
228
- };
216
+ }
217
+ catch (e) {
218
+ await this._audioRecorder.interrupt(true);
219
+ await this._audioRecorder.cleanup();
220
+ this._audioRecorder = null;
221
+ throw e;
222
+ }
223
+ return await (0, utils_1.encodeBase64OrUpload)(resultPath);
224
+ }
229
225
  /**
230
226
  * @typedef {import('../driver').XCUITestDriver} XCUITestDriver
231
227
  */
@@ -1 +1 @@
1
- {"version":3,"file":"record-audio.js","sourceRoot":"","sources":["../../../lib/commands/record-audio.js"],"names":[],"mappings":";;;AAAA,4CAAyD;AACzD,+CAAwC;AACxC,oCAA8C;AAC9C,uCAA0C;AAE1C,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,sBAAsB,GAAG,cAAc,CAAC;AAC9C,MAAM,cAAc,GAAG,cAAc,CAAC;AACtC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAExC,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,MAAM,aAAa,GAAG,QAAQ,CAAC;AAC/B,MAAM,YAAY,GAAG,gBAAM,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;AACrD,MAAa,aAAa;IACxB,YAAY,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,GAAG,EAAE;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,cAAc;QACxB,IAAI,CAAC;YACH,MAAM,YAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CACb,IAAI,aAAa,yEAAyE;gBACxF,8DAA8D,CACjE,CAAC;QACJ,CAAC;QAED,MAAM,EAAC,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAC,GAAG,IAAI,CAAC,IAAI,CAAC;QAEpF,MAAM,IAAI,GAAG;YACX,IAAI;YACJ,GAAG,cAAc,EAAE;YACnB,IAAI;YACJ,WAAW;YACX,I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,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,UAAU,CAAC;IACf,IAAI,CAAC;QACH,UAAU,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;QAChD,IAAI,CAAC,CAAC,MAAM,YAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAC/B,GAAG,aAAa,cAAc,GAAG,2CAA2C,UAAU,GAAG,CAC1F,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,MAAM,CAAC,CAAC;IACV,CAAC;IACD,OAAO,MAAM,IAAA,4BAAoB,EAAC,UAAU,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG"}
@@ -1,18 +1,20 @@
1
- export class ScreenRecorder {
2
- constructor(udid: any, log: any, videoPath: any, opts?: {});
3
- videoPath: any;
4
- log: any;
5
- opts: {};
6
- udid: any;
7
- mainProcess: any;
8
- timeoutHandler: NodeJS.Timeout | null;
9
- start(timeoutMs: any): Promise<void>;
10
- interrupt(force?: boolean): Promise<boolean>;
11
- finish(): Promise<any>;
12
- cleanup(): Promise<void>;
13
- }
14
- declare namespace _default {
15
- let _recentScreenRecorder: ScreenRecorder | null;
1
+ /**
2
+ * Direct Appium to start recording the device screen
3
+ *
4
+ * Record the display of devices running iOS Simulator since Xcode 9 or real devices since iOS 11
5
+ * (ffmpeg utility is required: 'brew install ffmpeg').
6
+ * It records screen activity to a MPEG-4 file. Audio is not recorded with the video file.
7
+ * If screen recording has been already started then the command will stop it forcefully and start a new one.
8
+ * The previously recorded video file will be deleted.
9
+ *
10
+ * @param {import('./types').StartRecordingScreenOptions} [options] - The available options.
11
+ * @returns {Promise<string>} Base64-encoded content of the recorded media file if
12
+ * any screen recording is currently running or an empty string.
13
+ * @throws {Error} If screen recording has failed to start.
14
+ * @this {XCUITestDriver}
15
+ */
16
+ export function startRecordingScreen(this: import("../driver").XCUITestDriver, options?: import("./types").StartRecordingScreenOptions): Promise<string>;
17
+ export class startRecordingScreen {
16
18
  /**
17
19
  * Direct Appium to start recording the device screen
18
20
  *
@@ -28,7 +30,28 @@ declare namespace _default {
28
30
  * @throws {Error} If screen recording has failed to start.
29
31
  * @this {XCUITestDriver}
30
32
  */
31
- function startRecordingScreen(this: import("../driver").XCUITestDriver, options?: import("./types").StartRecordingScreenOptions): Promise<string>;
33
+ constructor(this: import("../driver").XCUITestDriver, options?: import("./types").StartRecordingScreenOptions);
34
+ _recentScreenRecorder: ScreenRecorder;
35
+ }
36
+ /**
37
+ * Direct Appium to stop screen recording and return the video
38
+ *
39
+ * If no screen recording process is running then the endpoint will try to get
40
+ * the recently recorded file. If no previously recorded file is found and no
41
+ * active screen recording processes are running then the method returns an
42
+ * empty string.
43
+ *
44
+ * @param {import('./types').StopRecordingScreenOptions} options - The available
45
+ * options.
46
+ * @returns {Promise<string?>} Base64-encoded content of the recorded media
47
+ * file if `remotePath` parameter is empty or null or an empty string.
48
+ * @throws {Error} If there was an error while getting the name of a media
49
+ * file or the file content cannot be uploaded to the remote
50
+ * location.
51
+ * @this {XCUITestDriver}
52
+ */
53
+ export function stopRecordingScreen(this: import("../driver").XCUITestDriver, options?: import("./types").StopRecordingScreenOptions): Promise<string | null>;
54
+ export class stopRecordingScreen {
32
55
  /**
33
56
  * Direct Appium to stop screen recording and return the video
34
57
  *
@@ -46,8 +69,21 @@ declare namespace _default {
46
69
  * location.
47
70
  * @this {XCUITestDriver}
48
71
  */
49
- function stopRecordingScreen(this: import("../driver").XCUITestDriver, options?: import("./types").StopRecordingScreenOptions): Promise<string | null>;
72
+ constructor(this: import("../driver").XCUITestDriver, options?: import("./types").StopRecordingScreenOptions);
73
+ _recentScreenRecorder: any;
74
+ }
75
+ export class ScreenRecorder {
76
+ constructor(udid: any, log: any, videoPath: any, opts?: {});
77
+ videoPath: any;
78
+ log: any;
79
+ opts: {};
80
+ udid: any;
81
+ mainProcess: any;
82
+ timeoutHandler: NodeJS.Timeout | null;
83
+ start(timeoutMs: any): Promise<void>;
84
+ interrupt(force?: boolean): Promise<boolean>;
85
+ finish(): Promise<any>;
86
+ cleanup(): Promise<void>;
50
87
  }
51
- export default _default;
52
88
  export type XCUITestDriver = import("../driver").XCUITestDriver;
53
89
  //# sourceMappingURL=recordscreen.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recordscreen.d.ts","sourceRoot":"","sources":["../../../lib/commands/recordscreen.js"],"names":[],"mappings":"AAqEA;IACE,4DAOC;IANC,eAA0B;IAC1B,SAAc;IACd,SAAgB;IAChB,UAAgB;IAChB,iBAAuB;IACvB,sCAA0B;IAG5B,qCA8GC;IAED,6CAuBC;IAED,uBAGC;IAED,yBAIC;CACF;;+BAGY,cAAc,OAAC;IAE1B;;;;;;;;;;;;;;OAcG;IACH,kFANW,OAAO,SAAS,EAAE,2BAA2B,GAC3C,OAAO,CAAC,MAAM,CAAC,CA6G3B;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,iFATW,OAAO,SAAS,EAAE,0BAA0B,GAE1C,OAAO,CAAC,MAAM,OAAC,CAAC,CA2B5B;;;6BAIU,OAAO,WAAW,EAAE,cAAc"}
1
+ {"version":3,"file":"recordscreen.d.ts","sourceRoot":"","sources":["../../../lib/commands/recordscreen.js"],"names":[],"mappings":"AAoOA;;;;;;;;;;;;;;GAcG;AACH,yFANW,OAAO,SAAS,EAAE,2BAA2B,GAC3C,OAAO,CAAC,MAAM,CAAC,CA6G3B;;IAvHD;;;;;;;;;;;;;;OAcG;IACH,gEANW,OAAO,SAAS,EAAE,2BAA2B,EA8GvD;IA7DG,sCAAiC;;AA+DrC;;;;;;;;;;;;;;;;GAgBG;AACH,wFATW,OAAO,SAAS,EAAE,0BAA0B,GAE1C,OAAO,CAAC,MAAM,OAAC,CAAC,CA2B5B;;IArCD;;;;;;;;;;;;;;;;OAgBG;IACH,gEATW,OAAO,SAAS,EAAE,0BAA0B,EA6BtD;IAFG,2BAAiC;;AA3TrC;IACE,4DAOC;IANC,eAA0B;IAC1B,SAAc;IACd,SAAgB;IAChB,UAAgB;IAChB,iBAAuB;IACvB,sCAA0B;IAG5B,qCA8GC;IAED,6CAuBC;IAED,uBAGC;IAED,yBAIC;CACF;6BAmKY,OAAO,WAAW,EAAE,cAAc"}
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ScreenRecorder = void 0;
7
+ exports.startRecordingScreen = startRecordingScreen;
8
+ exports.stopRecordingScreen = stopRecordingScreen;
7
9
  const lodash_1 = __importDefault(require("lodash"));
8
10
  const support_1 = require("appium/support");
9
11
  const teen_process_1 = require("teen_process");
@@ -188,140 +190,136 @@ class ScreenRecorder {
188
190
  }
189
191
  }
190
192
  exports.ScreenRecorder = ScreenRecorder;
191
- exports.default = {
192
- /** @type {ScreenRecorder?} */
193
- _recentScreenRecorder: null,
194
- /**
195
- * Direct Appium to start recording the device screen
196
- *
197
- * Record the display of devices running iOS Simulator since Xcode 9 or real devices since iOS 11
198
- * (ffmpeg utility is required: 'brew install ffmpeg').
199
- * It records screen activity to a MPEG-4 file. Audio is not recorded with the video file.
200
- * If screen recording has been already started then the command will stop it forcefully and start a new one.
201
- * The previously recorded video file will be deleted.
202
- *
203
- * @param {import('./types').StartRecordingScreenOptions} [options] - The available options.
204
- * @returns {Promise<string>} Base64-encoded content of the recorded media file if
205
- * any screen recording is currently running or an empty string.
206
- * @throws {Error} If screen recording has failed to start.
207
- * @this {XCUITestDriver}
208
- */
209
- async startRecordingScreen(options = {}) {
210
- const { videoType = DEFAULT_VCODEC, timeLimit = DEFAULT_RECORDING_TIME_SEC, videoQuality = DEFAULT_QUALITY, videoFps = DEFAULT_FPS, videoFilters, videoScale, forceRestart, pixelFormat, hardwareAcceleration } = options;
211
- let result = '';
212
- if (!forceRestart) {
213
- this.log.info(`Checking if there is/was a previous screen recording. ` +
214
- `Set 'forceRestart' option to 'true' if you'd like to skip this step.`);
215
- result = (await this.stopRecordingScreen(options)) ?? result;
216
- }
217
- const videoPath = await support_1.tempDir.path({
218
- prefix: `appium_${Math.random().toString(16).substring(2, 8)}`,
219
- suffix: MP4_EXT
220
- });
221
- const wdaBaseUrl = this.opts.wdaBaseUrl || appium_webdriveragent_1.WDA_BASE_URL;
222
- const screenRecorder = new ScreenRecorder(this.device.udid, this.log, videoPath, {
223
- remotePort: this.opts.mjpegServerPort || DEFAULT_MJPEG_SERVER_PORT,
224
- remoteUrl: wdaBaseUrl,
225
- videoType,
226
- videoFilters,
227
- videoScale,
228
- videoFps,
229
- pixelFormat,
230
- hardwareAcceleration
231
- });
232
- if (!(await screenRecorder.interrupt(true))) {
233
- throw this.log.errorWithException('Unable to stop screen recording process');
234
- }
235
- if (this._recentScreenRecorder) {
236
- await this._recentScreenRecorder.cleanup();
237
- this._recentScreenRecorder = null;
238
- }
239
- const timeoutSeconds = parseFloat(String(timeLimit));
240
- if (isNaN(timeoutSeconds) || timeoutSeconds > MAX_RECORDING_TIME_SEC || timeoutSeconds <= 0) {
241
- throw this.log.errorWithException(`The timeLimit value must be in range [1, ${MAX_RECORDING_TIME_SEC}] seconds. ` +
242
- `The value of '${timeLimit}' has been passed instead.`);
243
- }
244
- let { mjpegServerScreenshotQuality, mjpegServerFramerate } =
245
- /** @type {import('appium-webdriveragent').WDASettings} */ (await this.proxyCommand('/appium/settings', 'GET'));
246
- if (videoQuality) {
247
- const quality = lodash_1.default.isInteger(videoQuality)
248
- ? videoQuality
249
- : QUALITY_MAPPING[lodash_1.default.toLower(String(videoQuality))];
250
- if (!quality) {
251
- throw new Error(`videoQuality value should be one of ${JSON.stringify(lodash_1.default.keys(QUALITY_MAPPING))} or a number in range 1..100. ` + `'${videoQuality}' is given instead`);
252
- }
253
- mjpegServerScreenshotQuality = mjpegServerScreenshotQuality !== quality ? quality : undefined;
254
- }
255
- else {
256
- mjpegServerScreenshotQuality = undefined;
257
- }
258
- if (videoFps) {
259
- const fps = parseInt(String(videoFps), 10);
260
- if (isNaN(fps)) {
261
- throw new Error(`videoFps value should be a valid number in range 1..60. ` +
262
- `'${videoFps}' is given instead`);
263
- }
264
- mjpegServerFramerate = mjpegServerFramerate !== fps ? fps : undefined;
265
- }
266
- else {
267
- mjpegServerFramerate = undefined;
268
- }
269
- if (support_1.util.hasValue(mjpegServerScreenshotQuality) || support_1.util.hasValue(mjpegServerFramerate)) {
270
- await this.proxyCommand('/appium/settings', 'POST', {
271
- settings: {
272
- mjpegServerScreenshotQuality,
273
- mjpegServerFramerate
274
- }
275
- });
276
- }
277
- try {
278
- await screenRecorder.start(timeoutSeconds * 1000);
279
- }
280
- catch (e) {
281
- await screenRecorder.interrupt(true);
282
- await screenRecorder.cleanup();
283
- throw e;
193
+ /**
194
+ * Direct Appium to start recording the device screen
195
+ *
196
+ * Record the display of devices running iOS Simulator since Xcode 9 or real devices since iOS 11
197
+ * (ffmpeg utility is required: 'brew install ffmpeg').
198
+ * It records screen activity to a MPEG-4 file. Audio is not recorded with the video file.
199
+ * If screen recording has been already started then the command will stop it forcefully and start a new one.
200
+ * The previously recorded video file will be deleted.
201
+ *
202
+ * @param {import('./types').StartRecordingScreenOptions} [options] - The available options.
203
+ * @returns {Promise<string>} Base64-encoded content of the recorded media file if
204
+ * any screen recording is currently running or an empty string.
205
+ * @throws {Error} If screen recording has failed to start.
206
+ * @this {XCUITestDriver}
207
+ */
208
+ async function startRecordingScreen(options = {}) {
209
+ const { videoType = DEFAULT_VCODEC, timeLimit = DEFAULT_RECORDING_TIME_SEC, videoQuality = DEFAULT_QUALITY, videoFps = DEFAULT_FPS, videoFilters, videoScale, forceRestart, pixelFormat, hardwareAcceleration } = options;
210
+ let result = '';
211
+ if (!forceRestart) {
212
+ this.log.info(`Checking if there is/was a previous screen recording. ` +
213
+ `Set 'forceRestart' option to 'true' if you'd like to skip this step.`);
214
+ result = (await this.stopRecordingScreen(options)) ?? result;
215
+ }
216
+ const videoPath = await support_1.tempDir.path({
217
+ prefix: `appium_${Math.random().toString(16).substring(2, 8)}`,
218
+ suffix: MP4_EXT
219
+ });
220
+ const wdaBaseUrl = this.opts.wdaBaseUrl || appium_webdriveragent_1.WDA_BASE_URL;
221
+ const screenRecorder = new ScreenRecorder(this.device.udid, this.log, videoPath, {
222
+ remotePort: this.opts.mjpegServerPort || DEFAULT_MJPEG_SERVER_PORT,
223
+ remoteUrl: wdaBaseUrl,
224
+ videoType,
225
+ videoFilters,
226
+ videoScale,
227
+ videoFps,
228
+ pixelFormat,
229
+ hardwareAcceleration
230
+ });
231
+ if (!(await screenRecorder.interrupt(true))) {
232
+ throw this.log.errorWithException('Unable to stop screen recording process');
233
+ }
234
+ if (this._recentScreenRecorder) {
235
+ await this._recentScreenRecorder.cleanup();
236
+ this._recentScreenRecorder = null;
237
+ }
238
+ const timeoutSeconds = parseFloat(String(timeLimit));
239
+ if (isNaN(timeoutSeconds) || timeoutSeconds > MAX_RECORDING_TIME_SEC || timeoutSeconds <= 0) {
240
+ throw this.log.errorWithException(`The timeLimit value must be in range [1, ${MAX_RECORDING_TIME_SEC}] seconds. ` +
241
+ `The value of '${timeLimit}' has been passed instead.`);
242
+ }
243
+ let { mjpegServerScreenshotQuality, mjpegServerFramerate } =
244
+ /** @type {import('appium-webdriveragent').WDASettings} */ (await this.proxyCommand('/appium/settings', 'GET'));
245
+ if (videoQuality) {
246
+ const quality = lodash_1.default.isInteger(videoQuality)
247
+ ? videoQuality
248
+ : QUALITY_MAPPING[lodash_1.default.toLower(String(videoQuality))];
249
+ if (!quality) {
250
+ throw new Error(`videoQuality value should be one of ${JSON.stringify(lodash_1.default.keys(QUALITY_MAPPING))} or a number in range 1..100. ` + `'${videoQuality}' is given instead`);
284
251
  }
285
- this._recentScreenRecorder = screenRecorder;
286
- return result;
287
- },
288
- /**
289
- * Direct Appium to stop screen recording and return the video
290
- *
291
- * If no screen recording process is running then the endpoint will try to get
292
- * the recently recorded file. If no previously recorded file is found and no
293
- * active screen recording processes are running then the method returns an
294
- * empty string.
295
- *
296
- * @param {import('./types').StopRecordingScreenOptions} options - The available
297
- * options.
298
- * @returns {Promise<string?>} Base64-encoded content of the recorded media
299
- * file if `remotePath` parameter is empty or null or an empty string.
300
- * @throws {Error} If there was an error while getting the name of a media
301
- * file or the file content cannot be uploaded to the remote
302
- * location.
303
- * @this {XCUITestDriver}
304
- */
305
- async stopRecordingScreen(options = {}) {
306
- if (!this._recentScreenRecorder) {
307
- this.log.info('Screen recording is not running. There is nothing to stop.');
308
- return '';
252
+ mjpegServerScreenshotQuality = mjpegServerScreenshotQuality !== quality ? quality : undefined;
253
+ }
254
+ else {
255
+ mjpegServerScreenshotQuality = undefined;
256
+ }
257
+ if (videoFps) {
258
+ const fps = parseInt(String(videoFps), 10);
259
+ if (isNaN(fps)) {
260
+ throw new Error(`videoFps value should be a valid number in range 1..60. ` +
261
+ `'${videoFps}' is given instead`);
309
262
  }
310
- try {
311
- const videoPath = await this._recentScreenRecorder.finish();
312
- if (!(await support_1.fs.exists(videoPath))) {
313
- throw this.log.errorWithException(`The screen recorder utility has failed ` +
314
- `to store the actual screen recording at '${videoPath}'`);
263
+ mjpegServerFramerate = mjpegServerFramerate !== fps ? fps : undefined;
264
+ }
265
+ else {
266
+ mjpegServerFramerate = undefined;
267
+ }
268
+ if (support_1.util.hasValue(mjpegServerScreenshotQuality) || support_1.util.hasValue(mjpegServerFramerate)) {
269
+ await this.proxyCommand('/appium/settings', 'POST', {
270
+ settings: {
271
+ mjpegServerScreenshotQuality,
272
+ mjpegServerFramerate
315
273
  }
316
- return await (0, utils_1.encodeBase64OrUpload)(videoPath, options.remotePath, options);
317
- }
318
- finally {
319
- await this._recentScreenRecorder.interrupt(true);
320
- await this._recentScreenRecorder.cleanup();
321
- this._recentScreenRecorder = null;
274
+ });
275
+ }
276
+ try {
277
+ await screenRecorder.start(timeoutSeconds * 1000);
278
+ }
279
+ catch (e) {
280
+ await screenRecorder.interrupt(true);
281
+ await screenRecorder.cleanup();
282
+ throw e;
283
+ }
284
+ this._recentScreenRecorder = screenRecorder;
285
+ return result;
286
+ }
287
+ /**
288
+ * Direct Appium to stop screen recording and return the video
289
+ *
290
+ * If no screen recording process is running then the endpoint will try to get
291
+ * the recently recorded file. If no previously recorded file is found and no
292
+ * active screen recording processes are running then the method returns an
293
+ * empty string.
294
+ *
295
+ * @param {import('./types').StopRecordingScreenOptions} options - The available
296
+ * options.
297
+ * @returns {Promise<string?>} Base64-encoded content of the recorded media
298
+ * file if `remotePath` parameter is empty or null or an empty string.
299
+ * @throws {Error} If there was an error while getting the name of a media
300
+ * file or the file content cannot be uploaded to the remote
301
+ * location.
302
+ * @this {XCUITestDriver}
303
+ */
304
+ async function stopRecordingScreen(options = {}) {
305
+ if (!this._recentScreenRecorder) {
306
+ this.log.info('Screen recording is not running. There is nothing to stop.');
307
+ return '';
308
+ }
309
+ try {
310
+ const videoPath = await this._recentScreenRecorder.finish();
311
+ if (!(await support_1.fs.exists(videoPath))) {
312
+ throw this.log.errorWithException(`The screen recorder utility has failed ` +
313
+ `to store the actual screen recording at '${videoPath}'`);
322
314
  }
315
+ return await (0, utils_1.encodeBase64OrUpload)(videoPath, options.remotePath, options);
323
316
  }
324
- };
317
+ finally {
318
+ await this._recentScreenRecorder.interrupt(true);
319
+ await this._recentScreenRecorder.cleanup();
320
+ this._recentScreenRecorder = null;
321
+ }
322
+ }
325
323
  /**
326
324
  * @typedef {import('../driver').XCUITestDriver} XCUITestDriver
327
325
  */